Skip to content

Commit

Permalink
Progress
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Apr 27, 2024
1 parent d9eff3a commit 70a6e7b
Show file tree
Hide file tree
Showing 41 changed files with 445 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,23 @@ public static void register(final DataProviderRegistrator registrator) {
return true;
})
.create(Keys.MAX_BURN_TIME)
.get(x -> new SpongeTicks(x.accessor$litDuration()))
.set((h, v) -> h.accessor$litDuration((int) v.ticks()))
.get(x -> SpongeTicks.ticksOrInfinite(x.accessor$litDuration()))
.set((h, v) -> h.accessor$litDuration(SpongeTicks.toSaturatedIntOrInfinite(v)))
.create(Keys.MAX_COOK_TIME)
.get(x -> new SpongeTicks(x.accessor$cookingTotalTime()))
.set((h, v) -> h.accessor$cookingTotalTime((int) v.ticks()))
.get(x -> SpongeTicks.ticksOrInfinite(x.accessor$cookingTotalTime()))
.set((h, v) -> h.accessor$cookingTotalTime(SpongeTicks.toSaturatedIntOrInfinite(v)))
.create(Keys.PASSED_COOK_TIME)
.get(x -> new SpongeTicks(x.accessor$cookingProgress()))
.set((h, v) -> {
.setAnd((h, v) -> {
if (v.isInfinite()) {
return false;
}
final int ticks = (int) v.ticks();
if (ticks < h.accessor$cookingTotalTime()) {
h.accessor$cookingProgress(ticks);
return true;
}
return false;
});
}
// @formatter:on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public static void register(final DataProviderRegistrator registrator) {
registrator
.asMutable(TheEndGatewayBlockEntityAccessor.class)
.create(Keys.COOLDOWN)
.get(x -> new SpongeTicks(x.accessor$teleportCooldown()))
.get(x -> SpongeTicks.ticksOrInfinite(x.accessor$teleportCooldown()))
.setAnd((h, v) -> {
final int ticks = (int) v.ticks();
if (ticks < 0) {
final int ticks = SpongeTicks.toSaturatedIntOrInfinite(v);
if (!v.isInfinite() && ticks < 0) {
return false;
}
h.accessor$teleportCooldown(ticks);
Expand All @@ -55,6 +55,9 @@ public static void register(final DataProviderRegistrator registrator) {
.create(Keys.END_GATEWAY_AGE)
.get(x -> new SpongeTicks(x.accessor$age()))
.setAnd((h, v) -> {
if (v.isInfinite()) {
return false;
}
final long ticks = v.ticks();
if (ticks < 0) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public static void register(final DataProviderRegistrator registrator) {
registrator
.asMutable(HopperBlockEntityAccessor.class)
.create(Keys.COOLDOWN)
.get(h -> new SpongeTicks(Math.max(h.accessor$cooldownTime(), 0)))
.get(h -> SpongeTicks.ticksOrInfinite(h.accessor$cooldownTime()))
.setAnd((h, v) -> {
final int ticks = (int) v.ticks();
if (ticks < 0) {
final int ticks = SpongeTicks.toSaturatedIntOrInfinite(v);
if (!v.isInfinite() && ticks < 0) {
return false;
}
h.accessor$cooldownTime(ticks);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,28 @@ public static void register(final DataProviderRegistrator registrator) {
.set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxNearbyEntities(v))
.create(Keys.MAX_SPAWN_DELAY)
.get(h -> new SpongeTicks(((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxSpawnDelay()))
.set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxSpawnDelay((int) v.ticks()))
.setAnd((h, v) -> {
if (v.isInfinite()) {
return false;
}
((BaseSpawnerAccessor) h.accessor$spawner()).accessor$maxSpawnDelay((int) v.ticks());
return true;
})
.create(Keys.MIN_SPAWN_DELAY)
.get(h -> new SpongeTicks(((BaseSpawnerAccessor) h.accessor$spawner()).accessor$minSpawnDelay()))
.set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$minSpawnDelay((int) v.ticks()))
.setAnd((h, v) -> {
if (v.isInfinite()) {
return false;
}
((BaseSpawnerAccessor) h.accessor$spawner()).accessor$minSpawnDelay((int) v.ticks());
return true;
})
.create(Keys.NEXT_ENTITY_TO_SPAWN)
.get(h -> MobSpawnerData.getNextEntity((BaseSpawnerAccessor) h.accessor$spawner()))
.set((h, v) -> MobSpawnerData.setNextEntity((SpawnerBlockEntity) h, v))
.create(Keys.REMAINING_SPAWN_DELAY)
.get(h -> new SpongeTicks(((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnDelay()))
.set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnDelay((int) v.ticks()))
.get(h -> SpongeTicks.ticksOrInfinite(((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnDelay()))
.set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$spawnDelay(SpongeTicks.toSaturatedIntOrInfinite(v)))
.create(Keys.REQUIRED_PLAYER_RANGE)
.get(h -> (double) ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$requiredPlayerRange())
.set((h, v) -> ((BaseSpawnerAccessor) h.accessor$spawner()).accessor$requiredPlayerRange(v.intValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ public static void register(final DataProviderRegistrator registrator) {
.get(h -> Color.ofRgb(h.getColor()))
.set((h, v) -> h.setFixedColor(v.rgb()))
.create(Keys.DURATION)
.get(x -> new SpongeTicks(x.getDuration()))
.get(x -> SpongeTicks.ticksOrInfinite(x.getDuration()))
.setAnd((h, v) -> {
final int ticks = (int) v.ticks();
if (ticks < 0) {
final int ticks = SpongeTicks.toSaturatedIntOrInfinite(v);
if (!v.isInfinite() && ticks < 0) {
return false;
}
h.setDuration(ticks);
Expand All @@ -68,18 +68,24 @@ public static void register(final DataProviderRegistrator registrator) {
.get(h -> (double) ((AreaEffectCloudAccessor) h).accessor$radiusPerTick())
.set((h, v) -> h.setRadiusPerTick(v.floatValue()))
.create(Keys.WAIT_TIME)
.get(h -> new SpongeTicks(((AreaEffectCloudAccessor) h).accessor$waitTime()))
.set((h, v) -> h.setWaitTime((int) v.ticks()))
.get(h -> SpongeTicks.ticksOrInfinite(((AreaEffectCloudAccessor) h).accessor$waitTime()))
.set((h, v) -> h.setWaitTime(SpongeTicks.toSaturatedIntOrInfinite(v)))
.asMutable(AreaEffectCloudAccessor.class)
.create(Keys.DURATION_ON_USE)
.get(h -> new SpongeTicks(h.accessor$durationOnUse()))
.set((h, v) -> h.accessor$durationOnUse((int) v.ticks()))
.setAnd((h, v) -> {
if (v.isInfinite()) {
return false;
}
h.accessor$durationOnUse(SpongeTicks.toSaturatedIntOrInfinite(v));
return true;
})
.create(Keys.POTION_EFFECTS)
.get(h -> PotionEffectUtil.copyAsPotionEffects(h.accessor$effects()))
.set((h, v) -> h.accessor$effects(PotionEffectUtil.copyAsEffectInstances(v)))
.create(Keys.REAPPLICATION_DELAY)
.get(h -> new SpongeTicks(h.accessor$reapplicationDelay()))
.set((h, v) -> h.accessor$reapplicationDelay((int) v.ticks()));
.get(h -> SpongeTicks.ticksOrInfinite(h.accessor$reapplicationDelay()))
.set((h, v) -> h.accessor$reapplicationDelay(SpongeTicks.toSaturatedIntOrInfinite(v)));
}
// @formatter:on
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public static void register(final DataProviderRegistrator registrator) {
registrator
.asMutable(Chicken.class)
.create(Keys.EGG_TIME)
.get(h -> new SpongeTicks(h.eggTime))
.get(h -> SpongeTicks.ticksOrInfinite(h.eggTime))
.setAnd((h, v) -> {
final int ticks = (int) v.ticks();
if (ticks < 0) {
final int ticks = SpongeTicks.toSaturatedIntOrInfinite(v);
if (!v.isInfinite() && ticks < 0) {
return false;
}
h.eggTime = ticks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,22 @@ public static void register(final DataProviderRegistrator registrator) {
.delete(h -> h.invoker$setBrightnessOverride(null))
.create(Keys.INTERPOLATION_DURATION)
.get(h -> Ticks.of(h.invoker$getInterpolationDuration()))
.set((h ,v) -> h.invoker$setInterpolationDuration((int) v.ticks()))
.setAnd((h ,v) -> {
if (v.isInfinite()) {
return false;
}
h.invoker$setInterpolationDuration((int) v.ticks());
return true;
})
.create(Keys.INTERPOLATION_DELAY)
.get(h -> Ticks.of(h.invoker$getInterpolationDelay()))
.set((h ,v) -> h.invoker$setInterpolationDelay((int) v.ticks()))
.setAnd((h ,v) -> {
if (v.isInfinite()) {
return false;
}
h.invoker$setInterpolationDelay((int) v.ticks());
return true;
})
.create(Keys.SHADOW_RADIUS)
.get(h -> (double) h.invoker$getShadowRadius())
.set((h ,v) -> h.invoker$setShadowRadius(v.floatValue()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import net.minecraft.world.entity.monster.Endermite;
import org.spongepowered.api.data.Keys;
import org.spongepowered.api.util.Ticks;
import org.spongepowered.common.accessor.world.entity.monster.EndermiteAccessor;
import org.spongepowered.common.data.provider.DataProviderRegistrator;
import org.spongepowered.common.util.SpongeTicks;
Expand All @@ -44,11 +45,15 @@ public static void register(final DataProviderRegistrator registrator) {
.create(Keys.DESPAWN_DELAY)
.get(h -> {
if (h.isPersistenceRequired()) {
return null;
return Ticks.infinite();
}
return new SpongeTicks(((EndermiteAccessor) h).accessor$life());
})
.setAnd((h, v) -> {
if (v.isInfinite()) {
h.setPersistenceRequired();
return true;
}
if (h.isPersistenceRequired()) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,22 @@ public static void register(final DataProviderRegistrator registrator) {
return true;
})
.create(Keys.FIRE_DAMAGE_DELAY)
.get(h -> new SpongeTicks(((EntityAccessor) h).invoker$getFireImmuneTicks()))
.get(h -> SpongeTicks.ticksOrInfinite(((EntityAccessor) h).invoker$getFireImmuneTicks()))
.setAnd((h, v) -> {
final int ticks = (int) v.ticks();
if (ticks < 1 || ticks > Short.MAX_VALUE) {
final int ticks = SpongeTicks.toSaturatedIntOrInfinite(v);
if (!v.isInfinite() && (ticks < 1 || ticks > Short.MAX_VALUE)) {
return false;
}
((EntityBridge) h).bridge$setFireImmuneTicks(ticks);
return ((EntityAccessor) h).invoker$getFireImmuneTicks() == ticks;
})
.create(Keys.FIRE_TICKS)
.get(h -> ((EntityAccessor) h).accessor$remainingFireTicks() > 0 ? Ticks.of(((EntityAccessor) h).accessor$remainingFireTicks()) : null)
.get(h -> ((EntityAccessor) h).accessor$remainingFireTicks() != 0
? SpongeTicks.ticksOrInfinite(((EntityAccessor) h).accessor$remainingFireTicks())
: null)
.set((h, v) -> {
final int ticks = (int) v.ticks();
((EntityAccessor) h).accessor$remainingFireTicks(Math.max(ticks, Constants.Entity.MINIMUM_FIRE_TICKS));
final int ticks = SpongeTicks.toSaturatedIntOrInfinite(v);
((EntityAccessor) h).accessor$remainingFireTicks(ticks);
})
.deleteAndGet(h -> {
final EntityAccessor accessor = (EntityAccessor) h;
Expand All @@ -126,17 +128,17 @@ public static void register(final DataProviderRegistrator registrator) {
return dtrBuilder.result(DataTransactionResult.Type.SUCCESS).build();
})
.create(Keys.FROZEN_TIME)
.get(h -> Ticks.of(h.getTicksFrozen()))
.set((h, v) -> h.setTicksFrozen((int) v.ticks()))
.get(h -> SpongeTicks.ticksOrInfinite(h.getTicksFrozen()))
.set((h, v) -> h.setTicksFrozen(SpongeTicks.toSaturatedIntOrInfinite(v)))
.create(Keys.MAX_FROZEN_TIME)
.get(h -> Ticks.of(h.getTicksRequiredToFreeze()))
.create(Keys.HEIGHT)
.get(h -> (double) h.getBbHeight())
.create(Keys.INVULNERABILITY_TICKS)
.get(h -> new SpongeTicks(h.invulnerableTime))
.get(h -> SpongeTicks.ticksOrInfinite(h.invulnerableTime))
.setAnd((h, v) -> {
final int ticks = (int) v.ticks();
if (ticks < 0) {
final int ticks = SpongeTicks.toSaturatedIntOrInfinite(v);
if (!v.isInfinite() && ticks < 0) {
return false;
}
h.invulnerableTime = ticks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package org.spongepowered.common.data.provider.entity;

import org.spongepowered.api.data.Keys;
import org.spongepowered.api.util.Ticks;
import org.spongepowered.common.accessor.world.entity.projectile.EyeOfEnderAccessor;
import org.spongepowered.common.data.provider.DataProviderRegistrator;
import org.spongepowered.common.util.Constants;
Expand All @@ -43,8 +44,16 @@ public static void register(final DataProviderRegistrator registrator) {
.get(h -> !h.accessor$surviveAfterDeath())
.set((h, v) -> h.accessor$surviveAfterDeath(!v))
.create(Keys.DESPAWN_DELAY)
.get(h -> new SpongeTicks(Constants.Sponge.Entity.EyeOfEnder.DESPAWN_TIMER_MAX - h.accessor$life()))
.set((h, v) -> h.accessor$life(Constants.Sponge.Entity.EyeOfEnder.DESPAWN_TIMER_MAX - (int) v.ticks()));
.get(h -> h.accessor$life() == Constants.Sponge.Entity.EyeOfEnder.INFINITE_DESPAWN_DELAY
? Ticks.infinite()
: new SpongeTicks(Constants.Sponge.Entity.EyeOfEnder.DESPAWN_TIMER_MAX - h.accessor$life()))
.set((h, v) -> {
if (v.isInfinite()) {
h.accessor$life(Constants.Sponge.Entity.EyeOfEnder.INFINITE_DESPAWN_DELAY - SpongeTicks.toSaturatedIntOrInfinite(v));
return;
}
h.accessor$life(Constants.Sponge.Entity.EyeOfEnder.DESPAWN_TIMER_MAX - SpongeTicks.toSaturatedIntOrInfinite(v));
});
}
// @formatter:on
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public static void register(final DataProviderRegistrator registrator) {
.create(Keys.FALL_TIME)
.get(x -> new SpongeTicks(x.accessor$time()))
.setAnd((h, v) -> {
if (v.isInfinite()) {
return false;
}
final int ticks = (int) v.ticks();
if (ticks < 0) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public static void register(final DataProviderRegistrator registrator) {
return null;
})
.setAnd((h, v) -> {
if (v.isInfinite()) {
return false;
}
final int ticks = (int) v.ticks();
if (ticks < 0 || ticks > Byte.MAX_VALUE) {
return false;
Expand Down
Loading

0 comments on commit 70a6e7b

Please sign in to comment.