9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-24 01:19:25 +00:00
Files
Leaf/patches/server/0008-Pufferfish-Entity-TTL.patch
2023-07-25 07:35:13 +08:00

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 b818da9c6f0617b93ab5f5979c9fd4f3797bc7d8..df341e7c29ea5cc7807969c41c8f63e062daa90b 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -841,6 +841,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<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 beb548a047b7dedabbd5a720102b7e0400cea6d8..50d1e6e6240335cab5a7d3e5ce574b9e1e1ca0fb 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<String, Integer> 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("performance.inactive-goal-selector-throttle", "inactive-goal-selector-throttle", 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("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() {