mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2026-01-06 15:51:31 +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 63ff39f3db2e695c8a14b021045c17f6d3d2f23d..c9de5fbb56b7b455b4c8bc59539695fd58a32566 100644
|
|
--- a/io/papermc/paper/entity/activation/ActivationRange.java
|
|
+++ b/io/papermc/paper/entity/activation/ActivationRange.java
|
|
@@ -179,6 +179,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.isInWater())) { // 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
|
|
}
|
|
}
|
|
}
|
|
@@ -190,11 +206,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 ad114ca013e0d09d40755acbe916586868a519ed..3f70fca36f67fa421314ff92d372a97112a19025 100644
|
|
--- a/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/net/minecraft/server/level/ServerLevel.java
|
|
@@ -775,6 +775,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 96341ee17591135d77d78c94814313b66eed4c3d..28e2ad1238651b8adb47b77763b0c8ae8172fe8a 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -364,6 +364,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 96e1f8f40a0af4350155f192ac2126b523c9f0f5..388689c44cf63ade939e271d490051c9b3fe8034 100644
|
|
--- a/net/minecraft/world/entity/EntityType.java
|
|
+++ b/net/minecraft/world/entity/EntityType.java
|
|
@@ -1085,6 +1085,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 dcea538d00d3751b887c71450026ce2ced0093b1..968422c673e23774f6b162ed9cdb02b9bb67f9a8 100644
|
|
--- a/net/minecraft/world/entity/Mob.java
|
|
+++ b/net/minecraft/world/entity/Mob.java
|
|
@@ -208,10 +208,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();
|
|
}
|
|
}
|
|
@@ -734,10 +734,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 653c58c7637c46c8b46a5082f671324a2221d431..55f1c138039b80894f655d180192f5cb95e32778 100644
|
|
--- a/net/minecraft/world/entity/ai/goal/GoalSelector.java
|
|
+++ b/net/minecraft/world/entity/ai/goal/GoalSelector.java
|
|
@@ -34,9 +34,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 de3bf0b62371f06ecb5d2035638e352ca0c06182..69500fa0b207fc3d5b1bc2bd665fa39f6725d23d 100644
|
|
--- a/net/minecraft/world/entity/animal/allay/Allay.java
|
|
+++ b/net/minecraft/world/entity/animal/allay/Allay.java
|
|
@@ -222,8 +222,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 6a5e9e9582e322aaa1555933de97e545ba74f8f4..3475ecbd95fac6c6b6e792a23cb15cdb3395985f 100644
|
|
--- a/net/minecraft/world/entity/animal/axolotl/Axolotl.java
|
|
+++ b/net/minecraft/world/entity/animal/axolotl/Axolotl.java
|
|
@@ -325,8 +325,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 b8703409dd3dc8e3020ed81b44ce4812984c88c3..f5c9ef8909f3852fc7a203265ae057232fa403ad 100644
|
|
--- a/net/minecraft/world/entity/animal/frog/Frog.java
|
|
+++ b/net/minecraft/world/entity/animal/frog/Frog.java
|
|
@@ -200,8 +200,10 @@ public class Frog extends Animal {
|
|
VariantUtils.readVariant(input, 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 c1510a6f1146f446ed65a1f08984af6c29de439a..5392cb211a3dc841ab38710a4ef688bde7fbe067 100644
|
|
--- a/net/minecraft/world/entity/animal/frog/Tadpole.java
|
|
+++ b/net/minecraft/world/entity/animal/frog/Tadpole.java
|
|
@@ -96,8 +96,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 bdac4929db71a39fc02985109cedc9cd316ec3cc..2a72d7f422c340dabef11a6dc680358207bee637 100644
|
|
--- a/net/minecraft/world/entity/animal/goat/Goat.java
|
|
+++ b/net/minecraft/world/entity/animal/goat/Goat.java
|
|
@@ -186,8 +186,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 bde6f9d9d1cc7a5ee8334ee9207afae304ddcfa9..084f82a7baaa309aa80cc33b4c01e54cf6da4b42 100644
|
|
--- a/net/minecraft/world/entity/monster/hoglin/Hoglin.java
|
|
+++ b/net/minecraft/world/entity/monster/hoglin/Hoglin.java
|
|
@@ -158,8 +158,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 689f200554d8c03313b3d194f209c527f315c29a..3e6cbf0166486995f7adcbd7b99a8b8c919956cd 100644
|
|
--- a/net/minecraft/world/entity/monster/piglin/Piglin.java
|
|
+++ b/net/minecraft/world/entity/monster/piglin/Piglin.java
|
|
@@ -316,8 +316,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 dd6666bd8b8df4148a1557627ce2a6ddab245ed6..6a9d3b749e251d3dac6fda13318bf5a0bf21f82b 100644
|
|
--- a/net/minecraft/world/entity/monster/warden/Warden.java
|
|
+++ b/net/minecraft/world/entity/monster/warden/Warden.java
|
|
@@ -275,8 +275,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 6cf2af33d22d3df8374746f5926f3f2d5093431d..f37759161b2a682612c6676cdd0d15908259776c 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;
|
|
}
|