From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: NONPLAYT <76615486+NONPLAYT@users.noreply.github.com> Date: Sun, 23 Mar 2025 01:16:35 +0300 Subject: [PATCH] Dynamic Activation of Brain diff --git a/io/papermc/paper/entity/activation/ActivationRange.java b/io/papermc/paper/entity/activation/ActivationRange.java index ae0a3c3d9d6300293a6d0dff5cae49ebe7c11dab..3b08dad7a9fac7ac9acec0bfb85d4826452bdc99 100644 --- a/io/papermc/paper/entity/activation/ActivationRange.java +++ b/io/papermc/paper/entity/activation/ActivationRange.java @@ -161,6 +161,21 @@ public final class ActivationRange { } ActivationRange.activateEntity(entity); + + // DivineMC start - Dynamic Activation of Brain + if (org.bxteam.divinemc.DivineConfig.dabEnabled && entity.getType().dabEnabled && (!org.bxteam.divinemc.DivineConfig.dabDontEnableIfInWater || entity.getType().is(net.minecraft.tags.EntityTypeTags.CAN_BREATHE_UNDER_WATER) || !entity.isInWaterOrBubble())) { + if (!entity.activatedPriorityReset) { + entity.activatedPriorityReset = true; + entity.activatedPriority = org.bxteam.divinemc.DivineConfig.dabMaximumActivationFrequency; + } + int squaredDistance = (int) player.distanceToSqr(entity); + entity.activatedPriority = squaredDistance > org.bxteam.divinemc.DivineConfig.dabStartDistanceSquared ? + Math.max(1, Math.min(squaredDistance >> org.bxteam.divinemc.DivineConfig.dabActivationDistanceMod, entity.activatedPriority)) : + 1; + } else { + entity.activatedPriority = 1; + } + // DivineMC end - Dynamic Activation of Brain } } } diff --git a/net/minecraft/server/level/ServerLevel.java b/net/minecraft/server/level/ServerLevel.java index 561066a2cf769e13ef3cea0881f7a2010ecbf2ec..5fe908ce51f95e1eab024dcd41ed108373f17fea 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -818,6 +818,7 @@ public class ServerLevel extends Level implements ServerEntityGetter, WorldGenLe this.entityTickList .forEach( entity -> { + entity.activatedPriorityReset = false; // DivineMC - Dynamic Activation of Brain 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 04ae7636d14a40a427b5d9b746632b0c489efa21..f1cd66d7d96771bc4967e214f70c756fec30efe5 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -336,6 +336,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; // DivineMC - Dynamic Activation of Brain + public int activatedPriority = org.bxteam.divinemc.DivineConfig.dabMaximumActivationFrequency; // DivineMC - Dynamic Activation of Brain 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 4186db5cb8d2cd29ebc230d704dd125ae0dfa358..79593dc0e42e4cf0aee5e7b8cac4aca186887d6f 100644 --- a/net/minecraft/world/entity/EntityType.java +++ b/net/minecraft/world/entity/EntityType.java @@ -1063,6 +1063,7 @@ public class EntityType implements FeatureElement, EntityTypeT private final boolean canSpawnFarFromPlayer; private final int clientTrackingRange; private final int updateInterval; + public boolean dabEnabled = false; // DivineMC - Dynamic Activation of Brain 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 b4e19cc65701d5ef94e1cc0a7473225c222725c3..00daf8de01bf23f55ba8af12d3e3e551d981c61c 100644 --- a/net/minecraft/world/entity/Mob.java +++ b/net/minecraft/world/entity/Mob.java @@ -218,10 +218,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)) { // DivineMC - Dynamic Activation of Brain this.goalSelector.tick(); } - if (this.targetSelector.inactiveTick()) { + if (this.targetSelector.inactiveTick(this.activatedPriority, true)) { // DivineMC - Dynamic Activation of Brain this.targetSelector.tick(); } } @@ -888,13 +888,19 @@ public abstract class Mob extends LivingEntity implements EquipmentUser, Leashab // Paper end - Allow nerfed mobs to jump and float this.sensing.tick(); int i = this.tickCount + this.getId(); + // DivineMC start - Dynamic Activation of Brain if (i % 2 != 0 && this.tickCount > 1) { - this.targetSelector.tickRunningGoals(false); - this.goalSelector.tickRunningGoals(false); + if (this.targetSelector.inactiveTick(this.activatedPriority, false)) + this.targetSelector.tickRunningGoals(false); + if (this.goalSelector.inactiveTick(this.activatedPriority, false)) + this.goalSelector.tickRunningGoals(false); } else { - this.targetSelector.tick(); - this.goalSelector.tick(); + if (this.targetSelector.inactiveTick(this.activatedPriority, false)) + this.targetSelector.tick(); + if (this.goalSelector.inactiveTick(this.activatedPriority, false)) + this.goalSelector.tick(); } + // DivineMC end - Dynamic Activation of Brain this.navigation.tick(); this.customServerAiStep((ServerLevel)this.level()); diff --git a/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java b/net/minecraft/world/entity/ai/behavior/VillagerPanicTrigger.java index f6c673b1abe53afcb14fd68d590431027ed29f67..1e5312e02298c63c168526a960d688dc03581cee 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 { @Override protected void tick(ServerLevel level, Villager owner, long gameTime) { - if (gameTime % 100L == 0L) { + // DivineMC start - Dynamic Activation of Brain + if (owner.nextGolemPanic < 0) owner.nextGolemPanic = gameTime + 100; + if (--owner.nextGolemPanic < gameTime) { + owner.nextGolemPanic = -1; + // DivineMC end - Dynamic Activation of Brain 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..4eed0bd3670fdcb0a156c29e7db63233a47f539b 100644 --- a/net/minecraft/world/entity/ai/goal/GoalSelector.java +++ b/net/minecraft/world/entity/ai/goal/GoalSelector.java @@ -36,10 +36,14 @@ public class GoalSelector { } // Paper start - EAR 2 - public boolean inactiveTick() { + // DivineMC start - Dynamic Activation of Brain + public boolean inactiveTick(int tickRate, boolean inactive) { + if (inactive && !org.bxteam.divinemc.DivineConfig.dabEnabled) tickRate = 4; + tickRate = Math.min(tickRate, 3); this.curRate++; - return this.curRate % 3 == 0; // TODO newGoalRate was already unused in 1.20.4, check if this is correct + return this.curRate % tickRate == 0; } + // DivineMC end - Dynamic Activation of Brain public boolean hasTasks() { for (WrappedGoal task : this.availableGoals) { diff --git a/net/minecraft/world/entity/animal/allay/Allay.java b/net/minecraft/world/entity/animal/allay/Allay.java index b2c9da89ae6044536f4996fdbd37e2cabf22ca12..fa9672e890f327dbdec57eadc258bbae8e98e91e 100644 --- a/net/minecraft/world/entity/animal/allay/Allay.java +++ b/net/minecraft/world/entity/animal/allay/Allay.java @@ -118,6 +118,7 @@ public class Allay extends PathfinderMob implements InventoryCarrier, VibrationS private float spinningAnimationTicks0; public boolean forceDancing = false; // CraftBukkit private org.purpurmc.purpur.controller.FlyingMoveControllerWASD purpurController; // Purpur - Ridables + private int behaviorTick = 0; // DivineMC - Dynamic Activation of Brain public Allay(EntityType entityType, Level level) { super(entityType, level); @@ -287,9 +288,13 @@ public class Allay extends PathfinderMob implements InventoryCarrier, VibrationS @Override protected void customServerAiStep(ServerLevel level) { //if ((getRider() == null || !this.isControllable()) && this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish // Purpur - only use brain if no rider - this.getBrain().tick(level, this); - AllayAi.updateActivity(this); - super.customServerAiStep(level); + // DivineMC start - Dynamic Activation of Brain + if (this.behaviorTick++ % this.activatedPriority == 0) { + this.getBrain().tick(level, this); + AllayAi.updateActivity(this); + super.customServerAiStep(level); + } + // DivineMC end - Dynamic Activation of Brain } @Override diff --git a/net/minecraft/world/entity/animal/axolotl/Axolotl.java b/net/minecraft/world/entity/animal/axolotl/Axolotl.java index bbfe48fd278cda9926793d0d2de743558fefd622..3f7c48282577a2de20e78b69ddcbc08347318fd3 100644 --- a/net/minecraft/world/entity/animal/axolotl/Axolotl.java +++ b/net/minecraft/world/entity/animal/axolotl/Axolotl.java @@ -105,6 +105,7 @@ public class Axolotl extends Animal implements VariantHolder, B public final BinaryAnimator onGroundAnimator = new BinaryAnimator(10, Mth::easeInOutSine); public final BinaryAnimator movingAnimator = new BinaryAnimator(10, Mth::easeInOutSine); private static final int REGEN_BUFF_BASE_DURATION = 100; + private int behaviorTick = 0; // DivineMC - Dynamic Activation of Brain public Axolotl(EntityType entityType, Level level) { super(entityType, level); @@ -347,12 +348,16 @@ public class Axolotl extends Animal implements VariantHolder, B @Override protected void customServerAiStep(ServerLevel level) { //if ((getRider() == null || !this.isControllable()) && this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish // Purpur - only use brain if no rider - this.getBrain().tick(level, this); - AxolotlAi.updateActivity(this); - if (!this.isNoAi()) { - Optional memory = this.getBrain().getMemory(MemoryModuleType.PLAY_DEAD_TICKS); - this.setPlayingDead(memory.isPresent() && memory.get() > 0); + // DivineMC start - Dynamic Activation of Brain + if (this.behaviorTick++ % this.activatedPriority == 0) { + this.getBrain().tick(level, this); + AxolotlAi.updateActivity(this); + if (!this.isNoAi()) { + Optional memory = this.getBrain().getMemory(MemoryModuleType.PLAY_DEAD_TICKS); + this.setPlayingDead(memory.isPresent() && memory.get() > 0); + } } + // DivineMC end - Dynamic Activation of Brain } public static AttributeSupplier.Builder createAttributes() { diff --git a/net/minecraft/world/entity/animal/frog/Frog.java b/net/minecraft/world/entity/animal/frog/Frog.java index dfcba5c2c8a489ebe74c2d5c1fa980c401806757..1827dead0a0a1d8e9dfbcc44038c9dbfbefddd48 100644 --- a/net/minecraft/world/entity/animal/frog/Frog.java +++ b/net/minecraft/world/entity/animal/frog/Frog.java @@ -106,6 +106,7 @@ public class Frog extends Animal implements VariantHolder> { public final AnimationState swimIdleAnimationState = new AnimationState(); private org.purpurmc.purpur.controller.MoveControllerWASD purpurLandController; // Purpur - Ridables private org.purpurmc.purpur.controller.WaterMoveControllerWASD purpurWaterController; // Purpur - Ridables + private int behaviorTick = 0; // DivineMC - Dynamic Activation of Brain public Frog(EntityType entityType, Level level) { super(entityType, level); @@ -242,9 +243,13 @@ public class Frog extends Animal implements VariantHolder> { @Override protected void customServerAiStep(ServerLevel level) { //if ((getRider() == null || !this.isControllable()) && this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish // Purpur - only use brain if no rider - this.getBrain().tick(level, this); - FrogAi.updateActivity(this); - super.customServerAiStep(level); + // DivineMC start - Dynamic Activation of Brain + if (this.behaviorTick++ % this.activatedPriority == 0) { + this.getBrain().tick(level, this); + FrogAi.updateActivity(this); + super.customServerAiStep(level); + } + // DivineMC end - Dynamic Activation of Brain } @Override diff --git a/net/minecraft/world/entity/animal/frog/Tadpole.java b/net/minecraft/world/entity/animal/frog/Tadpole.java index 78d256f6a95acb367efd690bc368d2106a928b8f..b32fabed65f929cb8d2c8c93667f2e45b9bef0b8 100644 --- a/net/minecraft/world/entity/animal/frog/Tadpole.java +++ b/net/minecraft/world/entity/animal/frog/Tadpole.java @@ -62,6 +62,7 @@ public class Tadpole extends AbstractFish { ); public boolean ageLocked; // Paper private org.purpurmc.purpur.controller.WaterMoveControllerWASD purpurController; // Purpur - Ridables + private int behaviorTick = 0; // DivineMC - Dynamic Activation of Brain public Tadpole(EntityType entityType, Level level) { super(entityType, level); @@ -133,9 +134,13 @@ public class Tadpole extends AbstractFish { @Override protected void customServerAiStep(ServerLevel level) { //if ((getRider() == null || !this.isControllable()) && this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish // Purpur - only use brain if no rider - this.getBrain().tick(level, this); - TadpoleAi.updateActivity(this); - super.customServerAiStep(level); + // DivineMC start - Dynamic Activation of Brain + if (this.behaviorTick++ % this.activatedPriority == 0) { + this.getBrain().tick(level, this); + TadpoleAi.updateActivity(this); + super.customServerAiStep(level); + } + // DivineMC end - Dynamic Activation of Brain } public static AttributeSupplier.Builder createAttributes() { diff --git a/net/minecraft/world/entity/animal/goat/Goat.java b/net/minecraft/world/entity/animal/goat/Goat.java index e21f024d0ed7f936ff17df16bd9666fffbf44a75..1f46d9e9def33458001c4c30bf2e37486646d23f 100644 --- a/net/minecraft/world/entity/animal/goat/Goat.java +++ b/net/minecraft/world/entity/animal/goat/Goat.java @@ -90,6 +90,7 @@ public class Goat extends Animal { public static final EntityDataAccessor DATA_HAS_RIGHT_HORN = SynchedEntityData.defineId(Goat.class, EntityDataSerializers.BOOLEAN); private boolean isLoweringHead; private int lowerHeadTick; + private int behaviorTick = 0; // DivineMC - Dynamic Activation of Brain public Goat(EntityType entityType, Level level) { super(entityType, level); @@ -230,9 +231,13 @@ public class Goat extends Animal { @Override protected void customServerAiStep(ServerLevel level) { //if ((getRider() == null || !this.isControllable()) && this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish // Purpur - only use brain if no rider - this.getBrain().tick(level, this); - GoatAi.updateActivity(this); - super.customServerAiStep(level); + // DivineMC start - Dynamic Activation of Brain + if (this.behaviorTick++ % this.activatedPriority == 0) { + this.getBrain().tick(level, this); + GoatAi.updateActivity(this); + super.customServerAiStep(level); + } + // DivineMC end - Dynamic Activation of Brain } @Override diff --git a/net/minecraft/world/entity/monster/hoglin/Hoglin.java b/net/minecraft/world/entity/monster/hoglin/Hoglin.java index a5ee49e35b0825c03af058347ee189a7962e8027..4a02ff2dbea64cf6fb867872c08ad1b80fc5145b 100644 --- a/net/minecraft/world/entity/monster/hoglin/Hoglin.java +++ b/net/minecraft/world/entity/monster/hoglin/Hoglin.java @@ -84,6 +84,7 @@ public class Hoglin extends Animal implements Enemy, HoglinBase { MemoryModuleType.PACIFIED, MemoryModuleType.IS_PANICKING ); + private int behaviorTick; // DivineMC - Dynamic Activation of Brain public Hoglin(EntityType entityType, Level level) { super(entityType, level); @@ -203,17 +204,21 @@ public class Hoglin extends Animal implements Enemy, HoglinBase { @Override protected void customServerAiStep(ServerLevel level) { //if ((getRider() == null || !this.isControllable()) && this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish // Purpur - only use brain if no rider - this.getBrain().tick(level, this); - HoglinAi.updateActivity(this); - if (this.isConverting()) { - this.timeInOverworld++; - if (this.timeInOverworld > 300) { - this.makeSound(SoundEvents.HOGLIN_CONVERTED_TO_ZOMBIFIED); - this.finishConversion(); + // DivineMC start - Dynamic Activation of Brain + if (this.behaviorTick++ % this.activatedPriority == 0) { + this.getBrain().tick(level, this); + HoglinAi.updateActivity(this); + if (this.isConverting()) { + this.timeInOverworld++; + if (this.timeInOverworld > 300) { + this.makeSound(SoundEvents.HOGLIN_CONVERTED_TO_ZOMBIFIED); + this.finishConversion(); + } + } else { + this.timeInOverworld = 0; } - } else { - this.timeInOverworld = 0; } + // DivineMC end - Dynamic Activation of Brain } @Override diff --git a/net/minecraft/world/entity/monster/piglin/Piglin.java b/net/minecraft/world/entity/monster/piglin/Piglin.java index b2e64c0d4c1943f8a50a03ba59318fc2e6b9e26a..a7f2c0aec77a8b196c9207b071ac904c30f34ee6 100644 --- a/net/minecraft/world/entity/monster/piglin/Piglin.java +++ b/net/minecraft/world/entity/monster/piglin/Piglin.java @@ -143,6 +143,7 @@ public class Piglin extends AbstractPiglin implements CrossbowAttackMob, Invento public Set allowedBarterItems = new HashSet<>(); public Set interestItems = new HashSet<>(); // CraftBukkit end + private int behaviorTick; // DivineMC - Dynamic Activation of Brain public Piglin(EntityType entityType, Level level) { super(entityType, level); @@ -382,9 +383,13 @@ public class Piglin extends AbstractPiglin implements CrossbowAttackMob, Invento @Override protected void customServerAiStep(ServerLevel level) { //if ((getRider() == null || !this.isControllable()) && this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish // Purpur - only use brain if no rider - this.getBrain().tick(level, this); - PiglinAi.updateActivity(this); - super.customServerAiStep(level); + // DivineMC start - Dynamic Activation of Brain + if (this.behaviorTick++ % this.activatedPriority == 0) { + this.getBrain().tick(level, this); + PiglinAi.updateActivity(this); + super.customServerAiStep(level); + } + // DivineMC end - Dynamic Activation of Brain } @Override diff --git a/net/minecraft/world/entity/monster/warden/Warden.java b/net/minecraft/world/entity/monster/warden/Warden.java index 59a12809e5c7f5ee85ca1f587f6b77383a1ff062..9777f5e99909790b49b05ea64fe12dedaaba6a0a 100644 --- a/net/minecraft/world/entity/monster/warden/Warden.java +++ b/net/minecraft/world/entity/monster/warden/Warden.java @@ -113,6 +113,7 @@ public class Warden extends Monster implements VibrationSystem { private final VibrationSystem.User vibrationUser; private VibrationSystem.Data vibrationData; AngerManagement angerManagement = new AngerManagement(this::canTargetEntity, Collections.emptyList()); + private int behaviorTick = 0; // DivineMC - Dynamic Activation of Brain public Warden(EntityType entityType, Level level) { super(entityType, level); @@ -306,18 +307,22 @@ public class Warden extends Monster implements VibrationSystem { @Override protected void customServerAiStep(ServerLevel level) { - this.getBrain().tick(level, this); - super.customServerAiStep(level); - if ((this.tickCount + this.getId()) % 120 == 0) { - applyDarknessAround(level, this.position(), this, 20); - } + // DivineMC start - Dynamic Activation of Brain + if (this.behaviorTick++ % this.activatedPriority == 0) { + this.getBrain().tick(level, this); + super.customServerAiStep(level); + if ((this.tickCount + this.getId()) % 120 == 0) { + applyDarknessAround(level, this.position(), this, 20); + } - if (this.tickCount % 20 == 0) { - this.angerManagement.tick(level, this::canTargetEntity); - this.syncClientAngerLevel(); - } + if (this.tickCount % 20 == 0) { + this.angerManagement.tick(level, this::canTargetEntity); + this.syncClientAngerLevel(); + } - WardenAi.updateActivity(this); + WardenAi.updateActivity(this); + } + // DivineMC end - Dynamic Activation of Brain } @Override diff --git a/net/minecraft/world/entity/npc/Villager.java b/net/minecraft/world/entity/npc/Villager.java index fec90e482c8935dfca609bbf90e67f86a1586221..2ac8a11e9afc6f776eba3dbe852d7b680ed21705 100644 --- a/net/minecraft/world/entity/npc/Villager.java +++ b/net/minecraft/world/entity/npc/Villager.java @@ -179,6 +179,8 @@ public class Villager extends AbstractVillager implements ReputationEventHandler ); private boolean isLobotomized = false; public boolean isLobotomized() { return this.isLobotomized; } // Purpur - Lobotomize stuck villagers private int notLobotomizedCount = 0; // Purpur - Lobotomize stuck villagers + public long nextGolemPanic = -1; // DivineMC - Dynamic Activation of Brain + private int behaviorTick = 0; // DivineMC - Dynamic Activation of Brain public Villager(EntityType entityType, Level level) { this(entityType, level, VillagerType.PLAINS); @@ -397,7 +399,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler } // Purpur end - Lobotomize stuck villagers // Pufferfish start - if (!inactive && (getRider() == null || !this.isControllable()) /*&& this.behaviorTick++ % this.activatedPriority == 0*/) { // Purpur - Ridables + if (!inactive && this.behaviorTick++ % this.activatedPriority == 0 && (getRider() == null || !this.isControllable()) /*&& this.behaviorTick++ % this.activatedPriority == 0*/) { // Purpur - Ridables // DivineMC - Dynamic Activation of Brain this.getBrain().tick(level, this); // Paper - EAR 2 } else if (this.isLobotomized && shouldRestock()) restock(); // Purpur - Lobotomize stuck villagers