mirror of
https://github.com/Winds-Studio/Leaf.git
synced 2025-12-23 17:09:29 +00:00
83 lines
3.5 KiB
Diff
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 1482310673c2c2ac9180ea80a96c24d4094e11c9..f146fb4a599d36e0a9492936312e609cbbfed641 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -827,6 +827,12 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource, S
|
|
}
|
|
|
|
public void tick() {
|
|
+ // Pufferfish start - entity TTL
|
|
+ if (type != EntityType.PLAYER && type.ttl >= 0 && this.tickCount >= type.ttl) {
|
|
+ discard(org.bukkit.event.entity.EntityRemoveEvent.Cause.DISCARD); // Purpur
|
|
+ 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 d86c34111ede6a1454dde5e7223d7caf2ab39ef3..dc11683ee4d8a6b7a1c42bcae36dc6e8105cd994 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
|
|
@@ -306,6 +306,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);
|
|
+ }
|
|
+ }
|
|
+}
|