9
0
mirror of https://github.com/Winds-Studio/Leaf.git synced 2025-12-29 20:09:17 +00:00
Files
Leaf/patches/server/0009-Pufferfish-Entity-TTL.patch
2024-06-21 13:14:45 +08:00

83 lines
3.5 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 1fc95388c3391082f19455c5cff65e98c856b797..55f544a7a7253cd6619ef43d26f17b38ccb375ea 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 SyncedDataHolder, Nameable, EntityAccess
}
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 b2d8a858d8767bd6ca52e0b8db84757986c6ed61..f9440014ab2fe753c16b9383f5fffbb8adb76e79 100644
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
@@ -317,6 +317,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/config/modules/opt/EntityTTL.java b/src/main/java/org/dreeam/leaf/config/modules/opt/EntityTTL.java
new file mode 100644
index 0000000000000000000000000000000000000000..8530cca54105d74f94a2c7e2ed7eab9b6f2f06f0
--- /dev/null
+++ b/src/main/java/org/dreeam/leaf/config/modules/opt/EntityTTL.java
@@ -0,0 +1,39 @@
+package org.dreeam.leaf.config.modules.opt;
+
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
+import net.minecraft.core.registries.BuiltInRegistries;
+import net.minecraft.world.entity.EntityType;
+import org.dreeam.leaf.config.EnumConfigCategory;
+import org.dreeam.leaf.config.IConfigModule;
+
+import java.util.Locale;
+
+public class EntityTTL implements IConfigModule {
+
+ @Override
+ public EnumConfigCategory getCategory() {
+ return EnumConfigCategory.PERFORMANCE;
+ }
+
+ @Override
+ public String getBaseName() {
+ return "entity_timeouts";
+ }
+
+ @Override
+ public void onLoaded(CommentedFileConfig config) {
+ config.setComment("performance.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.""");
+
+ // Set some defaults
+ this.get("performance.entity_timeouts.SNOWBALL", -1, config);
+ this.get("performance.entity_timeouts.LLAMA_SPIT", -1, config);
+ for (EntityType<?> entityType : BuiltInRegistries.ENTITY_TYPE) {
+ String type = EntityType.getKey(entityType).getPath().toUpperCase(Locale.ROOT);
+ entityType.ttl = this.get("performance.entity_timeouts." + type, -1, config);
+ }
+ }
+}