mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-19 15:09:25 +00:00
105 lines
4.5 KiB
Diff
105 lines
4.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
|
|
|
|
Removed since Leaf 1.21.3, Paper 1.21.3 included it
|
|
|
|
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 22d3d963dc9806643608d077324b27832641ce57..60fbed7a31fbeca07eae8ea6b0fb97705961bb7e 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -849,6 +849,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..79875406800536e753de92d7e9e6613f0f563a55
|
|
--- /dev/null
|
|
+++ b/src/main/java/org/dreeam/leaf/config/modules/opt/EntityTTL.java
|
|
@@ -0,0 +1,59 @@
|
|
+package org.dreeam.leaf.config.modules.opt;
|
|
+
|
|
+import net.minecraft.core.registries.BuiltInRegistries;
|
|
+import net.minecraft.world.entity.EntityType;
|
|
+import org.dreeam.leaf.config.ConfigModules;
|
|
+import org.dreeam.leaf.config.EnumConfigCategory;
|
|
+
|
|
+import java.util.Locale;
|
|
+
|
|
+public class EntityTTL extends ConfigModules {
|
|
+
|
|
+ public String getBasePath() {
|
|
+ return EnumConfigCategory.PERF.getBaseKeyName() + ".entity-timeouts";
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void onLoaded() {
|
|
+ config.addCommentRegionBased(getBasePath(), """
|
|
+ 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.""",
|
|
+ """
|
|
+ 这些值定义了实体的最大生命周期.
|
|
+ 如果实体存活时间超过指定的 tick 将被移除, 设置为 -1 可禁用此功能.""");
|
|
+
|
|
+ for (EntityType<?> entityType : BuiltInRegistries.ENTITY_TYPE) {
|
|
+ if (isFilteredEntity(entityType)) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ String type = EntityType.getKey(entityType).getPath().toUpperCase(Locale.ROOT);
|
|
+ entityType.ttl = config.getInt(getBasePath() + "." + type, -1);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ // These entity types cannot be controlled by Entity TTL, and also should not
|
|
+ // So just filter them from the config
|
|
+ private boolean isFilteredEntity(EntityType<?> entityType) {
|
|
+ return entityType == EntityType.PLAYER
|
|
+ || entityType == EntityType.MINECART
|
|
+ // BlockAttachedEntity start
|
|
+ || entityType == EntityType.GLOW_ITEM_FRAME
|
|
+ || entityType == EntityType.ITEM_FRAME
|
|
+ || entityType == EntityType.PAINTING
|
|
+ || entityType == EntityType.LEASH_KNOT
|
|
+ // BlockAttachedEntity end
|
|
+ // Display start
|
|
+ || entityType == EntityType.BLOCK_DISPLAY
|
|
+ || entityType == EntityType.ITEM_DISPLAY
|
|
+ || entityType == EntityType.TEXT_DISPLAY
|
|
+ // Display end
|
|
+ || entityType == EntityType.END_CRYSTAL
|
|
+ || entityType == EntityType.FALLING_BLOCK
|
|
+ || entityType == EntityType.INTERACTION
|
|
+ || entityType == EntityType.MARKER
|
|
+ || entityType == EntityType.TNT;
|
|
+ }
|
|
+}
|