Tweaks to EntityTypeBuilder [1.16] (#836)

* Better consistency with vanilla mobs

* Added a new method for just tracking distance

* Renamed param names

* Update FabricEntityTypeBuilder.java

* Updated v0 for backwards compatibility

* Updated descriptions and parameter names of FabricEntityTypeBuilder

* Added compat with new builders

* Style fix

* Fix style again

* Added backwards compat
This commit is contained in:
Hugman 2020-09-03 20:46:36 +02:00 committed by GitHub
parent a607839c1a
commit 15028e6f6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 126 additions and 21 deletions

View file

@ -50,9 +50,9 @@ public class FabricEntityTypeBuilder<T extends Entity> {
private EntityType.EntityFactory<T> factory; private EntityType.EntityFactory<T> factory;
private boolean saveable = true; private boolean saveable = true;
private boolean summonable = true; private boolean summonable = true;
private int trackingDistance = 5; private int trackRange = 5;
private int updateIntervalTicks = 3; private int trackedUpdateRate = 3;
private Boolean alwaysUpdateVelocity; private Boolean forceTrackedVelocityUpdates;
private boolean fireImmune = false; private boolean fireImmune = false;
private boolean spawnableFarFromPlayer; private boolean spawnableFarFromPlayer;
private EntityDimensions dimensions = EntityDimensions.changing(-1.0f, -1.0f); private EntityDimensions dimensions = EntityDimensions.changing(-1.0f, -1.0f);
@ -190,14 +190,55 @@ public class FabricEntityTypeBuilder<T extends Entity> {
return this; return this;
} }
public FabricEntityTypeBuilder<T> 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<T> trackable(int trackRangeBlocks, int trackedUpdateRate) {
return trackable(trackRangeBlocks, trackedUpdateRate, true);
} }
public FabricEntityTypeBuilder<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) { /**
this.trackingDistance = trackingDistanceBlocks; * @deprecated use {@link FabricEntityTypeBuilder#trackRangeBlocks(int)}, {@link FabricEntityTypeBuilder#trackedUpdateRate(int)} and {@link FabricEntityTypeBuilder#forceTrackedVelocityUpdates(boolean)}
this.updateIntervalTicks = updateIntervalTicks; */
this.alwaysUpdateVelocity = alwaysUpdateVelocity; @Deprecated
public FabricEntityTypeBuilder<T> 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<T> 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<T> trackRangeBlocks(int range) {
return trackRangeChunks(range + 15 / 16);
}
public FabricEntityTypeBuilder<T> trackedUpdateRate(int rate) {
this.trackedUpdateRate = rate;
return this;
}
public FabricEntityTypeBuilder<T> forceTrackedVelocityUpdates(boolean forceTrackedVelocityUpdates) {
this.forceTrackedVelocityUpdates = forceTrackedVelocityUpdates;
return this; return this;
} }
@ -223,7 +264,7 @@ public class FabricEntityTypeBuilder<T extends Entity> {
// TODO: Flesh out once modded datafixers exist. // TODO: Flesh out once modded datafixers exist.
} }
EntityType<T> type = new FabricEntityType<>(this.factory, this.spawnGroup, this.saveable, this.summonable, this.fireImmune, this.spawnableFarFromPlayer, this.specificSpawnBlocks, dimensions, trackingDistance, updateIntervalTicks, alwaysUpdateVelocity); EntityType<T> type = new FabricEntityType<>(this.factory, this.spawnGroup, this.saveable, this.summonable, this.fireImmune, this.spawnableFarFromPlayer, this.specificSpawnBlocks, dimensions, trackRange, trackedUpdateRate, forceTrackedVelocityUpdates);
return type; return type;
} }
@ -283,15 +324,47 @@ public class FabricEntityTypeBuilder<T extends Entity> {
return this; return this;
} }
/**
* @deprecated use {@link FabricEntityTypeBuilder.Living#trackRangeBlocks(int)}, {@link FabricEntityTypeBuilder.Living#trackedUpdateRate(int)} and {@link FabricEntityTypeBuilder.Living#forceTrackedVelocityUpdates(boolean)}
*/
@Override @Override
public FabricEntityTypeBuilder.Living<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks) { @Deprecated
super.trackable(trackingDistanceBlocks, updateIntervalTicks); public FabricEntityTypeBuilder.Living<T> 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<T> trackable(int trackRangeBlocks, int trackedUpdateRate, boolean forceTrackedVelocityUpdates) {
super.trackable(trackRangeBlocks, trackedUpdateRate, forceTrackedVelocityUpdates);
return this; return this;
} }
@Override @Override
public FabricEntityTypeBuilder.Living<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) { public FabricEntityTypeBuilder.Living<T> trackRangeChunks(int range) {
super.trackable(trackingDistanceBlocks, updateIntervalTicks, alwaysUpdateVelocity); super.trackRangeChunks(range);
return this;
}
@Override
public FabricEntityTypeBuilder.Living<T> trackRangeBlocks(int range) {
super.trackRangeBlocks(range);
return this;
}
@Override
public FabricEntityTypeBuilder.Living<T> trackedUpdateRate(int rate) {
super.trackedUpdateRate(rate);
return this;
}
@Override
public FabricEntityTypeBuilder.Living<T> forceTrackedVelocityUpdates(boolean forceTrackedVelocityUpdates) {
super.forceTrackedVelocityUpdates(forceTrackedVelocityUpdates);
return this; return this;
} }
@ -391,15 +464,47 @@ public class FabricEntityTypeBuilder<T extends Entity> {
return this; return this;
} }
/**
* @deprecated use {@link FabricEntityTypeBuilder.Mob#trackRangeBlocks(int)}, {@link FabricEntityTypeBuilder.Mob#trackedUpdateRate(int)} and {@link FabricEntityTypeBuilder.Mob#forceTrackedVelocityUpdates(boolean)}
*/
@Override @Override
public FabricEntityTypeBuilder.Mob<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks) { @Deprecated
super.trackable(trackingDistanceBlocks, updateIntervalTicks); public FabricEntityTypeBuilder.Mob<T> 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<T> trackable(int trackRangeBlocks, int trackedUpdateRate, boolean forceTrackedVelocityUpdates) {
super.trackable(trackRangeBlocks, trackedUpdateRate, forceTrackedVelocityUpdates);
return this; return this;
} }
@Override @Override
public FabricEntityTypeBuilder.Mob<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) { public FabricEntityTypeBuilder.Mob<T> trackRangeChunks(int range) {
super.trackable(trackingDistanceBlocks, updateIntervalTicks, alwaysUpdateVelocity); super.trackRangeChunks(range);
return this;
}
@Override
public FabricEntityTypeBuilder.Mob<T> trackRangeBlocks(int range) {
super.trackRangeBlocks(range);
return this;
}
@Override
public FabricEntityTypeBuilder.Mob<T> trackedUpdateRate(int rate) {
super.trackedUpdateRate(rate);
return this;
}
@Override
public FabricEntityTypeBuilder.Mob<T> forceTrackedVelocityUpdates(boolean forceTrackedVelocityUpdates) {
super.forceTrackedVelocityUpdates(forceTrackedVelocityUpdates);
return this; return this;
} }

View file

@ -28,7 +28,7 @@ public class FabricEntityType<T extends Entity> extends EntityType<T> {
private final Boolean alwaysUpdateVelocity; private final Boolean alwaysUpdateVelocity;
public FabricEntityType(EntityType.EntityFactory<T> factory, SpawnGroup spawnGroup, boolean bl, boolean summonable, boolean fireImmune, boolean spawnableFarFromPlayer, ImmutableSet<Block> spawnBlocks, EntityDimensions entityDimensions, int maxTrackDistance, int trackTickInterval, Boolean alwaysUpdateVelocity) { public FabricEntityType(EntityType.EntityFactory<T> factory, SpawnGroup spawnGroup, boolean bl, boolean summonable, boolean fireImmune, boolean spawnableFarFromPlayer, ImmutableSet<Block> 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; this.alwaysUpdateVelocity = alwaysUpdateVelocity;
} }

View file

@ -81,12 +81,12 @@ public class FabricEntityTypeBuilder<T extends Entity> {
} }
public FabricEntityTypeBuilder<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks) { public FabricEntityTypeBuilder<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks) {
this.delegate.trackable(trackingDistanceBlocks, updateIntervalTicks); this.delegate.trackRangeBlocks(trackingDistanceBlocks).trackedUpdateRate(updateIntervalTicks).forceTrackedVelocityUpdates(true);
return this; return this;
} }
public FabricEntityTypeBuilder<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) { public FabricEntityTypeBuilder<T> trackable(int trackingDistanceBlocks, int updateIntervalTicks, boolean alwaysUpdateVelocity) {
this.delegate.trackable(trackingDistanceBlocks, updateIntervalTicks, alwaysUpdateVelocity); this.delegate.trackRangeBlocks(trackingDistanceBlocks).trackedUpdateRate(updateIntervalTicks).forceTrackedVelocityUpdates(alwaysUpdateVelocity);
return this; return this;
} }