/
0015-Dynamic-Activation-of-Brain.patch
346 lines (323 loc) · 18.1 KB
/
0015-Dynamic-Activation-of-Brain.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Paul Sauve <paul@technove.co>
Date: Fri, 15 Jan 2021 19:05:01 -0600
Subject: [PATCH] Dynamic Activation of Brain
This replaces the current method of ticking an inactive entity's
pathfinder 1/4 times with a new method that's dynamic based off how far
away it is from a player. If an entity is within 32 blocks, it gets
ticked every tick. If it's within 45 blocks, it gets ticked every other
tick. If it's within 55 blocks, it gets ticked once every three ticks.
(these numbers have since been changed, but the idea is the same.)
Airplane
Copyright (C) 2020 Technove LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
diff --git a/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java b/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java
index 8a854f830fbec0c674d4266552602cee3e07af9b..a2d35abb0cf6054323896c2dff52b95e64050e71 100644
--- a/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java
+++ b/src/main/java/gg/pufferfish/pufferfish/PufferfishConfig.java
@@ -2,6 +2,12 @@ package gg.pufferfish.pufferfish;
import java.io.File;
import java.io.IOException;
+import java.util.Collections;
+import net.minecraft.server.MinecraftServer;
+import org.apache.logging.log4j.Level;
+import org.bukkit.configuration.ConfigurationSection;
+import net.minecraft.core.Registry;
+import net.minecraft.world.entity.EntityType;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.List;
@@ -179,5 +185,37 @@ public class PufferfishConfig {
}
-}
+ public static boolean dearEnabled;
+ public static int startDistance;
+ public static int startDistanceSquared;
+ public static int maximumActivationPrio;
+ public static int activationDistanceMod;
+
+ private static void dynamicActivationOfBrains() throws IOException {
+ dearEnabled = getBoolean("dab.enabled", "activation-range.enabled", true);
+ startDistance = getInt("dab.start-distance", "activation-range.start-distance", 12,
+ "This value determines how far away an entity has to be",
+ "from the player to start being effected by DEAR.");
+ startDistanceSquared = startDistance * startDistance;
+ maximumActivationPrio = getInt("dab.max-tick-freq", "activation-range.max-tick-freq", 20,
+ "This value defines how often in ticks, the furthest entity",
+ "will get their pathfinders and behaviors ticked. 20 = 1s");
+ activationDistanceMod = getInt("dab.activation-dist-mod", "activation-range.activation-dist-mod", 8,
+ "This value defines how much distance modifies an entity's",
+ "tick frequency. freq = (distanceToPlayer^2) / (2^value)",
+ "If you want further away entities to tick less often, use 7.",
+ "If you want further away entities to tick more often, try 9.");
+
+ for (EntityType<?> entityType : Registry.ENTITY_TYPE) {
+ entityType.dabEnabled = true; // reset all, before setting the ones to true
+ }
+ getStringList("dab.blacklisted-entities", "activation-range.blacklisted-entities", Collections.emptyList(), "A list of entities to ignore for activation")
+ .forEach(name -> EntityType.byString(name).ifPresentOrElse(entityType -> {
+ entityType.dabEnabled = false;
+ }, () -> MinecraftServer.LOGGER.log(Level.WARN, "Unknown entity \"" + name + "\"")));
+
+ setComment("dab", "Optimizes entity brains when", "they're far away from the player");
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 4fae47c51b39828c06f0c10d3a549285620cc8f9..a1088c0bc4017a49c28bc4a652f2b82728672195 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -343,6 +343,10 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, i
return this.originWorld;
}
// Paper end
+ // Pufferfish start
+ public int activatedPriority = gg.pufferfish.pufferfish.PufferfishConfig.maximumActivationPrio; // golf score
+ // Pufferfish end
+
public float getBukkitYaw() {
return this.yRot;
}
diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java
index 7307b3208f1b4ffe31fc4e6f73ac7264eb95849a..fce7a9c1c1477d1b02a4adbe0bc5a5c97b8c93c9 100644
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
@@ -304,6 +304,7 @@ public class EntityType<T extends Entity> implements EntityTypeTest<Entity, T> {
return Registry.ENTITY_TYPE.getOptional(ResourceLocation.tryParse(id));
}
+ public boolean dabEnabled = false; // Pufferfish
// Paper start - add id
public final String id;
diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java
index c0c69fc680b713794bfafe64d356341b80d7c47e..37d82403dc8a36bfa8b38f9e4736e388d78e1167 100644
--- a/src/main/java/net/minecraft/world/entity/Mob.java
+++ b/src/main/java/net/minecraft/world/entity/Mob.java
@@ -214,10 +214,10 @@ public abstract class Mob extends LivingEntity {
@Override
public void inactiveTick() {
super.inactiveTick();
- if (this.goalSelector.inactiveTick()) {
+ if (this.goalSelector.inactiveTick(this.activatedPriority, true)) { // Pufferfish - pass activated priroity
this.goalSelector.tick();
}
- if (this.targetSelector.inactiveTick()) {
+ if (this.targetSelector.inactiveTick(this.activatedPriority, true)) { // Pufferfish - pass activated priority
this.targetSelector.tick();
}
}
@@ -881,16 +881,20 @@ public abstract class Mob extends LivingEntity {
if (i % 2 != 0 && this.tickCount > 1) {
this.level.getProfiler().push("targetSelector");
+ if (this.targetSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
this.targetSelector.tickRunningGoals(false);
this.level.getProfiler().pop();
this.level.getProfiler().push("goalSelector");
+ if (this.goalSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
this.goalSelector.tickRunningGoals(false);
this.level.getProfiler().pop();
} else {
this.level.getProfiler().push("targetSelector");
+ if (this.targetSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
this.targetSelector.tick();
this.level.getProfiler().pop();
this.level.getProfiler().push("goalSelector");
+ if (this.goalSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
this.goalSelector.tick();
this.level.getProfiler().pop();
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java b/src/main/java/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java
index 42d466f7f162943886078eba3db18f2dfc2d7bee..6c0dda1ce018ec6bb2ebb97147045fffae0a89d5 100644
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java
+++ b/src/main/java/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java
@@ -37,7 +37,11 @@ public class VillagerPanicTrigger extends Behavior<Villager> {
@Override
protected void tick(ServerLevel serverLevel, Villager villager, long l) {
- if (l % 100L == 0L) {
+ // Pufferfish start
+ if (villager.nextGolemPanic < 0) villager.nextGolemPanic = l + 100;
+ if (--villager.nextGolemPanic < l) {
+ villager.nextGolemPanic = -1;
+ // Pufferfish end
villager.spawnGolemIfNeeded(serverLevel, l, 3);
}
diff --git a/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
index 7fdc1cbd04a5bba9648272985f51c849b07b8223..02f44b5682b99417f3cd6d6b25dc46cdc2a09093 100644
--- a/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
+++ b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java
@@ -51,9 +51,12 @@ public class GoalSelector {
}
// Paper start
- public boolean inactiveTick() {
+ public boolean inactiveTick(int tickRate, boolean inactive) { // Pufferfish start
+ if (inactive && !gg.pufferfish.pufferfish.PufferfishConfig.dearEnabled) tickRate = 4; // reset to Paper's
+ tickRate = Math.min(tickRate, this.newGoalRate);
this.curRate++;
- return this.curRate % this.newGoalRate == 0;
+ return this.curRate % tickRate == 0;
+ // Pufferfish end
}
public boolean hasTasks() {
for (WrappedGoal task : this.availableGoals) {
diff --git a/src/main/java/net/minecraft/world/entity/animal/axolotl/Axolotl.java b/src/main/java/net/minecraft/world/entity/animal/axolotl/Axolotl.java
index 96c2920a808a0ab7fbd52677f29955d1b73ca290..a41e32fb0c2545c2ddb6651881ff05fea0b6c3a3 100644
--- a/src/main/java/net/minecraft/world/entity/animal/axolotl/Axolotl.java
+++ b/src/main/java/net/minecraft/world/entity/animal/axolotl/Axolotl.java
@@ -313,9 +313,11 @@ public class Axolotl extends Animal implements LerpingModel, Bucketable {
return true;
}
+ private int behaviorTick = 0; // Pufferfish
@Override
protected void customServerAiStep() {
this.level.getProfiler().push("axolotlBrain");
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
this.getBrain().tick((ServerLevel) this.level, this);
this.level.getProfiler().pop();
this.level.getProfiler().push("axolotlActivityUpdate");
diff --git a/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java b/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java
index 66106dc6879b7b37dd149131a5fe751b788a15fa..a98845eb04db68ac7250c435920c109856f61618 100644
--- a/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java
+++ b/src/main/java/net/minecraft/world/entity/animal/goat/Goat.java
@@ -178,10 +178,12 @@ public class Goat extends Animal {
return (Brain<Goat>) super.getBrain(); // CraftBukkit - decompile error
}
+ private int behaviorTick = 0; // Pufferfish
@Override
protected void customServerAiStep() {
this.level.getProfiler().push("goatBrain");
- if (getRider() == null) // Purpur - only use brain if no rider
+ // if (getRider() == null) // Purpur - only use brain if no rider // Pufferfish - diff on change
+ if (this.behaviorTick++ % this.activatedPriority == 0 && getRider() == null) // Pufferfish
this.getBrain().tick((ServerLevel) this.level, this);
this.level.getProfiler().pop();
this.level.getProfiler().push("goatActivityUpdate");
diff --git a/src/main/java/net/minecraft/world/entity/monster/hoglin/Hoglin.java b/src/main/java/net/minecraft/world/entity/monster/hoglin/Hoglin.java
index 170b48953a4bf494d92ded572f27711fc50a2723..972c7405e254a493e0a24dda96ab6042ae79a419 100644
--- a/src/main/java/net/minecraft/world/entity/monster/hoglin/Hoglin.java
+++ b/src/main/java/net/minecraft/world/entity/monster/hoglin/Hoglin.java
@@ -158,10 +158,12 @@ public class Hoglin extends Animal implements Enemy, HoglinBase {
return (Brain<Hoglin>) super.getBrain(); // Purpur - decompile fix
}
+ private int behaviorTick; // Pufferfish
@Override
protected void customServerAiStep() {
this.level.getProfiler().push("hoglinBrain");
- if (getRider() == null) // Purpur - only use brain if no rider
+ // if (getRider() == null) // Purpur - only use brain if no rider // Pufferfish - diff on change
+ if (this.behaviorTick++ % this.activatedPriority == 0 && getRider() == null) // Pufferfish
this.getBrain().tick((ServerLevel)this.level, this);
this.level.getProfiler().pop();
HoglinAi.updateActivity(this);
diff --git a/src/main/java/net/minecraft/world/entity/monster/piglin/Piglin.java b/src/main/java/net/minecraft/world/entity/monster/piglin/Piglin.java
index 4d72739ff70a7c116686cf74546a336852ac978c..1ec9a533ea7d95b64d27de5f70b06fc32a97a9c6 100644
--- a/src/main/java/net/minecraft/world/entity/monster/piglin/Piglin.java
+++ b/src/main/java/net/minecraft/world/entity/monster/piglin/Piglin.java
@@ -315,10 +315,12 @@ public class Piglin extends AbstractPiglin implements CrossbowAttackMob, Invento
return !this.cannotHunt;
}
+ private int behaviorTick; // Pufferfish
@Override
protected void customServerAiStep() {
this.level.getProfiler().push("piglinBrain");
- if (getRider() == null) // Purpur - only use brain if no rider
+ // if (getRider() == null) // Purpur - only use brain if no rider // Pufferfish - diff on change
+ if (this.behaviorTick++ % this.activatedPriority == 0 && getRider() == null) // Pufferfish
this.getBrain().tick((ServerLevel) this.level, this);
this.level.getProfiler().pop();
PiglinAi.updateActivity(this);
diff --git a/src/main/java/net/minecraft/world/entity/npc/Villager.java b/src/main/java/net/minecraft/world/entity/npc/Villager.java
index efb98dd788b5b8ce51c92847c585e5ee9c0465f3..3a0f0d62dc57cf53cf10775c7ae4d940a3e96243 100644
--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java
+++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java
@@ -139,6 +139,8 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
});
private final int brainTickOffset; // Purpur
+ public long nextGolemPanic = -1; // Pufferfish
+
public Villager(EntityType<? extends Villager> entityType, Level world) {
this(entityType, world, VillagerType.PLAINS);
}
@@ -281,15 +283,23 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
}
// Spigot End
+ private int behaviorTick = 0; // Pufferfish
@Override
protected void customServerAiStep() { mobTick(false); }
protected void mobTick(boolean inactive) {
this.level.getProfiler().push("villagerBrain");
+ /* // Pufferfish - remove purpur patch
// Purpur start
boolean tick = (level.getGameTime() + brainTickOffset) % level.purpurConfig.villagerBrainTicks == 0;
if (((ServerLevel) level).getServer().lagging ? tick : level.purpurConfig.villagerUseBrainTicksOnlyWhenLagging || tick)
// Purpur end
- if (!inactive) this.getBrain().tick((ServerLevel) this.level, this); // Paper
+ */ // Pufferfish - remove purpur patch
+ // Pufferfish start
+ if (!inactive) {
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
+ this.getBrain().tick((ServerLevel) this.level, this); // Paper
+ }
+ // Pufferfish end
this.level.getProfiler().pop();
if (this.assignProfessionWhenSpawned) {
this.assignProfessionWhenSpawned = false;
diff --git a/src/main/java/org/spigotmc/ActivationRange.java b/src/main/java/org/spigotmc/ActivationRange.java
index d96a5bc1bba1a5ed86bc5f096b7a69c34391fb9e..59b4e5595b1066e1cc1c37ef9e8af0dd5cf6bd68 100644
--- a/src/main/java/org/spigotmc/ActivationRange.java
+++ b/src/main/java/org/spigotmc/ActivationRange.java
@@ -38,6 +38,10 @@ import co.aikar.timings.MinecraftTimings;
import net.minecraft.world.entity.schedule.Activity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.AABB;
+// Pufferfish start
+import net.minecraft.world.phys.Vec3;
+import java.util.List;
+// Pufferfish end
public class ActivationRange
{
@@ -212,6 +216,21 @@ public class ActivationRange
for (int i = 0; i < entities.size(); i++) {
Entity entity = entities.get(i);
ActivationRange.activateEntity(entity);
+
+ // Pufferfish start
+ if (gg.pufferfish.pufferfish.PufferfishConfig.dearEnabled && entity.getType().dabEnabled) {
+ Vec3 playerVec = player.position();
+ Vec3 entityVec = entity.position();
+ double diffX = playerVec.x - entityVec.x, diffY = playerVec.y - entityVec.y, diffZ = playerVec.z - entityVec.z;
+ int squaredDistance = (int) (diffX * diffX + diffY * diffY + diffZ * diffZ);
+ entity.activatedPriority = squaredDistance > gg.pufferfish.pufferfish.PufferfishConfig.startDistanceSquared ?
+ Math.max(1, Math.min(squaredDistance >> gg.pufferfish.pufferfish.PufferfishConfig.activationDistanceMod, gg.pufferfish.pufferfish.PufferfishConfig.maximumActivationPrio)) :
+ 1;
+ } else {
+ entity.activatedPriority = 1;
+ }
+ // Pufferfish end
+
}
// Paper end
}
@@ -228,12 +247,12 @@ public class ActivationRange
if ( MinecraftServer.currentTick > entity.activatedTick )
{
if ( entity.defaultActivationState )
- {
+ { // Pufferfish - diff on change
entity.activatedTick = MinecraftServer.currentTick;
return;
}
if ( entity.activationType.boundingBox.intersects( entity.getBoundingBox() ) )
- {
+ { // Pufferfish - diff on change
entity.activatedTick = MinecraftServer.currentTick;
}
}