mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-03 22:26:19 +00:00
335 lines
18 KiB
Diff
335 lines
18 KiB
Diff
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] Pufferfish: Dynamic Activation of Brain
|
|
|
|
Dreeam TODO: waiting Paper dealing with the newGoalRate
|
|
|
|
Original license: GPL v3
|
|
Original project: https://github.com/pufferfish-gg/Pufferfish
|
|
|
|
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 <https://www.gnu.org/licenses/>.
|
|
|
|
diff --git a/io/papermc/paper/entity/activation/ActivationRange.java b/io/papermc/paper/entity/activation/ActivationRange.java
|
|
index bdbbbc5e0c06c71584e7514623d0c8be168befd7..f3ca86e09a4a076d143fb21eac529967ff004df4 100644
|
|
--- a/io/papermc/paper/entity/activation/ActivationRange.java
|
|
+++ b/io/papermc/paper/entity/activation/ActivationRange.java
|
|
@@ -173,6 +173,22 @@ public final class ActivationRange {
|
|
}
|
|
|
|
ActivationRange.activateEntity(entity);
|
|
+
|
|
+ // Pufferfish start
|
|
+ if (org.dreeam.leaf.config.modules.opt.DynamicActivationofBrain.enabled && entity.getType().dabEnabled &&
|
|
+ (!org.dreeam.leaf.config.modules.opt.DynamicActivationofBrain.dontEnableIfInWater || entity.getType().is(net.minecraft.tags.EntityTypeTags.CAN_BREATHE_UNDER_WATER) || !entity.isInWaterOrRain())) { // Leaf - Option for dontEnableIfInWater
|
|
+ if (!entity.activatedPriorityReset) {
|
|
+ entity.activatedPriorityReset = true;
|
|
+ entity.activatedPriority = org.dreeam.leaf.config.modules.opt.DynamicActivationofBrain.maximumActivationPrio;
|
|
+ }
|
|
+ int squaredDistance = (int) player.distanceToSqr(entity);
|
|
+ entity.activatedPriority = squaredDistance > org.dreeam.leaf.config.modules.opt.DynamicActivationofBrain.startDistanceSquared ?
|
|
+ Math.max(1, Math.min(squaredDistance >> org.dreeam.leaf.config.modules.opt.DynamicActivationofBrain.activationDistanceMod, entity.activatedPriority)) :
|
|
+ 1;
|
|
+ } else {
|
|
+ entity.activatedPriority = 1;
|
|
+ }
|
|
+ // Pufferfish end
|
|
}
|
|
}
|
|
}
|
|
@@ -184,11 +200,11 @@ public final class ActivationRange {
|
|
*/
|
|
private static void activateEntity(final Entity entity) {
|
|
if (MinecraftServer.currentTick > entity.activatedTick) {
|
|
- if (entity.defaultActivationState) {
|
|
+ if (entity.defaultActivationState) { // Pufferfish - diff on change
|
|
entity.activatedTick = MinecraftServer.currentTick;
|
|
return;
|
|
}
|
|
- if (entity.activationType.boundingBox.intersects(entity.getBoundingBox())) {
|
|
+ if (entity.activationType.boundingBox.intersects(entity.getBoundingBox())) { // Pufferfish - diff on change
|
|
entity.activatedTick = MinecraftServer.currentTick;
|
|
}
|
|
}
|
|
diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java
|
|
index d99ac6eb59e10ff6af841c4496ee46fbfbf57c22..074869245407abb32775b17140e1ffadabc5fcd5 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -771,6 +771,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe
|
|
this.entityTickList
|
|
.forEach(
|
|
entity -> {
|
|
+ entity.activatedPriorityReset = false; // Pufferfish - DAB
|
|
if (!entity.isRemoved()) {
|
|
if (!tickRateManager.isEntityFrozen(entity)) {
|
|
entity.checkDespawn();
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index 8508f4b94f3e4532ce36baff4e68189540b0b59a..8370be95e4f0d1d3b99274fea415f77845ad5712 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -343,6 +343,8 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
public boolean fixedPose = false; // Paper - Expand Pose API
|
|
private final int despawnTime; // Paper - entity despawn time limit
|
|
public int totalEntityAge; // Paper - age-like counter for all entities
|
|
+ public boolean activatedPriorityReset = false; // Pufferfish - DAB
|
|
+ public int activatedPriority = org.dreeam.leaf.config.modules.opt.DynamicActivationofBrain.maximumActivationPrio; // Pufferfish - DAB (golf score)
|
|
public final io.papermc.paper.entity.activation.ActivationType activationType = io.papermc.paper.entity.activation.ActivationType.activationTypeFor(this); // Paper - EAR 2/tracking ranges
|
|
// Paper start - EAR 2
|
|
public final boolean defaultActivationState;
|
|
diff --git a/net/minecraft/world/entity/EntityType.java b/net/minecraft/world/entity/EntityType.java
|
|
index ed11697d81789ee6cd48ee2de2c9fcb8ff2be0d4..a1379aa8eaf84868ceb8b3762f7ca3b87a2d7785 100644
|
|
--- a/net/minecraft/world/entity/EntityType.java
|
|
+++ b/net/minecraft/world/entity/EntityType.java
|
|
@@ -1075,6 +1075,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
|
|
private final boolean canSpawnFarFromPlayer;
|
|
private final int clientTrackingRange;
|
|
private final int updateInterval;
|
|
+ public boolean dabEnabled = false; // Pufferfish
|
|
private final String descriptionId;
|
|
@Nullable
|
|
private Component description;
|
|
diff --git a/net/minecraft/world/entity/Mob.java b/net/minecraft/world/entity/Mob.java
|
|
index 6cc000611dc58a5487034ad87af4156059dd37d7..7e466022af0f023b409462ed4d4f3a8aa80c4183 100644
|
|
--- a/net/minecraft/world/entity/Mob.java
|
|
+++ b/net/minecraft/world/entity/Mob.java
|
|
@@ -205,10 +205,10 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
@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();
|
|
}
|
|
}
|
|
@@ -717,10 +717,14 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab
|
|
this.sensing.tick();
|
|
int i = this.tickCount + this.getId();
|
|
if (i % 2 != 0 && this.tickCount > 1) {
|
|
+ if (this.targetSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.targetSelector.tickRunningGoals(false);
|
|
+ if (this.goalSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.goalSelector.tickRunningGoals(false);
|
|
} else {
|
|
+ if (this.targetSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.targetSelector.tick();
|
|
+ if (this.goalSelector.inactiveTick(this.activatedPriority, false)) // Pufferfish - use this to alternate ticking
|
|
this.goalSelector.tick();
|
|
}
|
|
|
|
diff --git a/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java b/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java
|
|
index f6c673b1abe53afcb14fd68d590431027ed29f67..21deb221b87ecb70c8a0dc963ab79124b26ac930 100644
|
|
--- a/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java
|
|
+++ b/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java
|
|
@@ -36,7 +36,11 @@ public class VillagerPanicTrigger extends Behavior<Villager> {
|
|
|
|
@Override
|
|
protected void tick(ServerLevel level, Villager owner, long gameTime) {
|
|
- if (gameTime % 100L == 0L) {
|
|
+ // Pufferfish start
|
|
+ if (owner.nextGolemPanic < 0) owner.nextGolemPanic = gameTime + 100;
|
|
+ if (--owner.nextGolemPanic < gameTime) {
|
|
+ owner.nextGolemPanic = -1;
|
|
+ // Pufferfish end
|
|
owner.spawnGolemIfNeeded(level, gameTime, 3);
|
|
}
|
|
}
|
|
diff --git a/net/minecraft/world/entity/ai/goal/GoalSelector.java b/net/minecraft/world/entity/ai/goal/GoalSelector.java
|
|
index b816b2de8eb327060ca6ea7c4afc17373fa77ff6..e82e32407cec6109b9c3b0106295217f4a3f4aa2 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/GoalSelector.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/GoalSelector.java
|
|
@@ -36,9 +36,13 @@ public class GoalSelector {
|
|
}
|
|
|
|
// Paper start - EAR 2
|
|
- public boolean inactiveTick() {
|
|
+ public boolean inactiveTick(int tickRate, boolean inactive) { // Pufferfish start
|
|
+ if (inactive && !org.dreeam.leaf.config.modules.opt.DynamicActivationofBrain.enabled) tickRate = 4; // reset to Paper's
|
|
+ tickRate = Math.min(tickRate, 3); // Dreeam TODO - Waiting Paper
|
|
this.curRate++;
|
|
- return this.curRate % 3 == 0; // TODO newGoalRate was already unused in 1.20.4, check if this is correct
|
|
+ //return this.curRate % 3 == 0; // TODO newGoalRate was already unused in 1.20.4, check if this is correct
|
|
+ return this.curRate % tickRate == 0;
|
|
+ // Pufferfish end
|
|
}
|
|
|
|
public boolean hasTasks() {
|
|
diff --git a/net/minecraft/world/entity/animal/allay/Allay.java b/net/minecraft/world/entity/animal/allay/Allay.java
|
|
index fc2290a62c0a01cfa3143e77384f30e17d94f039..2ab261bba5f9e0babfc9072afd2ebbee0536041c 100644
|
|
--- a/net/minecraft/world/entity/animal/allay/Allay.java
|
|
+++ b/net/minecraft/world/entity/animal/allay/Allay.java
|
|
@@ -237,8 +237,10 @@ public class Allay extends PathfinderMob implements InventoryCarrier, VibrationS
|
|
return 0.4F;
|
|
}
|
|
|
|
+ private int behaviorTick = 0; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep(ServerLevel level) {
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
this.getBrain().tick(level, this);
|
|
AllayAi.updateActivity(this);
|
|
super.customServerAiStep(level);
|
|
diff --git a/net/minecraft/world/entity/animal/axolotl/Axolotl.java b/net/minecraft/world/entity/animal/axolotl/Axolotl.java
|
|
index d3d4d8b025480f9e2202157591319df3af43f9de..f54b854adedd58a37b5c38c63abc3fc94ed9ba80 100644
|
|
--- a/net/minecraft/world/entity/animal/axolotl/Axolotl.java
|
|
+++ b/net/minecraft/world/entity/animal/axolotl/Axolotl.java
|
|
@@ -323,8 +323,10 @@ public class Axolotl extends Animal implements Bucketable {
|
|
return true;
|
|
}
|
|
|
|
+ private int behaviorTick = 0; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep(ServerLevel level) {
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
this.getBrain().tick(level, this);
|
|
AxolotlAi.updateActivity(this);
|
|
if (!this.isNoAi()) {
|
|
diff --git a/net/minecraft/world/entity/animal/frog/Frog.java b/net/minecraft/world/entity/animal/frog/Frog.java
|
|
index fdf40dc10aad108db6ca68fcfec9ecf48f76a9c1..bd80e58179fe577693fa419a77989b0db39abb04 100644
|
|
--- a/net/minecraft/world/entity/animal/frog/Frog.java
|
|
+++ b/net/minecraft/world/entity/animal/frog/Frog.java
|
|
@@ -199,8 +199,10 @@ public class Frog extends Animal {
|
|
VariantUtils.readVariant(compound, this.registryAccess(), Registries.FROG_VARIANT).ifPresent(this::setVariant);
|
|
}
|
|
|
|
+ private int behaviorTick = 0; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep(ServerLevel level) {
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
this.getBrain().tick(level, this);
|
|
FrogAi.updateActivity(this);
|
|
super.customServerAiStep(level);
|
|
diff --git a/net/minecraft/world/entity/animal/frog/Tadpole.java b/net/minecraft/world/entity/animal/frog/Tadpole.java
|
|
index faaa8197e8421c2bbdc2a8bbaae4f4d0820dbbe7..72c4403a4b5fa817f91dbcd842d4b7939a4834ab 100644
|
|
--- a/net/minecraft/world/entity/animal/frog/Tadpole.java
|
|
+++ b/net/minecraft/world/entity/animal/frog/Tadpole.java
|
|
@@ -94,8 +94,10 @@ public class Tadpole extends AbstractFish {
|
|
return SoundEvents.TADPOLE_FLOP;
|
|
}
|
|
|
|
+ private int behaviorTick = 0; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep(ServerLevel level) {
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
this.getBrain().tick(level, this);
|
|
TadpoleAi.updateActivity(this);
|
|
super.customServerAiStep(level);
|
|
diff --git a/net/minecraft/world/entity/animal/goat/Goat.java b/net/minecraft/world/entity/animal/goat/Goat.java
|
|
index 9047e75a5edf9fec2b73aec272284d8003793eaa..048e62b361e33b3edd5122fd4a47c5627491bcaf 100644
|
|
--- a/net/minecraft/world/entity/animal/goat/Goat.java
|
|
+++ b/net/minecraft/world/entity/animal/goat/Goat.java
|
|
@@ -185,8 +185,10 @@ public class Goat extends Animal {
|
|
return (Brain<Goat>)super.getBrain();
|
|
}
|
|
|
|
+ private int behaviorTick = 0; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep(ServerLevel level) {
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
this.getBrain().tick(level, this);
|
|
GoatAi.updateActivity(this);
|
|
super.customServerAiStep(level);
|
|
diff --git a/net/minecraft/world/entity/monster/hoglin/Hoglin.java b/net/minecraft/world/entity/monster/hoglin/Hoglin.java
|
|
index 2989add9a4746646f06ec3f6c386ac5df4a64726..6691dc90c35d05a7c28c4e3ac887ed9d3bb88de9 100644
|
|
--- a/net/minecraft/world/entity/monster/hoglin/Hoglin.java
|
|
+++ b/net/minecraft/world/entity/monster/hoglin/Hoglin.java
|
|
@@ -157,8 +157,10 @@ public class Hoglin extends Animal implements Enemy, HoglinBase {
|
|
return (Brain<Hoglin>)super.getBrain();
|
|
}
|
|
|
|
+ private int behaviorTick; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep(ServerLevel level) {
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
this.getBrain().tick(level, this);
|
|
HoglinAi.updateActivity(this);
|
|
if (this.isConverting()) {
|
|
diff --git a/net/minecraft/world/entity/monster/piglin/Piglin.java b/net/minecraft/world/entity/monster/piglin/Piglin.java
|
|
index 27052ded60db7c3916de3f4c8b48227f53fd7249..634c518c105c8dc50838a4a6690641d82fd637fb 100644
|
|
--- a/net/minecraft/world/entity/monster/piglin/Piglin.java
|
|
+++ b/net/minecraft/world/entity/monster/piglin/Piglin.java
|
|
@@ -315,8 +315,10 @@ public class Piglin extends AbstractPiglin implements CrossbowAttackMob, Invento
|
|
return !this.cannotHunt;
|
|
}
|
|
|
|
+ private int behaviorTick; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep(ServerLevel level) {
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
this.getBrain().tick(level, this);
|
|
PiglinAi.updateActivity(this);
|
|
super.customServerAiStep(level);
|
|
diff --git a/net/minecraft/world/entity/monster/warden/Warden.java b/net/minecraft/world/entity/monster/warden/Warden.java
|
|
index 67fdcbe05e8d5f4000255f753565591825f54f67..42ca4243d86ef4a14a9ce70da4b79f6c8eeb3a7d 100644
|
|
--- a/net/minecraft/world/entity/monster/warden/Warden.java
|
|
+++ b/net/minecraft/world/entity/monster/warden/Warden.java
|
|
@@ -277,8 +277,10 @@ public class Warden extends Monster implements VibrationSystem {
|
|
}
|
|
}
|
|
|
|
+ private int behaviorTick = 0; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep(ServerLevel level) {
|
|
+ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish
|
|
this.getBrain().tick(level, this);
|
|
super.customServerAiStep(level);
|
|
if ((this.tickCount + this.getId()) % 120 == 0) {
|
|
diff --git a/net/minecraft/world/entity/npc/Villager.java b/net/minecraft/world/entity/npc/Villager.java
|
|
index c62eee45d661b6f9d2b862a709b4d23645ed41e6..202bcb28218b0d9a2a5e211fee173ecd5f625896 100644
|
|
--- a/net/minecraft/world/entity/npc/Villager.java
|
|
+++ b/net/minecraft/world/entity/npc/Villager.java
|
|
@@ -177,6 +177,8 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
|
(villager, poiType) -> poiType.is(PoiTypes.MEETING)
|
|
);
|
|
|
|
+ public long nextGolemPanic = -1; // Pufferfish
|
|
+
|
|
public Villager(EntityType<? extends Villager> entityType, Level level) {
|
|
this(entityType, level, VillagerType.PLAINS);
|
|
}
|
|
@@ -285,6 +287,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
|
}
|
|
// Paper end - EAR 2
|
|
|
|
+ private int behaviorTick = 0; // Pufferfish
|
|
@Override
|
|
protected void customServerAiStep(ServerLevel level) {
|
|
// Paper start - EAR 2
|
|
@@ -292,7 +295,11 @@ public class Villager extends AbstractVillager implements ReputationEventHandler
|
|
}
|
|
protected void customServerAiStep(ServerLevel level, final boolean inactive) {
|
|
// Paper end - EAR 2
|
|
- if (!inactive) this.getBrain().tick(level, this); // Paper - EAR 2
|
|
+ // Pufferfish start
|
|
+ if (!inactive && this.behaviorTick++ % this.activatedPriority == 0) {
|
|
+ this.getBrain().tick(level, this); // Paper - EAR 2
|
|
+ }
|
|
+ // Pufferfish end
|
|
if (this.assignProfessionWhenSpawned) {
|
|
this.assignProfessionWhenSpawned = false;
|
|
}
|