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 265f20fd771df850a0bb0029e699d3146d883837..a9326f1acc6ffe7fbacc34bf13f56d87e212027a 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.isInWaterOrRain())) { + 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 d7ec2dd011a6728e7a1adb5a84f587904166df79..27ff3ae4400de969c95eb337cfd88f8137c77d3b 100644 --- a/net/minecraft/server/level/ServerLevel.java +++ b/net/minecraft/server/level/ServerLevel.java @@ -802,6 +802,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 0a23d54a6f03b1d776ab24922f88144762c90875..b98010d6d3d369c680ccc8f15da9574e4f6a139c 100644 --- a/net/minecraft/world/entity/Entity.java +++ b/net/minecraft/world/entity/Entity.java @@ -344,6 +344,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 d6a0ad078fd1f0350afaac3f1743896d73b015e1..50bc352f4d918678a479a39b218973f7cd0500c7 100644 --- a/net/minecraft/world/entity/EntityType.java +++ b/net/minecraft/world/entity/EntityType.java @@ -1075,6 +1075,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 d618752727e2f2f5c0c1afa97f455e349cb7e76c..ed89fe2ccfb5ce3e8384a108243288f6e542bc1d 100644 --- a/net/minecraft/world/entity/Mob.java +++ b/net/minecraft/world/entity/Mob.java @@ -206,10 +206,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(); } } @@ -754,13 +754,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 29c22b464705f1b50ec0e423c5df40d8f21e57b7..76d99e4a89fe7df736b836a165d829def489c07b 100644 --- a/net/minecraft/world/entity/animal/allay/Allay.java +++ b/net/minecraft/world/entity/animal/allay/Allay.java @@ -116,6 +116,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); @@ -283,9 +284,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 0b787911c929f1564d859dcba1ee04510b4a9b7f..b3c09fe1a86f6a47448d4e71261ff34664758c17 100644 --- a/net/minecraft/world/entity/animal/axolotl/Axolotl.java +++ b/net/minecraft/world/entity/animal/axolotl/Axolotl.java @@ -110,6 +110,7 @@ public class Axolotl extends Animal implements Bucketable { 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); @@ -372,12 +373,16 @@ public class Axolotl extends Animal implements Bucketable { @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 3ccc48afb7a9eb2290f16c6a3218515bee59c2bd..617d47d61dd97fd1c7b56db71e47f4e334a4f491 100644 --- a/net/minecraft/world/entity/animal/frog/Frog.java +++ b/net/minecraft/world/entity/animal/frog/Frog.java @@ -105,6 +105,7 @@ public class Frog extends Animal { 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); @@ -259,9 +260,13 @@ public class Frog 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); - 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 63645451495dffd87362fd37cf91a90717ae4470..615655b41eb51b18b9517110e463ef44837ff8dc 100644 --- a/net/minecraft/world/entity/animal/frog/Tadpole.java +++ b/net/minecraft/world/entity/animal/frog/Tadpole.java @@ -63,6 +63,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); @@ -134,9 +135,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 01e1712854aaebc59db844045141b25561df8fc3..45aac1f956a54368f33e1292ba2dbfdd3e426bd0 100644 --- a/net/minecraft/world/entity/animal/goat/Goat.java +++ b/net/minecraft/world/entity/animal/goat/Goat.java @@ -93,6 +93,7 @@ public class Goat extends Animal { private static final boolean DEFAULT_HAS_RIGHT_HORN = true; private boolean isLoweringHead; private int lowerHeadTick; + private int behaviorTick = 0; // DivineMC - Dynamic Activation of Brain public Goat(EntityType entityType, Level level) { super(entityType, level); @@ -233,9 +234,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 0644f425cddebe8e5a65e69acae57db867380981..56fb3c23a265403a20cfab551aa002792cd942ea 100644 --- a/net/minecraft/world/entity/monster/hoglin/Hoglin.java +++ b/net/minecraft/world/entity/monster/hoglin/Hoglin.java @@ -87,6 +87,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); @@ -206,17 +207,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 73049e486fbf8411819551b43e3ca641ed7a5578..acbbe69df488b085de44e7825e9713bdeb600308 100644 --- a/net/minecraft/world/entity/monster/piglin/Piglin.java +++ b/net/minecraft/world/entity/monster/piglin/Piglin.java @@ -128,6 +128,7 @@ public class Piglin extends AbstractPiglin implements CrossbowAttackMob, Invento private static final com.mojang.serialization.Codec> ITEM_SET_CODEC = net.minecraft.core.registries.BuiltInRegistries.ITEM .byNameCodec().listOf().xmap(java.util.HashSet::new, List::copyOf); // CraftBukkit end + private int behaviorTick; // DivineMC - Dynamic Activation of Brain public Piglin(EntityType entityType, Level level) { super(entityType, level); @@ -357,9 +358,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 97ee07ebbba5ad29f766dff5eb4e51fc0e12cfcb..0898a7ea98b60edb31828d91afb92db44f63f85e 100644 --- a/net/minecraft/world/entity/monster/warden/Warden.java +++ b/net/minecraft/world/entity/monster/warden/Warden.java @@ -110,6 +110,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); @@ -303,18 +304,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 a08818450ed6fd78bb429743ee044726fc7994e7..abf7308a41e7c28e1d9fd82d5f86022a80159bff 100644 --- a/net/minecraft/world/entity/npc/Villager.java +++ b/net/minecraft/world/entity/npc/Villager.java @@ -178,6 +178,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); @@ -400,7 +402,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