From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: M2ke4U <79621885+MrHua269@users.noreply.github.com> Date: Sun, 26 Nov 2023 16:30:24 +0800 Subject: [PATCH] Pufferfish Entity TTL diff --git a/src/main/java/me/earthme/luminol/LuminolConfig.java b/src/main/java/me/earthme/luminol/LuminolConfig.java index de0855656ad3882b182aa5674fd0117288268e71..d0c0b4daec59f23a989a8b8f66ea3c704b0e309c 100644 --- a/src/main/java/me/earthme/luminol/LuminolConfig.java +++ b/src/main/java/me/earthme/luminol/LuminolConfig.java @@ -4,13 +4,16 @@ import dev.kaiijumc.kaiiju.region.RegionFileFormat; import com.electronwill.nightconfig.core.file.CommentedFileConfig; import me.earthme.luminol.commands.TpsBarCommand; import me.earthme.luminol.functions.GlobalServerTpsBar; +import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.entity.EntityType; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bukkit.Bukkit; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.logging.Level; import java.io.File; import java.io.IOException; @@ -65,6 +68,22 @@ public class LuminolConfig { } } + private static void initEntityTTL() { + // Set some defaults + get("optimizations.entity_timeouts.SNOWBALL", -1); + get("optimizations.entity_timeouts.LLAMA_SPIT", -1); + MAIN_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 = get("optimizations.entity_timeouts." + type, -1); + } + } + public static void initValues(){ serverModName = get("misc.server_mod_name",serverModName,"The servermod name will be sent to players,and you can see it in F3 or motd responses"); fakeVanillaModeEnabled = get("misc.enable_fake_vanilla_mode",fakeVanillaModeEnabled,"Enable this to make the ping response of your server like a vanilla server"); @@ -106,6 +125,7 @@ public class LuminolConfig { reduceSensorWork = get("optimizations.reduce_sensor_work",reduceSensorWork,"This optimization is from petal.You can find out more about it on petal's repository"); enableSuffocationOptimization = get("optimizations.optimize_suffocation_check",enableSuffocationOptimization); + initEntityTTL(); } public static T get(String key,T def){ diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java index abf7fc1e7a05a741e9258af014411d4ac5e6626c..453b0bee24d4c3e5d673463a55a192d28f18c0a8 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -806,6 +806,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 d37a7f2ab6a8041d3bfeed600d15f77d253140f6..cb850c18ca101d5b7c80746fca333d31cc770407 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 implements FeatureElement, EntityTypeT private ResourceLocation lootTable; private final EntityDimensions dimensions; private final FeatureFlagSet requiredFeatures; + public int ttl = -1; // Pufferfish private static EntityType register(String id, EntityType.Builder type) { // CraftBukkit - decompile error return (EntityType) Registry.register(BuiltInRegistries.ENTITY_TYPE, id, (EntityType) type.build(id)); // CraftBukkit - decompile error