9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-28 11:29:11 +00:00
Files
Leaf/patches/server/0037-Pufferfish-Entity-TTL.patch

77 lines
4.1 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Kevin Raneri <kevin.raneri@gmail.com>
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 d1b20fd95dd078a89b9f2f0b58710cebdd53fb55..da3f2b08a1c9a9c58ee0a5e557165014b3744dfb 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -820,6 +820,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 969a27ca909252d5ecedaedc16fdbcc482dfa794..7c6db12723c46b336046fabea53f2ede18207a9c 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<T extends Entity> 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 19124240535bec20326f9a480fd4f341c4e836da..1ac1ca1bc10a6f83f328f29370f27d5889ffb8ab 100644
--- a/src/main/java/org/dreeam/leaf/LeafConfig.java
+++ b/src/main/java/org/dreeam/leaf/LeafConfig.java
@@ -19,6 +19,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 {
@@ -203,6 +204,7 @@ public class LeafConfig {
public static int maximumActivationPrio;
public static int activationDistanceMod;
public static boolean throttleInactiveGoalSelectorTick;
+ public static Map<String, Integer> projectileTimeouts;
private static void performance() {
laggingThreshold = getDouble("performance.lagging-threshold", laggingThreshold);
tpsCatchup = getBoolean("performance.tps-catchup", tpsCatchup);
@@ -256,6 +258,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);
+ }
}
public static String commandTPSBarOutput = "<green>Tpsbar toggled <onoff> for <target>";