From 49cf4cca9cb8f5e02be47a494c0c0de4ca47dea4 Mon Sep 17 00:00:00 2001 From: wangxyper Date: Fri, 29 Sep 2023 08:15:37 +0800 Subject: [PATCH] Add some optimizations from pufferfish --- .../0042-Kaiiju-Unsafe-teleportation.patch | 4 +- ...fferfish-Dynamic-Activation-of-Brain.patch | 384 ++++++++++++++++++ .../server/0044-Pufferfish-Entity-TTL.patch | 81 ++++ 3 files changed, 467 insertions(+), 2 deletions(-) create mode 100644 patches/server/0043-Pufferfish-Dynamic-Activation-of-Brain.patch create mode 100644 patches/server/0044-Pufferfish-Entity-TTL.patch diff --git a/patches/server/0042-Kaiiju-Unsafe-teleportation.patch b/patches/server/0042-Kaiiju-Unsafe-teleportation.patch index 722054b..ff1d59d 100644 --- a/patches/server/0042-Kaiiju-Unsafe-teleportation.patch +++ b/patches/server/0042-Kaiiju-Unsafe-teleportation.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Kaiiju Unsafe teleportation diff --git a/src/main/java/me/earthme/molia/MoliaConfig.java b/src/main/java/me/earthme/molia/MoliaConfig.java -index 405bc9c2ea13e8b70c70f52c1fc81336b4dd432e..b989377fb0f0f57ea9e114ed44818150c71822f2 100644 +index 405bc9c2ea13e8b70c70f52c1fc81336b4dd432e..e95a14cec8a6c276adbf787c4af850db5dd45634 100644 --- a/src/main/java/me/earthme/molia/MoliaConfig.java +++ b/src/main/java/me/earthme/molia/MoliaConfig.java @@ -23,6 +23,7 @@ public class MoliaConfig { @@ -20,7 +20,7 @@ index 405bc9c2ea13e8b70c70f52c1fc81336b4dd432e..b989377fb0f0f57ea9e114ed44818150 fixCanNotMoveEntityOffMain = getBoolean("fixes.fix_can_not_move_entity_off_main",fixCanNotMoveEntityOffMain); fixDoublingChunkSend = getBoolean("fixes.fix_doubling_chunk_send",fixDoublingChunkSend); allowGravityBlockDupe = getBoolean("fixes.allow_gravity_block_dupe",allowGravityBlockDupe); -+ safeTeleportation = getBoolean("fixes.safe_teleportation", safeTeleportation) || !allowGravityBlockDupe; ++ safeTeleportation = getBoolean("fixes.safe_teleportation", safeTeleportation) && !allowGravityBlockDupe; updateTripWireIfRemoving = getBoolean("fixes.update_tripwire_if_removing",updateTripWireIfRemoving); breakRedstoneOnTripDoorEarly = getBoolean("fixes.break_redstone_early_on_tripdoor",breakRedstoneOnTripDoorEarly); allowVoidTrading = getBoolean("fixes.allow_void_trading",allowVoidTrading); diff --git a/patches/server/0043-Pufferfish-Dynamic-Activation-of-Brain.patch b/patches/server/0043-Pufferfish-Dynamic-Activation-of-Brain.patch new file mode 100644 index 0000000..54339c7 --- /dev/null +++ b/patches/server/0043-Pufferfish-Dynamic-Activation-of-Brain.patch @@ -0,0 +1,384 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: wangxyper +Date: Fri, 29 Sep 2023 08:00:49 +0800 +Subject: [PATCH] Pufferfish Dynamic Activation of Brain + + +diff --git a/src/main/java/me/earthme/molia/MoliaConfig.java b/src/main/java/me/earthme/molia/MoliaConfig.java +index e95a14cec8a6c276adbf787c4af850db5dd45634..4f73701bb810f456146714c8ff67ff9ec423f79b 100644 +--- a/src/main/java/me/earthme/molia/MoliaConfig.java ++++ b/src/main/java/me/earthme/molia/MoliaConfig.java +@@ -1,7 +1,9 @@ + package me.earthme.molia; + + import com.google.common.collect.Lists; ++import net.minecraft.core.registries.BuiltInRegistries; + import net.minecraft.server.MinecraftServer; ++import net.minecraft.world.entity.EntityType; + import org.apache.logging.log4j.LogManager; + import org.apache.logging.log4j.Logger; + import org.bukkit.configuration.InvalidConfigurationException; +@@ -10,6 +12,7 @@ import top.leavesmc.leaves.bot.BotCommand; + import top.leavesmc.leaves.bot.agent.Actions; + import java.io.File; + import java.io.IOException; ++import java.util.Collections; + import java.util.List; + import me.earthme.molia.commands.TpsBarCommand; + import me.earthme.molia.functions.GlobalServerTpsBar; +@@ -30,6 +33,10 @@ public class MoliaConfig { + public static boolean enableSuffocationOptimization = true; + public static int maxProjectileLoadsPerTick = 10; + public static int maxProjectileLoadsPerProjectile = 10; ++ public static boolean dearEnabled = false; ++ public static int startDistanceSquared = 144; ++ public static int maximumActivationPrio = 20; ++ public static int activationDistanceMod = 8; + + //Gameplay + public static boolean tpsBarEnabled = false; +@@ -56,6 +63,17 @@ public class MoliaConfig { + MinecraftServer.getServer().server.getCommandMap().register("bot","leaves",new BotCommand("bot")); + } + ++ public static void initDAB(){ ++ for (EntityType entityType : BuiltInRegistries.ENTITY_TYPE) { ++ entityType.dabEnabled = true; // reset all, before setting the ones to true ++ } ++ ++ getStringList("optimizations.dab.blacklisted-entities", Collections.emptyList()) ++ .forEach(name -> EntityType.byString(name).ifPresentOrElse(entityType -> { ++ entityType.dabEnabled = false; ++ }, () -> MinecraftServer.LOGGER.warn("Unknown entity \"" + name + "\""))); ++ } ++ + public static void initTpsBar(){ + if (!tpsBarEnabled){ + return; +@@ -78,6 +96,11 @@ public class MoliaConfig { + enableSuffocationOptimization = getBoolean("optimizations.enable_suffocation_optimization",enableSuffocationOptimization); + maxProjectileLoadsPerTick = getInt("optimizations.max_projectile_loads_per_tick",maxProjectileLoadsPerTick); + maxProjectileLoadsPerProjectile = getInt("optimizations.max_projectile_loads_per_projectile",maxProjectileLoadsPerProjectile); ++ dearEnabled = getBoolean("optimizations.dab.enabled",dearEnabled); ++ startDistanceSquared = getInt("optimizations.dab.start_distance",(int)Math.sqrt(startDistanceSquared)) ^ 2; ++ maximumActivationPrio = getInt("optimizations.dab.max_tick_freq",maximumActivationPrio); ++ activationDistanceMod = getInt("optimizations.dab.activation_dist_mod",activationDistanceMod); ++ initDAB(); + + fakeplayerSupport = getBoolean("gameplay.leaves.fakeplayer.enabled",fakeplayerSupport); + fakeplayerLimit = getInt("gameplay.leaves.fakeplayer.fake_player_limit",fakeplayerLimit); +diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java +index 56509902b52a58c6c3b7c304dc2d01a8ff3ce211..338baba6a02c3debee4e2c7f2b34838ce6c0c76c 100644 +--- a/src/main/java/net/minecraft/server/level/ServerLevel.java ++++ b/src/main/java/net/minecraft/server/level/ServerLevel.java +@@ -854,6 +854,7 @@ public class ServerLevel extends Level implements WorldGenLevel { + org.spigotmc.ActivationRange.activateEntities(this); // Spigot + timings.entityTick.startTiming(); // Spigot + regionizedWorldData.forEachTickingEntity((entity) -> { // Folia - regionised ticking ++ entity.activatedPriorityReset = false; //Pufferfish - DAB + if (!entity.isRemoved()) { + if (false && this.shouldDiscardEntity(entity)) { // CraftBukkit - We prevent spawning in general, so this butchering is not needed + entity.discard(); +diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java +index 1fbf7a09556b1dd60c63c21c7005415a6d2310c0..f34a79f573bd473f6a23a953d9022ff0693ab80e 100644 +--- a/src/main/java/net/minecraft/world/entity/Entity.java ++++ b/src/main/java/net/minecraft/world/entity/Entity.java +@@ -442,6 +442,11 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { + // Pufferfish end + + // Paper end ++ // Pufferfish start ++ public boolean activatedPriorityReset = false; // DAB ++ public int activatedPriority = MoliaConfig.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 9afc81ccb237c3655d64cdbe8a0db9a4d7791043..1679f0a3d095a7b758b468c77b6d3a4c078b7962 100644 +--- a/src/main/java/net/minecraft/world/entity/EntityType.java ++++ b/src/main/java/net/minecraft/world/entity/EntityType.java +@@ -300,6 +300,7 @@ public class EntityType implements FeatureElement, EntityTypeT + private final boolean canSpawnFarFromPlayer; + private final int clientTrackingRange; + private final int updateInterval; ++ public boolean dabEnabled = false; // Pufferfish + @Nullable + private String descriptionId; + @Nullable +diff --git a/src/main/java/net/minecraft/world/entity/Mob.java b/src/main/java/net/minecraft/world/entity/Mob.java +index 8f44b4ce1d4c3e831c2fd2fed484aea017e48c55..07bfff21bc9a11454fad357edd4c13b0c1a28a80 100644 +--- a/src/main/java/net/minecraft/world/entity/Mob.java ++++ b/src/main/java/net/minecraft/world/entity/Mob.java +@@ -230,10 +230,10 @@ public abstract class Mob extends LivingEntity implements Targeting { + @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(); + } + } +@@ -925,16 +925,20 @@ public abstract class Mob extends LivingEntity implements Targeting { + + 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/goal/GoalSelector.java b/src/main/java/net/minecraft/world/entity/ai/goal/GoalSelector.java +index b738ee2d3801fadfd09313f05ae24593e56b0ec6..a00a883aa9846c1bea08246096bada86c2bd2d20 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 +@@ -11,6 +11,8 @@ import java.util.Set; + import java.util.function.Predicate; + import java.util.function.Supplier; + import java.util.stream.Stream; ++ ++import me.earthme.molia.MoliaConfig; + import net.minecraft.util.profiling.ProfilerFiller; + import org.slf4j.Logger; + +@@ -53,9 +55,12 @@ public class GoalSelector { + } + + // Paper start +- public boolean inactiveTick() { ++ public boolean inactiveTick(int tickRate, boolean inactive) { // Pufferfish start ++ if (inactive && !MoliaConfig.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/allay/Allay.java b/src/main/java/net/minecraft/world/entity/animal/allay/Allay.java +index 339c70f101d026a100a801e66cf514b3329a89d2..1a0eee3b766a5ce5623c32ed9c023a0f80db1d1a 100644 +--- a/src/main/java/net/minecraft/world/entity/animal/allay/Allay.java ++++ b/src/main/java/net/minecraft/world/entity/animal/allay/Allay.java +@@ -222,9 +222,11 @@ public class Allay extends PathfinderMob implements InventoryCarrier, VibrationS + return 0.4F; + } + ++ private int behaviorTick = 0; // Pufferfish + @Override + protected void customServerAiStep() { + this.level().getProfiler().push("allayBrain"); ++ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish + this.getBrain().tick((ServerLevel) this.level(), this); + this.level().getProfiler().pop(); + this.level().getProfiler().push("allayActivityUpdate"); +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 2682a49cd3948e0f80e2d7e58abcd3e6d8f7ac4e..42e22a4b9cb6841de04862cc81454da3232aa65a 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 +@@ -285,9 +285,11 @@ public class Axolotl extends Animal implements LerpingModel, VariantHolder { + return true; + } + ++ private int behaviorTick = 0; // Pufferfish + @Override + protected void customServerAiStep() { + this.level().getProfiler().push("frogBrain"); ++ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish + this.getBrain().tick((ServerLevel)this.level(), this); + this.level().getProfiler().pop(); + this.level().getProfiler().push("frogActivityUpdate"); +diff --git a/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java b/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java +index 4aeab90e778629c355189dfe79c39c4b21f5f5ac..6ed4ac06c76b8d0d6e8db778cade15dbd1e3e5f5 100644 +--- a/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java ++++ b/src/main/java/net/minecraft/world/entity/animal/frog/Tadpole.java +@@ -77,9 +77,11 @@ public class Tadpole extends AbstractFish { + return SoundEvents.TADPOLE_FLOP; + } + ++ private int behaviorTick = 0; // Pufferfish + @Override + protected void customServerAiStep() { + this.level().getProfiler().push("tadpoleBrain"); ++ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish + this.getBrain().tick((ServerLevel) this.level(), this); + this.level().getProfiler().pop(); + this.level().getProfiler().push("tadpoleActivityUpdate"); +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 247aca0b612f5079a0596350e8311c385df8ab1c..7f21d1d400c8a5615ed1a787dcb0680338f8c28d 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 +@@ -189,9 +189,11 @@ public class Goat extends Animal { + return (Brain) super.getBrain(); // CraftBukkit - decompile error + } + ++ private int behaviorTick = 0; // Pufferfish + @Override + protected void customServerAiStep() { + this.level().getProfiler().push("goatBrain"); ++ if (this.behaviorTick++ % this.activatedPriority == 0) // 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 e8f6c34ea789136d63c0aa88aec90203ef6282b5..d6d61b91096d28eea1e5af69ea1c07890820ee7f 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 +@@ -126,9 +126,11 @@ public class Hoglin extends Animal implements Enemy, HoglinBase { + return (Brain) super.getBrain(); // Paper - decompile fix + } + ++ private int behaviorTick; // Pufferfish + @Override + protected void customServerAiStep() { + this.level().getProfiler().push("hoglinBrain"); ++ if (this.behaviorTick++ % this.activatedPriority == 0) // 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 27d9145693a772cd1b5d171da303c934101f3be8..e235cc9d1b3ce59ab662ef3cf3ce0267ca78536d 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 +@@ -305,9 +305,11 @@ 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 (this.behaviorTick++ % this.activatedPriority == 0) // 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/monster/warden/Warden.java b/src/main/java/net/minecraft/world/entity/monster/warden/Warden.java +index 97b763431bc5015448ee7a26a340635a932c950b..71db8bd6885377d55cfc571fccc21df6d8a57b54 100644 +--- a/src/main/java/net/minecraft/world/entity/monster/warden/Warden.java ++++ b/src/main/java/net/minecraft/world/entity/monster/warden/Warden.java +@@ -271,11 +271,13 @@ public class Warden extends Monster implements VibrationSystem { + + } + ++ private int behaviorTick = 0; // Pufferfish + @Override + protected void customServerAiStep() { + ServerLevel worldserver = (ServerLevel) this.level(); + + worldserver.getProfiler().push("wardenBrain"); ++ if (this.behaviorTick++ % this.activatedPriority == 0) // Pufferfish + this.getBrain().tick(worldserver, this); + this.level().getProfiler().pop(); + super.customServerAiStep(); +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 bcc1af431fb2da84ba00e87ae9491eb5f580e6de..ca6a7dcdd984660522320417e68db5fabf5dbbd8 100644 +--- a/src/main/java/net/minecraft/world/entity/npc/Villager.java ++++ b/src/main/java/net/minecraft/world/entity/npc/Villager.java +@@ -141,6 +141,8 @@ public class Villager extends AbstractVillager implements ReputationEventHandler + return holder.is(PoiTypes.MEETING); + }); + ++ public long nextGolemPanic = -1; // Pufferfish ++ + public Villager(EntityType entityType, Level world) { + this(entityType, world, VillagerType.PLAINS); + } +@@ -244,6 +246,7 @@ public class Villager extends AbstractVillager implements ReputationEventHandler + } + // Spigot End + ++ private int behaviorTick = 0; // Pufferfish + @Override + @Deprecated // Paper + protected void customServerAiStep() { +@@ -253,7 +256,11 @@ public class Villager extends AbstractVillager implements ReputationEventHandler + protected void customServerAiStep(final boolean inactive) { + // Paper end + this.level().getProfiler().push("villagerBrain"); +- if (!inactive) this.getBrain().tick((ServerLevel) this.level(), this); // Paper ++ // Pufferfish start ++ if (!inactive && this.behaviorTick++ % this.activatedPriority == 0) { ++ 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 e83192f3dc510d916845a146cd4751e3244bab94..ca1b87a96eff284aefed489c829be01aa2864a09 100644 +--- a/src/main/java/org/spigotmc/ActivationRange.java ++++ b/src/main/java/org/spigotmc/ActivationRange.java +@@ -39,6 +39,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 + { +@@ -232,7 +236,28 @@ public class ActivationRange + ((net.minecraft.server.level.ServerLevel)world).getEntityLookup().getEntities((Entity)null, maxBB, entities, entityPredicate); // Paper - optimise this call // Folia - region ticking - bypass getEntities thread check, we perform a check on the entities later + for (int i = 0; i < entities.size(); i++) { + Entity entity = entities.get(i); +- if (io.papermc.paper.util.TickThread.isTickThreadFor(entity)) ActivationRange.activateEntity(entity); // Folia - region ticking ++ if (io.papermc.paper.util.TickThread.isTickThreadFor(entity)) { ++ ActivationRange.activateEntity(entity); // Folia - region ticking ++ ++ // Pufferfish start ++ if (MoliaConfig.dearEnabled && entity.getType().dabEnabled) { ++ if (!entity.activatedPriorityReset) { ++ entity.activatedPriorityReset = true; ++ entity.activatedPriority = MoliaConfig.maximumActivationPrio; ++ } ++ 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 > MoliaConfig.startDistanceSquared ? ++ Math.max(1, Math.min(squaredDistance >> MoliaConfig.activationDistanceMod, entity.activatedPriority)) : ++ 1; ++ } else { ++ entity.activatedPriority = 1; ++ } ++ // Pufferfish end ++ ++ } + } + // Paper end + } diff --git a/patches/server/0044-Pufferfish-Entity-TTL.patch b/patches/server/0044-Pufferfish-Entity-TTL.patch new file mode 100644 index 0000000..6a3b501 --- /dev/null +++ b/patches/server/0044-Pufferfish-Entity-TTL.patch @@ -0,0 +1,81 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: wangxyper +Date: Fri, 29 Sep 2023 08:14:01 +0800 +Subject: [PATCH] Pufferfish Entity TTL + + +diff --git a/src/main/java/me/earthme/molia/MoliaConfig.java b/src/main/java/me/earthme/molia/MoliaConfig.java +index 4f73701bb810f456146714c8ff67ff9ec423f79b..cde3d3b0cf541cace5c3afeb1467c5cb6ab61824 100644 +--- a/src/main/java/me/earthme/molia/MoliaConfig.java ++++ b/src/main/java/me/earthme/molia/MoliaConfig.java +@@ -14,6 +14,9 @@ import java.io.File; + import java.io.IOException; + import java.util.Collections; + import java.util.List; ++import java.util.Locale; ++import java.util.Map; ++ + import me.earthme.molia.commands.TpsBarCommand; + import me.earthme.molia.functions.GlobalServerTpsBar; + +@@ -37,6 +40,7 @@ public class MoliaConfig { + public static int startDistanceSquared = 144; + public static int maximumActivationPrio = 20; + public static int activationDistanceMod = 8; ++ public static Map entityTTLs; + + //Gameplay + public static boolean tpsBarEnabled = false; +@@ -74,6 +78,15 @@ public class MoliaConfig { + }, () -> MinecraftServer.LOGGER.warn("Unknown entity \"" + name + "\""))); + } + ++ public static void initEntityTTL(){ ++ getInt("optimizations.entity_timeouts.SNOWBALL", -1); ++ getInt("optimizations.entity_timeouts.LLAMA_SPIT", -1); ++ for (EntityType entityType : BuiltInRegistries.ENTITY_TYPE) { ++ String type = EntityType.getKey(entityType).getPath().toUpperCase(Locale.ROOT); ++ entityType.ttl = getInt("optimizations.entity_timeouts." + type, -1); ++ } ++ } ++ + public static void initTpsBar(){ + if (!tpsBarEnabled){ + return; +@@ -101,6 +114,7 @@ public class MoliaConfig { + maximumActivationPrio = getInt("optimizations.dab.max_tick_freq",maximumActivationPrio); + activationDistanceMod = getInt("optimizations.dab.activation_dist_mod",activationDistanceMod); + initDAB(); ++ initEntityTTL(); + + fakeplayerSupport = getBoolean("gameplay.leaves.fakeplayer.enabled",fakeplayerSupport); + fakeplayerLimit = getInt("gameplay.leaves.fakeplayer.fake_player_limit",fakeplayerLimit); +diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java +index f34a79f573bd473f6a23a953d9022ff0693ab80e..d4f65c32f747a15dbad3a430c87b1377f3e08efa 100644 +--- a/src/main/java/net/minecraft/world/entity/Entity.java ++++ b/src/main/java/net/minecraft/world/entity/Entity.java +@@ -811,6 +811,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { + } + + public void tick() { ++ // Pufferfish start - entity TTL ++ if (type != EntityType.PLAYER && type.ttl >= 0 && this.tickCount >= type.ttl) { ++ discard(); ++ return; ++ } ++ // Pufferfish end - entity TTL + this.baseTick(); + } + +diff --git a/src/main/java/net/minecraft/world/entity/EntityType.java b/src/main/java/net/minecraft/world/entity/EntityType.java +index 1679f0a3d095a7b758b468c77b6d3a4c078b7962..aa5cec6d56d7a8e80861aa4c9b4a74ca3e64be8c 100644 +--- a/src/main/java/net/minecraft/world/entity/EntityType.java ++++ b/src/main/java/net/minecraft/world/entity/EntityType.java +@@ -301,6 +301,7 @@ public class EntityType implements FeatureElement, EntityTypeT + private final int clientTrackingRange; + private final int updateInterval; + public boolean dabEnabled = false; // Pufferfish ++ public int ttl = -1; // Pufferfish + @Nullable + private String descriptionId; + @Nullable