diff --git a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/entity/FabricEntityTypeBuilder.java b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/entity/FabricEntityTypeBuilder.java index 2d96e9697..bda6b25f1 100644 --- a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/entity/FabricEntityTypeBuilder.java +++ b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/api/object/builder/v1/entity/FabricEntityTypeBuilder.java @@ -50,9 +50,9 @@ public class FabricEntityTypeBuilder { private EntityType.EntityFactory factory; private boolean saveable = true; private boolean summonable = true; - private int trackingDistance = 5; - private int updateIntervalTicks = 3; - private Boolean alwaysUpdateVelocity; + private int trackRange = 5; + private int trackedUpdateRate = 3; + private Boolean forceTrackedVelocityUpdates; private boolean fireImmune = false; private boolean spawnableFarFromPlayer; private EntityDimensions dimensions = EntityDimensions.changing(-1.0f, -1.0f); @@ -190,14 +190,55 @@ public class FabricEntityTypeBuilder { return this; } - public FabricEntityTypeBuilder trackable(int trackingDistanceBlocks, int updateIntervalTicks) { - return trackable(trackingDistanceBlocks, updateIntervalTicks, true); + /** + * @deprecated use {@link FabricEntityTypeBuilder#trackRangeBlocks(int)}, {@link FabricEntityTypeBuilder#trackedUpdateRate(int)} and {@link FabricEntityTypeBuilder#forceTrackedVelocityUpdates(boolean)} + */ + @Deprecated + public FabricEntityTypeBuilder trackable(int trackRangeBlocks, int trackedUpdateRate) { + return trackable(trackRangeBlocks, trackedUpdateRate, true); } - public FabricEntityTypeBuilder trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) { - this.trackingDistance = trackingDistanceBlocks; - this.updateIntervalTicks = updateIntervalTicks; - this.alwaysUpdateVelocity = alwaysUpdateVelocity; + /** + * @deprecated use {@link FabricEntityTypeBuilder#trackRangeBlocks(int)}, {@link FabricEntityTypeBuilder#trackedUpdateRate(int)} and {@link FabricEntityTypeBuilder#forceTrackedVelocityUpdates(boolean)} + */ + @Deprecated + public FabricEntityTypeBuilder trackable(int trackRangeBlocks, int trackedUpdateRate, boolean forceTrackedVelocityUpdates) { + this.trackRangeBlocks(trackRangeBlocks); + this.trackedUpdateRate(trackedUpdateRate); + this.forceTrackedVelocityUpdates(forceTrackedVelocityUpdates); + return this; + } + + /** + * Sets the maximum chunk tracking range of this entity type. + * + * @param range the tracking range in chunks + * + * @return this builder for chaining + */ + public FabricEntityTypeBuilder trackRangeChunks(int range) { + this.trackRange = range; + return this; + } + + /** + * Sets the maximum block range at which players can see this entity type. + * + * @param range the tracking range in blocks + * + * @return this builder for chaining + */ + public FabricEntityTypeBuilder trackRangeBlocks(int range) { + return trackRangeChunks(range + 15 / 16); + } + + public FabricEntityTypeBuilder trackedUpdateRate(int rate) { + this.trackedUpdateRate = rate; + return this; + } + + public FabricEntityTypeBuilder forceTrackedVelocityUpdates(boolean forceTrackedVelocityUpdates) { + this.forceTrackedVelocityUpdates = forceTrackedVelocityUpdates; return this; } @@ -223,7 +264,7 @@ public class FabricEntityTypeBuilder { // TODO: Flesh out once modded datafixers exist. } - EntityType type = new FabricEntityType<>(this.factory, this.spawnGroup, this.saveable, this.summonable, this.fireImmune, this.spawnableFarFromPlayer, this.specificSpawnBlocks, dimensions, trackingDistance, updateIntervalTicks, alwaysUpdateVelocity); + EntityType type = new FabricEntityType<>(this.factory, this.spawnGroup, this.saveable, this.summonable, this.fireImmune, this.spawnableFarFromPlayer, this.specificSpawnBlocks, dimensions, trackRange, trackedUpdateRate, forceTrackedVelocityUpdates); return type; } @@ -283,15 +324,47 @@ public class FabricEntityTypeBuilder { return this; } + /** + * @deprecated use {@link FabricEntityTypeBuilder.Living#trackRangeBlocks(int)}, {@link FabricEntityTypeBuilder.Living#trackedUpdateRate(int)} and {@link FabricEntityTypeBuilder.Living#forceTrackedVelocityUpdates(boolean)} + */ @Override - public FabricEntityTypeBuilder.Living trackable(int trackingDistanceBlocks, int updateIntervalTicks) { - super.trackable(trackingDistanceBlocks, updateIntervalTicks); + @Deprecated + public FabricEntityTypeBuilder.Living trackable(int trackRangeBlocks, int trackedUpdateRate) { + super.trackable(trackRangeBlocks, trackedUpdateRate); + return this; + } + + /** + * @deprecated use {@link FabricEntityTypeBuilder.Living#trackRangeBlocks(int)}, {@link FabricEntityTypeBuilder.Living#trackedUpdateRate(int)} and {@link FabricEntityTypeBuilder.Living#forceTrackedVelocityUpdates(boolean)} + */ + @Override + @Deprecated + public FabricEntityTypeBuilder.Living trackable(int trackRangeBlocks, int trackedUpdateRate, boolean forceTrackedVelocityUpdates) { + super.trackable(trackRangeBlocks, trackedUpdateRate, forceTrackedVelocityUpdates); return this; } @Override - public FabricEntityTypeBuilder.Living trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) { - super.trackable(trackingDistanceBlocks, updateIntervalTicks, alwaysUpdateVelocity); + public FabricEntityTypeBuilder.Living trackRangeChunks(int range) { + super.trackRangeChunks(range); + return this; + } + + @Override + public FabricEntityTypeBuilder.Living trackRangeBlocks(int range) { + super.trackRangeBlocks(range); + return this; + } + + @Override + public FabricEntityTypeBuilder.Living trackedUpdateRate(int rate) { + super.trackedUpdateRate(rate); + return this; + } + + @Override + public FabricEntityTypeBuilder.Living forceTrackedVelocityUpdates(boolean forceTrackedVelocityUpdates) { + super.forceTrackedVelocityUpdates(forceTrackedVelocityUpdates); return this; } @@ -391,15 +464,47 @@ public class FabricEntityTypeBuilder { return this; } + /** + * @deprecated use {@link FabricEntityTypeBuilder.Mob#trackRangeBlocks(int)}, {@link FabricEntityTypeBuilder.Mob#trackedUpdateRate(int)} and {@link FabricEntityTypeBuilder.Mob#forceTrackedVelocityUpdates(boolean)} + */ @Override - public FabricEntityTypeBuilder.Mob trackable(int trackingDistanceBlocks, int updateIntervalTicks) { - super.trackable(trackingDistanceBlocks, updateIntervalTicks); + @Deprecated + public FabricEntityTypeBuilder.Mob trackable(int trackRangeBlocks, int trackedUpdateRate) { + super.trackable(trackRangeBlocks, trackedUpdateRate); + return this; + } + + /** + * @deprecated use {@link FabricEntityTypeBuilder.Mob#trackRangeBlocks(int)}, {@link FabricEntityTypeBuilder.Mob#trackedUpdateRate(int)} and {@link FabricEntityTypeBuilder.Mob#forceTrackedVelocityUpdates(boolean)} + */ + @Override + @Deprecated + public FabricEntityTypeBuilder.Mob trackable(int trackRangeBlocks, int trackedUpdateRate, boolean forceTrackedVelocityUpdates) { + super.trackable(trackRangeBlocks, trackedUpdateRate, forceTrackedVelocityUpdates); return this; } @Override - public FabricEntityTypeBuilder.Mob trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) { - super.trackable(trackingDistanceBlocks, updateIntervalTicks, alwaysUpdateVelocity); + public FabricEntityTypeBuilder.Mob trackRangeChunks(int range) { + super.trackRangeChunks(range); + return this; + } + + @Override + public FabricEntityTypeBuilder.Mob trackRangeBlocks(int range) { + super.trackRangeBlocks(range); + return this; + } + + @Override + public FabricEntityTypeBuilder.Mob trackedUpdateRate(int rate) { + super.trackedUpdateRate(rate); + return this; + } + + @Override + public FabricEntityTypeBuilder.Mob forceTrackedVelocityUpdates(boolean forceTrackedVelocityUpdates) { + super.forceTrackedVelocityUpdates(forceTrackedVelocityUpdates); return this; } diff --git a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/impl/object/builder/FabricEntityType.java b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/impl/object/builder/FabricEntityType.java index c1c0761b2..0d74fce13 100644 --- a/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/impl/object/builder/FabricEntityType.java +++ b/fabric-object-builder-api-v1/src/main/java/net/fabricmc/fabric/impl/object/builder/FabricEntityType.java @@ -28,7 +28,7 @@ public class FabricEntityType extends EntityType { private final Boolean alwaysUpdateVelocity; public FabricEntityType(EntityType.EntityFactory factory, SpawnGroup spawnGroup, boolean bl, boolean summonable, boolean fireImmune, boolean spawnableFarFromPlayer, ImmutableSet spawnBlocks, EntityDimensions entityDimensions, int maxTrackDistance, int trackTickInterval, Boolean alwaysUpdateVelocity) { - super(factory, spawnGroup, bl, summonable, fireImmune, spawnableFarFromPlayer, spawnBlocks, entityDimensions, (maxTrackDistance + 15) / 16, trackTickInterval); + super(factory, spawnGroup, bl, summonable, fireImmune, spawnableFarFromPlayer, spawnBlocks, entityDimensions, maxTrackDistance, trackTickInterval); this.alwaysUpdateVelocity = alwaysUpdateVelocity; } diff --git a/fabric-object-builders-v0/src/main/java/net/fabricmc/fabric/api/entity/FabricEntityTypeBuilder.java b/fabric-object-builders-v0/src/main/java/net/fabricmc/fabric/api/entity/FabricEntityTypeBuilder.java index f3b75fa5b..67c55b598 100644 --- a/fabric-object-builders-v0/src/main/java/net/fabricmc/fabric/api/entity/FabricEntityTypeBuilder.java +++ b/fabric-object-builders-v0/src/main/java/net/fabricmc/fabric/api/entity/FabricEntityTypeBuilder.java @@ -81,12 +81,12 @@ public class FabricEntityTypeBuilder { } public FabricEntityTypeBuilder trackable(int trackingDistanceBlocks, int updateIntervalTicks) { - this.delegate.trackable(trackingDistanceBlocks, updateIntervalTicks); + this.delegate.trackRangeBlocks(trackingDistanceBlocks).trackedUpdateRate(updateIntervalTicks).forceTrackedVelocityUpdates(true); return this; } public FabricEntityTypeBuilder trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) { - this.delegate.trackable(trackingDistanceBlocks, updateIntervalTicks, alwaysUpdateVelocity); + this.delegate.trackRangeBlocks(trackingDistanceBlocks).trackedUpdateRate(updateIntervalTicks).forceTrackedVelocityUpdates(alwaysUpdateVelocity); return this; }