Path: blob/1.21.x/patches/minecraft/net/minecraft/world/entity/EntityType.java.patch
7580 views
--- a/net/minecraft/world/entity/EntityType.java1+++ b/net/minecraft/world/entity/EntityType.java2@@ -961,6 +_,11 @@3private final FeatureFlagSet requiredFeatures;4private final boolean allowedInPeaceful;56+ private final java.util.function.Predicate<EntityType<?>> velocityUpdateSupplier;7+ private final java.util.function.ToIntFunction<EntityType<?>> trackingRangeSupplier;8+ private final java.util.function.ToIntFunction<EntityType<?>> updateIntervalSupplier;9+ private final java.util.function.BiFunction<net.minecraftforge.network.packets.SpawnEntity, Level, T> customClientFactory;10+11private static <T extends Entity> EntityType<T> register(ResourceKey<EntityType<?>> p_368406_, EntityType.Builder<T> p_363129_) {12return Registry.register(BuiltInRegistries.ENTITY_TYPE, p_368406_, p_363129_.build(p_368406_));13}14@@ -996,7 +_,8 @@15String p_367006_,16Optional<ResourceKey<LootTable>> p_364691_,17FeatureFlagSet p_273518_,18- boolean p_430684_19+ boolean p_430684_,20+ Builder builder21) {22this.factory = p_273268_;23this.category = p_272918_;24@@ -1013,6 +_,10 @@25this.lootTable = p_364691_;26this.requiredFeatures = p_273518_;27this.allowedInPeaceful = p_430684_;28+ this.velocityUpdateSupplier = builder == null || builder.velocityUpdateSupplier == null ? EntityType::defaultVelocitySupplier : builder.velocityUpdateSupplier;29+ this.trackingRangeSupplier = builder == null || builder.trackingRangeSupplier == null ? EntityType::defaultTrackingRangeSupplier : builder.trackingRangeSupplier;30+ this.updateIntervalSupplier = builder == null || builder.updateIntervalSupplier == null ? EntityType::defaultUpdateIntervalSupplier : builder.updateIntervalSupplier;31+ this.customClientFactory = builder == null ? null : builder.customClientFactory;32}3334@Nullable35@@ -1316,14 +_,26 @@36}3738public int clientTrackingRange() {39+ return trackingRangeSupplier.applyAsInt(this);40+ }41+42+ private int defaultTrackingRangeSupplier() {43return this.clientTrackingRange;44}4546public int updateInterval() {47+ return updateIntervalSupplier.applyAsInt(this);48+ }49+50+ private int defaultUpdateIntervalSupplier() {51return this.updateInterval;52}5354public boolean trackDeltas() {55+ return velocityUpdateSupplier.test(this);56+ }57+58+ private boolean defaultVelocitySupplier() {59return this != PLAYER60&& this != LLAMA_SPIT61&& this != WITHER62@@ -1383,6 +_,12 @@63return OP_ONLY_CUSTOM_DATA.contains(this);64}6566+ public T customClientSpawn(net.minecraftforge.network.packets.SpawnEntity packet, Level world) {67+ if (customClientFactory == null) return this.create(world, EntitySpawnReason.LOAD);68+ return customClientFactory.apply(packet, world);69+ }70+ public Stream<TagKey<EntityType<?>>> getTags() {return this.builtInRegistryHolder().tags();}71+72public static class Builder<T extends Entity> {73private final EntityType.EntityFactory<T> factory;74private final MobCategory category;75@@ -1402,6 +_,10 @@76);77private final DependantName<EntityType<?>, String> descriptionId = p_358878_ -> Util.makeDescriptionId("entity", p_358878_.location());78private boolean allowedInPeaceful = true;79+ private java.util.function.Predicate<EntityType<?>> velocityUpdateSupplier = EntityType::defaultVelocitySupplier;80+ private java.util.function.ToIntFunction<EntityType<?>> trackingRangeSupplier = EntityType::defaultTrackingRangeSupplier;81+ private java.util.function.ToIntFunction<EntityType<?>> updateIntervalSupplier = EntityType::defaultUpdateIntervalSupplier;82+ private java.util.function.BiFunction<net.minecraftforge.network.packets.SpawnEntity, Level, T> customClientFactory;8384private Builder(EntityType.EntityFactory<T> p_20696_, MobCategory p_20697_) {85this.factory = p_20696_;86@@ -1520,6 +_,30 @@87return this;88}8990+ public EntityType.Builder<T> setUpdateInterval(int interval) {91+ this.updateIntervalSupplier = t->interval;92+ return this;93+ }94+95+ public EntityType.Builder<T> setTrackingRange(int range) {96+ this.trackingRangeSupplier = t->range;97+ return this;98+ }99+100+ public EntityType.Builder<T> setShouldReceiveVelocityUpdates(boolean value) {101+ this.velocityUpdateSupplier = t->value;102+ return this;103+ }104+105+ /**106+ * By default, entities are spawned clientside via {@link EntityType#create(Level)}}.107+ * If you need finer control over the spawning process, use this to get read access to the spawn packet.108+ */109+ public EntityType.Builder<T> setCustomClientFactory(java.util.function.BiFunction<net.minecraftforge.network.packets.SpawnEntity, Level, T> customClientFactory) {110+ this.customClientFactory = customClientFactory;111+ return this;112+ }113+114public EntityType<T> build(ResourceKey<EntityType<?>> p_369693_) {115if (this.serialize) {116Util.fetchChoiceType(References.ENTITY_TREE, p_369693_.location().toString());117@@ -1540,7 +_,8 @@118this.descriptionId.get(p_369693_),119this.lootTable.get(p_369693_),120this.requiredFeatures,121- this.allowedInPeaceful122+ this.allowedInPeaceful,123+ this124);125}126}127128129