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