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 223086fa230346e7212051710758560f874cb3b0..c6069b70d188a45950be27f9f6c63c8218dea7fa 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 { // CraftBukkit end public void baseTick() { + // Pufferfish start - entity TTL + if (type != EntityType.PLAYER && type.ttl >= 0 && this.tickCount >= type.ttl) { + remove(RemovalReason.DISCARDED); + return; + } + // Pufferfish end - entity TTL if (firstTick && this instanceof net.minecraft.world.entity.NeutralMob neutralMob) neutralMob.tickInitialPersistentAnger(level); // Paper - Update last hurt when ticking this.feetBlockState = null; if (this.isPassenger() && this.getVehicle().isRemoved()) { 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 955871484354d1a894afa52146e3ec354defd3b0..37399feb26f51c0f198124444ed427056e3f9da4 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 { @@ -175,6 +176,7 @@ public class LeafConfig { public static int maximumActivationPrio; public static int activationDistanceMod; public static boolean throttleInactiveGoalSelectorTick; + public static Map projectileTimeouts; private static void performance() { String sentryEnvironment = System.getenv("SENTRY_DSN"); String sentryConfig = getString("performance.sentry-dsn", sentryDsn, "Sentry DSN for improved error logging, leave blank to disable", "Obtain from https://sentry.io/"); @@ -218,6 +220,18 @@ public class LeafConfig { throttleInactiveGoalSelectorTick = getBoolean("inactive-goal-selector-throttle", "inactive-goal-selector-disable", true, "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("entity_timeouts.SNOWBALL", -1); + getInt("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() {