9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-19 15:09:25 +00:00
Files
Leaf/patches/unapplied/server/0007-Pufferfish-Entity-TTL.patch

77 lines
3.8 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 1b47b15cc4e9b277cc68beec8795b45f34d9f18d..c59ce8a083eb0ca616f9d17932457b899dc946a5 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -772,6 +772,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 ebf05a484175548c0e411adfd35fd1f648925fed..2561e74ffdf595a9b6ae13dcd738662c772db442 100644
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
@@ -302,6 +302,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 9cfa1d626c83a5c2fb1ae7db4746a4cb07262778..c135a861217d0ae43cf1b84e5bf259b41a0bf92e 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 {
@@ -172,6 +173,7 @@ public class LeafConfig {
public static int maximumActivationPrio = 20;
public static int activationDistanceMod = 8;
public static boolean throttleInactiveGoalSelectorTick = true;
+ public static Map<String, Integer> projectileTimeouts;
private static void performance() {
dabEnabled = getBoolean("performance.dab.enabled", "dab.enabled", dabEnabled);
startDistance = getInt("performance.dab.start-distance", "dab.start-distance", startDistance,
@@ -197,6 +199,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() {