80 lines
3.8 KiB
Diff
80 lines
3.8 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: MrHua269 <novau233@163.com>
|
|
Date: Wed, 7 Feb 2024 05:19:37 +0000
|
|
Subject: [PATCH] Pufferfish Entity TTL
|
|
|
|
|
|
diff --git a/src/main/java/me/earthme/luminol/config/modules/optimizations/EntityTTLOptimizationConfig.java b/src/main/java/me/earthme/luminol/config/modules/optimizations/EntityTTLOptimizationConfig.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..15697d69659b6e1e776acf5094684b5f0c079b57
|
|
--- /dev/null
|
|
+++ b/src/main/java/me/earthme/luminol/config/modules/optimizations/EntityTTLOptimizationConfig.java
|
|
@@ -0,0 +1,38 @@
|
|
+package me.earthme.luminol.config.modules.optimizations;
|
|
+
|
|
+import com.electronwill.nightconfig.core.file.CommentedFileConfig;
|
|
+import me.earthme.luminol.config.EnumConfigCategory;
|
|
+import me.earthme.luminol.config.IConfigModule;
|
|
+import net.minecraft.core.registries.BuiltInRegistries;
|
|
+import net.minecraft.world.entity.EntityType;
|
|
+
|
|
+import java.util.Locale;
|
|
+
|
|
+public class EntityTTLOptimizationConfig implements IConfigModule {
|
|
+ @Override
|
|
+ public EnumConfigCategory getCategory() {
|
|
+ return EnumConfigCategory.OPTIMIZATIONS;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public String getBaseName() {
|
|
+ return "entity_time_outs";
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void onLoaded(CommentedFileConfig config) {
|
|
+ // Set some defaults
|
|
+ this.get("optimizations.entity_timeouts.SNOWBALL", -1,config);
|
|
+ this.get("optimizations.entity_timeouts.LLAMA_SPIT", -1,config);
|
|
+ config.setComment("optimizations.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 = this.get("optimizations.entity_timeouts." + type, -1,config);
|
|
+ }
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index e6b90e53b2b539543084ddbfda4ab819656a3179..03a6633edd34a34f7c5cfb1a58f4d132e6bd1c12 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -798,6 +798,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();
|
|
+ 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 f921c159c4f7556daf3c8405241de3607ba251ad..8deae3e95a26f4b42b2c2134e22f9649bd7a5391 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/EntityType.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/EntityType.java
|
|
@@ -313,6 +313,7 @@ public class EntityType<T extends Entity> implements FeatureElement, EntityTypeT
|
|
private ResourceLocation lootTable;
|
|
private final EntityDimensions dimensions;
|
|
private final FeatureFlagSet requiredFeatures;
|
|
+ public int ttl = -1; // Pufferfish
|
|
|
|
private static <T extends Entity> EntityType<T> register(String id, EntityType.Builder type) { // CraftBukkit - decompile error
|
|
return (EntityType) Registry.register(BuiltInRegistries.ENTITY_TYPE, id, (EntityType<T>) type.build(id)); // CraftBukkit - decompile error
|