From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Kevin Raneri Date: Thu, 2 Jun 2022 19:54:09 -0500 Subject: [PATCH] Pufferfish: Entity TTL Original license: GPL v3 Original project: https://github.com/pufferfish-gg/Pufferfish diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java index edfb51e5c54d443926d0c051a3732a97dcecbd00..31d248b0a3ec735edff3aeb5e00fd009940013da 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -828,6 +828,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 diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java index 9a11228726c9a489181fc8a0c511ea83cdcf0f6e..9299d2fe1cda71b6881fd8bd65d3d74b1189a196 100644 --- a/src/main/java/org/dreeam/leaf/LeafConfig.java +++ b/src/main/java/org/dreeam/leaf/LeafConfig.java @@ -17,6 +17,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.Map; public class LeafConfig { @@ -174,6 +175,7 @@ public class LeafConfig { public static int maximumActivationPrio = 20; public static int activationDistanceMod = 8; public static boolean throttleInactiveGoalSelectorTick = true; + public static Map projectileTimeouts; private static void performance() { boolean asyncMobSpawning = getBoolean("performance.enable-async-mob-spawning", enableAsyncMobSpawning, "Whether or not asynchronous mob spawning should be enabled.", @@ -210,6 +212,18 @@ public class LeafConfig { throttleInactiveGoalSelectorTick = getBoolean("performance.inactive-goal-selector-throttle", "inactive-goal-selector-throttle", throttleInactiveGoalSelectorTick, "Throttles the AI goal selector in entity inactive ticks.", "This can improve performance by a few percent, but has minor gameplay implications."); + // Set some defaults + getInt("performance.entity_timeouts.SNOWBALL", -1); + getInt("performance.entity_timeouts.LLAMA_SPIT", -1); + setComment("entity_timeouts", + "These values define a entity's maximum lifespan. If an", + "entity is in this list and it has survived for longer than", + "that number of ticks, then it will be removed. Setting a value to", + "-1 disables this feature."); + for (EntityType entityType : BuiltInRegistries.ENTITY_TYPE) { + String type = EntityType.getKey(entityType).getPath().toUpperCase(Locale.ROOT); + entityType.ttl = config.getInt("entity_timeouts." + type, -1); + } } private static void network() {