From 3f0845cc5e783d53d5671bf15b096c569cc6fa56 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Sun, 31 Dec 2023 04:39:24 -0500 Subject: [PATCH 1/4] Readd bukkit TimedRegisteredListener to keep plugin compatibility --- patches/api/0004-Remove-Timings.patch | 136 ++------------------------ 1 file changed, 10 insertions(+), 126 deletions(-) diff --git a/patches/api/0004-Remove-Timings.patch b/patches/api/0004-Remove-Timings.patch index a877b724..c0287617 100644 --- a/patches/api/0004-Remove-Timings.patch +++ b/patches/api/0004-Remove-Timings.patch @@ -2972,7 +2972,7 @@ index e43d0e0a2c5edfcc82a677b6c4db9314006c9bf4..68fafa73d2e8d832acc7ce4759147774 server.getPluginManager().callEvent(new com.destroystokyo.paper.event.server.ServerExceptionEvent(new com.destroystokyo.paper.exception.ServerCommandException(ex, target, sender, args))); // Paper throw new CommandException(msg, ex); diff --git a/src/main/java/org/bukkit/plugin/SimplePluginManager.java b/src/main/java/org/bukkit/plugin/SimplePluginManager.java -index 899d67fa782fac639fe7fb096e05c551d75bd647..cb01547706de416dd41879bf479d93fa0e7e23c9 100644 +index 899d67fa782fac639fe7fb096e05c551d75bd647..4e93f49d1c54f3b061be456c0b8f11aa58f5a3af 100644 --- a/src/main/java/org/bukkit/plugin/SimplePluginManager.java +++ b/src/main/java/org/bukkit/plugin/SimplePluginManager.java @@ -60,7 +60,6 @@ public final class SimplePluginManager implements PluginManager { @@ -2991,8 +2991,9 @@ index 899d67fa782fac639fe7fb096e05c551d75bd647..cb01547706de416dd41879bf479d93fa - if (false) { // Spigot - RL handles useTimings check now // Paper - getEventListeners(event).register(new TimedRegisteredListener(listener, executor, priority, plugin, ignoreCancelled)); - } else { - getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled)); +- getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled)); - } ++ getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled)); } @NotNull @@ -3015,115 +3016,8 @@ index 899d67fa782fac639fe7fb096e05c551d75bd647..cb01547706de416dd41879bf479d93fa } // Paper start -diff --git a/src/main/java/org/bukkit/plugin/TimedRegisteredListener.java b/src/main/java/org/bukkit/plugin/TimedRegisteredListener.java -deleted file mode 100644 -index 1d76e30b82ca56bb4cf3b9a33f5a129ab829e3f0..0000000000000000000000000000000000000000 ---- a/src/main/java/org/bukkit/plugin/TimedRegisteredListener.java -+++ /dev/null -@@ -1,101 +0,0 @@ --package org.bukkit.plugin; -- --import org.bukkit.event.Event; --import org.bukkit.event.EventException; --import org.bukkit.event.EventPriority; --import org.bukkit.event.Listener; --import org.jetbrains.annotations.NotNull; --import org.jetbrains.annotations.Nullable; -- --/** -- * Extends RegisteredListener to include timing information -- */ --public class TimedRegisteredListener extends RegisteredListener { -- private int count; -- private long totalTime; -- private Class eventClass; -- private boolean multiple = false; -- -- public TimedRegisteredListener(@NotNull final Listener pluginListener, @NotNull final EventExecutor eventExecutor, @NotNull final EventPriority eventPriority, @NotNull final Plugin registeredPlugin, final boolean listenCancelled) { -- super(pluginListener, eventExecutor, eventPriority, registeredPlugin, listenCancelled); -- } -- -- @Override -- public void callEvent(@NotNull Event event) throws EventException { -- if (event.isAsynchronous()) { -- super.callEvent(event); -- return; -- } -- count++; -- Class newEventClass = event.getClass(); -- if (this.eventClass == null) { -- this.eventClass = newEventClass; -- } else if (!this.eventClass.equals(newEventClass)) { -- multiple = true; -- this.eventClass = getCommonSuperclass(newEventClass, this.eventClass).asSubclass(Event.class); -- } -- long start = System.nanoTime(); -- super.callEvent(event); -- totalTime += System.nanoTime() - start; -- } -- -- @NotNull -- private static Class getCommonSuperclass(@NotNull Class class1, @NotNull Class class2) { -- while (!class1.isAssignableFrom(class2)) { -- class1 = class1.getSuperclass(); -- } -- return class1; -- } -- -- /** -- * Resets the call count and total time for this listener -- */ -- public void reset() { -- count = 0; -- totalTime = 0; -- } -- -- /** -- * Gets the total times this listener has been called -- * -- * @return Times this listener has been called -- */ -- public int getCount() { -- return count; -- } -- -- /** -- * Gets the total time calls to this listener have taken -- * -- * @return Total time for all calls of this listener -- */ -- public long getTotalTime() { -- return totalTime; -- } -- -- /** -- * Gets the class of the events this listener handled. If it handled -- * multiple classes of event, the closest shared superclass will be -- * returned, such that for any event this listener has handled, -- * this.getEventClass().isAssignableFrom(event.getClass()) -- * and no class this.getEventClass().isAssignableFrom(clazz) -- * {@literal && this.getEventClass() != clazz &&} -- * event.getClass().isAssignableFrom(clazz) for all handled events. -- * -- * @return the event class handled by this RegisteredListener -- */ -- @Nullable -- public Class getEventClass() { -- return eventClass; -- } -- -- /** -- * Gets whether this listener has handled multiple events, such that for -- * some two events, eventA.getClass() != eventB.getClass(). -- * -- * @return true if this listener has handled multiple events -- */ -- public boolean hasMultiple() { -- return multiple; -- } --} diff --git a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java -index f7266e3991d991e7d7b38752ed472bc9cfa5f43c..d0b97df06a3fb5b05592f1d8204358e8f6e4d459 100644 +index f7266e3991d991e7d7b38752ed472bc9cfa5f43c..74e4abd3766d905280da0a53ce7e4d98e90e7690 100644 --- a/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java +++ b/src/main/java/org/bukkit/plugin/java/JavaPluginLoader.java @@ -39,11 +39,9 @@ import org.bukkit.plugin.PluginDescriptionFile; @@ -3138,27 +3032,16 @@ index f7266e3991d991e7d7b38752ed472bc9cfa5f43c..d0b97df06a3fb5b05592f1d8204358e8 import org.yaml.snakeyaml.error.YAMLException; /** -@@ -239,7 +237,6 @@ public final class JavaPluginLoader implements PluginLoader { - Preconditions.checkArgument(plugin != null, "Plugin can not be null"); - Preconditions.checkArgument(listener != null, "Listener can not be null"); - -- boolean useTimings = server.getPluginManager().useTimings(); - Map, Set> ret = new HashMap, Set>(); - Set methods; - try { -@@ -300,9 +297,9 @@ public final class JavaPluginLoader implements PluginLoader { +@@ -300,7 +298,7 @@ public final class JavaPluginLoader implements PluginLoader { } } - EventExecutor executor = new co.aikar.timings.TimedEventExecutor(new EventExecutor() { // Paper + EventExecutor executor = new EventExecutor() { @Override -- public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException { // Paper -+ public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException { + public void execute(@NotNull Listener listener, @NotNull Event event) throws EventException { // Paper try { - if (!eventClass.isAssignableFrom(event.getClass())) { - return; -@@ -314,12 +311,8 @@ public final class JavaPluginLoader implements PluginLoader { +@@ -314,12 +312,8 @@ public final class JavaPluginLoader implements PluginLoader { throw new EventException(t); } } @@ -3166,9 +3049,10 @@ index f7266e3991d991e7d7b38752ed472bc9cfa5f43c..d0b97df06a3fb5b05592f1d8204358e8 - if (false) { // Spigot - RL handles useTimings check now - eventSet.add(new TimedRegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled())); - } else { -+ }; - eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled())); +- eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled())); - } ++ }; ++ eventSet.add(new RegisteredListener(listener, executor, eh.priority(), plugin, eh.ignoreCancelled())); } return ret; } From 2053ad6fc3b257765a4abbcea6f54579bfa4bf3e Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Tue, 16 Jan 2024 15:54:07 -0500 Subject: [PATCH 2/4] Make checkNearbyItem for MinecraftHopper configurable & Optimize items for fluid update check --- patches/server/0041-Fix-sprint-glitch.patch | 6 +- ...em-checks-for-finding-MinecartHopper.patch | 110 ++++++++++++++++++ ...Optimize-item-updates-in-fluid-check.patch | 93 +++++++++++++++ 3 files changed, 206 insertions(+), 3 deletions(-) create mode 100644 patches/server/0043-Reduce-item-checks-for-finding-MinecartHopper.patch create mode 100644 patches/server/0044-Optimize-item-updates-in-fluid-check.patch diff --git a/patches/server/0041-Fix-sprint-glitch.patch b/patches/server/0041-Fix-sprint-glitch.patch index 6276f2d1..0d1a5bb9 100644 --- a/patches/server/0041-Fix-sprint-glitch.patch +++ b/patches/server/0041-Fix-sprint-glitch.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Fix sprint glitch diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java -index d811a2456b7c2b8c4766f4b7943eeb438e88e3fd..1a9eb22266c83a6fb49f53f34190d661fa0be53a 100644 +index d811a2456b7c2b8c4766f4b7943eeb438e88e3fd..b648f7054bc649c0f166f846d3b3f33b0b0a13ee 100644 --- a/src/main/java/net/minecraft/world/entity/LivingEntity.java +++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java @@ -1430,7 +1430,8 @@ public abstract class LivingEntity extends Entity implements Attackable { @@ -13,8 +13,8 @@ index d811a2456b7c2b8c4766f4b7943eeb438e88e3fd..1a9eb22266c83a6fb49f53f34190d661 } - player.updateScaledHealth(false); -+ this.entityData.set(LivingEntity.DATA_HEALTH_ID, player.getScaledHealth()); // Sprint glitch Fix by pafias -+ // player.updateScaledHealth(false); // Commented out to fix sprint glitch ++ this.entityData.set(LivingEntity.DATA_HEALTH_ID, player.getScaledHealth()); // Leaf - Sprint glitch Fix by pafias ++ //player.updateScaledHealth(false); // Leaf - Commented out to fix sprint glitch return; } // CraftBukkit end diff --git a/patches/server/0043-Reduce-item-checks-for-finding-MinecartHopper.patch b/patches/server/0043-Reduce-item-checks-for-finding-MinecartHopper.patch new file mode 100644 index 00000000..2dfee8c4 --- /dev/null +++ b/patches/server/0043-Reduce-item-checks-for-finding-MinecartHopper.patch @@ -0,0 +1,110 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> +Date: Mon, 15 Jan 2024 10:53:10 -0500 +Subject: [PATCH] Reduce item checks for finding MinecartHopper + +This patch add a toggle for checking MinecraftHopper nearby items, +and add a time throttler and MinecraftHopper pre-cehck for items checking + +But still recommend to turn-off `checkForMinecartNearItemWhileInactive` +Since `Reduce-hopper-item-checks.patch` will cause lag under massive dropped items + +diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java +index 0fe02df86483809cef22fca2e2ce0af7b4a5c6d5..d6ab766ae4affb26cb8a26da113d3e70bd4b402b 100644 +--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java ++++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java +@@ -1,9 +1,12 @@ + package net.minecraft.world.entity.item; + ++import java.util.HashMap; + import java.util.Iterator; + import java.util.List; ++import java.util.Map; + import java.util.Objects; + import java.util.UUID; ++import java.util.concurrent.TimeUnit; + import javax.annotation.Nullable; + import net.minecraft.tags.DamageTypeTags; + import net.minecraft.tags.FluidTags; +@@ -219,7 +222,9 @@ public class ItemEntity extends Entity implements TraceableEntity { + this.discard(); + return; // Gale - EMC - reduce hopper item checks + } +- this.markNearbyHopperCartsAsImmune(); // Gale - EMC - reduce hopper item checks ++ if (level().galeConfig().smallOptimizations.reducedIntervals.checkNearbyItem.hopper.minecart.temporaryImmunity.checkForMinecartNearItemWhileActive) { ++ this.markNearbyHopperCartsAsImmune(); // Gale - EMC - reduce hopper item checks ++ } + + } + } +@@ -231,17 +236,53 @@ public class ItemEntity extends Entity implements TraceableEntity { + if (config.interval <= 1) { + return; + } ++ ++ // Leaf start - Reduce item checks for finding MinecartHopper ++ BlockPos pos = new BlockPos(this.getBlockX(), this.getBlockY(), this.getBlockZ()); ++ if (this.shouldCheckItem(pos)) { ++ cachedResults.putIfAbsent(pos, true); ++ + if (config.temporaryImmunity.duration > 0 && this.isAlive() && this.onGround && !this.isRemoved() && (config.temporaryImmunity.nearbyItemMaxAge == -1 || this.age <= config.temporaryImmunity.nearbyItemMaxAge) && this.age % Math.max(1, config.temporaryImmunity.checkForMinecartNearItemInterval) == 0 && config.temporaryImmunity.maxItemHorizontalDistance >= 0 && config.temporaryImmunity.maxItemVerticalDistance >= 0) { + AABB aabb = this.getBoundingBox().inflate(config.temporaryImmunity.maxItemHorizontalDistance, config.temporaryImmunity.maxItemVerticalDistance, config.temporaryImmunity.maxItemHorizontalDistance); ++ if (this.level().getEntities(this, aabb).stream().noneMatch(entity -> entity instanceof MinecartHopper)) {// Leaf TODO - getEntities still take a lot of TPS ++ return; ++ } ++ + for (Entity entity : this.level().getEntities(this, aabb)) { + if (entity instanceof MinecartHopper) { + ((MinecartHopper) entity).pickupImmunity = MinecraftServer.currentTick + config.temporaryImmunity.duration; + } + } + } ++ }// Leaf end + } + // Gale end - EMC - reduce hopper item checks + ++ // Leaf start - Reduce item checks for finding MinecartHopper ++ private Map cachedResults = new HashMap<>(); ++ private long startTime = System.nanoTime(); ++ ++ private boolean shouldCheckItem(BlockPos pos) { ++ long now = System.nanoTime(); ++ long timeElapsed = (now - startTime) / 1000000L; ++ ++ // Throttle ++ if (timeElapsed < 20000L) { ++ return false; ++ } ++ ++ // Check in cache ++ if (cachedResults.containsKey(pos)) { ++ return cachedResults.get(pos); ++ } ++ ++ // Reset timer ++ startTime = now; ++ ++ return true; ++ } ++ // Leaf end ++ + // Spigot start - copied from above + @Override + public void inactiveTick() { +diff --git a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java +index 1b1bf657993c2a96d7168e3b1161872839a6e67a..32e4fda2807aa68ba07e2c40881a451848bebd77 100644 +--- a/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java ++++ b/src/main/java/org/galemc/gale/configuration/GaleWorldConfiguration.java +@@ -76,10 +76,11 @@ public class GaleWorldConfiguration extends ConfigurationPart { + + public TemporaryImmunity temporaryImmunity; + public class TemporaryImmunity extends ConfigurationPart { ++ public boolean checkForMinecartNearItemWhileActive = false; // Leaf - Make it configurable and reorder code ++ public boolean checkForMinecartNearItemWhileInactive = true; + public int duration = 100; + public int nearbyItemMaxAge = 1200; + public int checkForMinecartNearItemInterval = 20; +- public boolean checkForMinecartNearItemWhileInactive = true; + public double maxItemHorizontalDistance = 24.0; + public double maxItemVerticalDistance = 4.0; + } diff --git a/patches/server/0044-Optimize-item-updates-in-fluid-check.patch b/patches/server/0044-Optimize-item-updates-in-fluid-check.patch new file mode 100644 index 00000000..ad821c73 --- /dev/null +++ b/patches/server/0044-Optimize-item-updates-in-fluid-check.patch @@ -0,0 +1,93 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> +Date: Mon, 15 Jan 2024 23:02:33 -0500 +Subject: [PATCH] Optimize item updates in fluid check + + +diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java +index 3cf07a2d82ec9f0d6666fb27aee9acc9d9823ead..813a02601110245161ae157f4054512d6f117cd9 100644 +--- a/src/main/java/net/minecraft/world/entity/Entity.java ++++ b/src/main/java/net/minecraft/world/entity/Entity.java +@@ -864,9 +864,20 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { + + this.wasInPowderSnow = this.isInPowderSnow; + this.isInPowderSnow = false; +- this.updateInWaterStateAndDoFluidPushing(); +- this.updateFluidOnEyes(); +- this.updateSwimming(); ++ // Leaf start - Optimize item updates in fluid check ++ if (org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateEnabled) { ++ ItemEntity.checkInLiquid(this); ++ if (this instanceof ItemEntity && ItemEntity.isInLiquid) { ++ this.updateInWaterStateAndDoFluidPushing(); ++ this.updateFluidOnEyes(); ++ this.updateSwimming(); ++ } ++ } else { ++ this.updateInWaterStateAndDoFluidPushing(); ++ this.updateFluidOnEyes(); ++ this.updateSwimming(); ++ } ++ // Leaf end + if (this.level().isClientSide) { + this.clearFire(); + } else if (this.remainingFireTicks > 0) { +diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java +index d6ab766ae4affb26cb8a26da113d3e70bd4b402b..d521b44325c202f9671f0b7a34aafe112cf7edbc 100644 +--- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java ++++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java +@@ -131,6 +131,15 @@ public class ItemEntity extends Entity implements TraceableEntity { + this.getEntityData().define(ItemEntity.DATA_ITEM, ItemStack.EMPTY); + } + ++ // Leaf start - Optimize item updates in fluid check ++ public static boolean isInLiquid = false; ++ public static void checkInLiquid(Entity e) { ++ if (e.tickCount % org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateTickCount == 0) { ++ isInLiquid = e.isInLiquid(); ++ } ++ } ++ // Leaf end ++ + @Override + public void tick() { + if (this.getItem().isEmpty()) { +@@ -203,7 +212,14 @@ public class ItemEntity extends Entity implements TraceableEntity { + } + // CraftBukkit end */ + +- this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing(); ++ // Leaf - Optimize item updates in fluid check ++ if (org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateEnabled) { ++ checkInLiquid(this); ++ if (isInLiquid) this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing(); ++ } else { ++ this.hasImpulse |= this.updateInWaterStateAndDoFluidPushing(); ++ } ++ // Leaf end + if (!this.level().isClientSide) { + double d0 = this.getDeltaMovement().subtract(vec3d).lengthSqr(); + +diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java +index 53bde816ca9bf8b704fb2e9794de260a9eba402f..98723f55a5557f10b75a299c586bf2caf31887f3 100644 +--- a/src/main/java/org/dreeam/leaf/LeafConfig.java ++++ b/src/main/java/org/dreeam/leaf/LeafConfig.java +@@ -202,6 +202,8 @@ public class LeafConfig { + public static int asyncPathfindingMaxThreads = 0; + public static int asyncPathfindingKeepalive = 60; + public static boolean cacheMinecartCollision = false; ++ public static boolean optimizeItemsInFluidUpdateEnabled = false; ++ public static int optimizeItemsInFluidUpdateTickCount = 20; + private static void performance() { + boolean asyncMobSpawning = getBoolean("performance.enable-async-mob-spawning", enableAsyncMobSpawning, + "Whether or not asynchronous mob spawning should be enabled.", +@@ -265,6 +267,9 @@ public class LeafConfig { + cacheMinecartCollision = getBoolean("performance.cache-minecart-collision", cacheMinecartCollision, + "Cache the minecart collision result to prevent massive stacked minecart lag the server.", + "The known issue: entity can't enter the minecart after enabling this!"); ++ optimizeItemsInFluidUpdateEnabled = getBoolean("performance.optimize-items-in-fluid-update.enabled", optimizeItemsInFluidUpdateEnabled); ++ optimizeItemsInFluidUpdateTickCount = getInt("performance.optimize-items-in-fluid-update.tick-count", optimizeItemsInFluidUpdateTickCount); ++ + } + + public static boolean jadeProtocol = false; From 92078d29b4039a62948719c03d4119608e2dcf02 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Wed, 17 Jan 2024 06:10:27 -0500 Subject: [PATCH 3/4] Fixes --- ...e-items-finding-hopper-nearby-check.patch} | 25 ++++++++----------- ...Optimize-item-updates-in-fluid-check.patch | 12 ++++----- 2 files changed, 17 insertions(+), 20 deletions(-) rename patches/server/{0043-Reduce-item-checks-for-finding-MinecartHopper.patch => 0043-Reduce-items-finding-hopper-nearby-check.patch} (85%) diff --git a/patches/server/0043-Reduce-item-checks-for-finding-MinecartHopper.patch b/patches/server/0043-Reduce-items-finding-hopper-nearby-check.patch similarity index 85% rename from patches/server/0043-Reduce-item-checks-for-finding-MinecartHopper.patch rename to patches/server/0043-Reduce-items-finding-hopper-nearby-check.patch index 2dfee8c4..aaf9e8fd 100644 --- a/patches/server/0043-Reduce-item-checks-for-finding-MinecartHopper.patch +++ b/patches/server/0043-Reduce-items-finding-hopper-nearby-check.patch @@ -1,19 +1,19 @@ From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Mon, 15 Jan 2024 10:53:10 -0500 -Subject: [PATCH] Reduce item checks for finding MinecartHopper +Subject: [PATCH] Reduce items finding hopper nearby check -This patch add a toggle for checking MinecraftHopper nearby items, +This patch add a toggle for items checking MinecraftHopper nearby, and add a time throttler and MinecraftHopper pre-cehck for items checking -But still recommend to turn-off `checkForMinecartNearItemWhileInactive` +But still recommend to turn-off `checkForMinecartNearItemWhileActive` Since `Reduce-hopper-item-checks.patch` will cause lag under massive dropped items diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java -index 0fe02df86483809cef22fca2e2ce0af7b4a5c6d5..d6ab766ae4affb26cb8a26da113d3e70bd4b402b 100644 +index 0fe02df86483809cef22fca2e2ce0af7b4a5c6d5..7fce419490b39409f876914ce306f77d11e659b7 100644 --- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java +++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java -@@ -1,9 +1,12 @@ +@@ -1,7 +1,9 @@ package net.minecraft.world.entity.item; +import java.util.HashMap; @@ -22,34 +22,31 @@ index 0fe02df86483809cef22fca2e2ce0af7b4a5c6d5..d6ab766ae4affb26cb8a26da113d3e70 +import java.util.Map; import java.util.Objects; import java.util.UUID; -+import java.util.concurrent.TimeUnit; import javax.annotation.Nullable; - import net.minecraft.tags.DamageTypeTags; - import net.minecraft.tags.FluidTags; -@@ -219,7 +222,9 @@ public class ItemEntity extends Entity implements TraceableEntity { +@@ -219,7 +221,9 @@ public class ItemEntity extends Entity implements TraceableEntity { this.discard(); return; // Gale - EMC - reduce hopper item checks } - this.markNearbyHopperCartsAsImmune(); // Gale - EMC - reduce hopper item checks -+ if (level().galeConfig().smallOptimizations.reducedIntervals.checkNearbyItem.hopper.minecart.temporaryImmunity.checkForMinecartNearItemWhileActive) { ++ if (level().galeConfig().smallOptimizations.reducedIntervals.checkNearbyItem.hopper.minecart.temporaryImmunity.checkForMinecartNearItemWhileActive) { // Leaf - Reduce items finding hopper nearby check + this.markNearbyHopperCartsAsImmune(); // Gale - EMC - reduce hopper item checks + } } } -@@ -231,17 +236,53 @@ public class ItemEntity extends Entity implements TraceableEntity { +@@ -231,17 +235,53 @@ public class ItemEntity extends Entity implements TraceableEntity { if (config.interval <= 1) { return; } + -+ // Leaf start - Reduce item checks for finding MinecartHopper ++ // Leaf start - Reduce items finding hopper nearby check + BlockPos pos = new BlockPos(this.getBlockX(), this.getBlockY(), this.getBlockZ()); + if (this.shouldCheckItem(pos)) { + cachedResults.putIfAbsent(pos, true); + if (config.temporaryImmunity.duration > 0 && this.isAlive() && this.onGround && !this.isRemoved() && (config.temporaryImmunity.nearbyItemMaxAge == -1 || this.age <= config.temporaryImmunity.nearbyItemMaxAge) && this.age % Math.max(1, config.temporaryImmunity.checkForMinecartNearItemInterval) == 0 && config.temporaryImmunity.maxItemHorizontalDistance >= 0 && config.temporaryImmunity.maxItemVerticalDistance >= 0) { AABB aabb = this.getBoundingBox().inflate(config.temporaryImmunity.maxItemHorizontalDistance, config.temporaryImmunity.maxItemVerticalDistance, config.temporaryImmunity.maxItemHorizontalDistance); -+ if (this.level().getEntities(this, aabb).stream().noneMatch(entity -> entity instanceof MinecartHopper)) {// Leaf TODO - getEntities still take a lot of TPS ++ if (this.level().getEntities(this, aabb).stream().noneMatch(entity -> entity instanceof MinecartHopper)) { + return; + } + @@ -63,7 +60,7 @@ index 0fe02df86483809cef22fca2e2ce0af7b4a5c6d5..d6ab766ae4affb26cb8a26da113d3e70 } // Gale end - EMC - reduce hopper item checks -+ // Leaf start - Reduce item checks for finding MinecartHopper ++ // Leaf start - Reduce items finding hopper nearby check + private Map cachedResults = new HashMap<>(); + private long startTime = System.nanoTime(); + diff --git a/patches/server/0044-Optimize-item-updates-in-fluid-check.patch b/patches/server/0044-Optimize-item-updates-in-fluid-check.patch index ad821c73..22407ab5 100644 --- a/patches/server/0044-Optimize-item-updates-in-fluid-check.patch +++ b/patches/server/0044-Optimize-item-updates-in-fluid-check.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Optimize item updates in fluid check diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java -index 3cf07a2d82ec9f0d6666fb27aee9acc9d9823ead..813a02601110245161ae157f4054512d6f117cd9 100644 +index 3cf07a2d82ec9f0d6666fb27aee9acc9d9823ead..3aa0ad4fad1b44817f484cce13642ed7d3f3a4c6 100644 --- a/src/main/java/net/minecraft/world/entity/Entity.java +++ b/src/main/java/net/minecraft/world/entity/Entity.java @@ -864,9 +864,20 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource { @@ -16,9 +16,9 @@ index 3cf07a2d82ec9f0d6666fb27aee9acc9d9823ead..813a02601110245161ae157f4054512d - this.updateFluidOnEyes(); - this.updateSwimming(); + // Leaf start - Optimize item updates in fluid check -+ if (org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateEnabled) { ++ if (org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateEnabled && this instanceof ItemEntity) { + ItemEntity.checkInLiquid(this); -+ if (this instanceof ItemEntity && ItemEntity.isInLiquid) { ++ if (ItemEntity.isInLiquid) { + this.updateInWaterStateAndDoFluidPushing(); + this.updateFluidOnEyes(); + this.updateSwimming(); @@ -33,10 +33,10 @@ index 3cf07a2d82ec9f0d6666fb27aee9acc9d9823ead..813a02601110245161ae157f4054512d this.clearFire(); } else if (this.remainingFireTicks > 0) { diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java -index d6ab766ae4affb26cb8a26da113d3e70bd4b402b..d521b44325c202f9671f0b7a34aafe112cf7edbc 100644 +index 7fce419490b39409f876914ce306f77d11e659b7..065f63825627466ddd59bc68edfa72cd2ceef1c7 100644 --- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java +++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java -@@ -131,6 +131,15 @@ public class ItemEntity extends Entity implements TraceableEntity { +@@ -130,6 +130,15 @@ public class ItemEntity extends Entity implements TraceableEntity { this.getEntityData().define(ItemEntity.DATA_ITEM, ItemStack.EMPTY); } @@ -52,7 +52,7 @@ index d6ab766ae4affb26cb8a26da113d3e70bd4b402b..d521b44325c202f9671f0b7a34aafe11 @Override public void tick() { if (this.getItem().isEmpty()) { -@@ -203,7 +212,14 @@ public class ItemEntity extends Entity implements TraceableEntity { +@@ -202,7 +211,14 @@ public class ItemEntity extends Entity implements TraceableEntity { } // CraftBukkit end */ From 8db96ab1f3234ec03d564153cf3c26c44b890645 Mon Sep 17 00:00:00 2001 From: Dreeam <61569423+Dreeam-qwq@users.noreply.github.com> Date: Wed, 17 Jan 2024 06:14:13 -0500 Subject: [PATCH 4/4] Correct config name --- .../0044-Optimize-item-updates-in-fluid-check.patch | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/patches/server/0044-Optimize-item-updates-in-fluid-check.patch b/patches/server/0044-Optimize-item-updates-in-fluid-check.patch index 22407ab5..fc62d762 100644 --- a/patches/server/0044-Optimize-item-updates-in-fluid-check.patch +++ b/patches/server/0044-Optimize-item-updates-in-fluid-check.patch @@ -33,7 +33,7 @@ index 3cf07a2d82ec9f0d6666fb27aee9acc9d9823ead..3aa0ad4fad1b44817f484cce13642ed7 this.clearFire(); } else if (this.remainingFireTicks > 0) { diff --git a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java -index 7fce419490b39409f876914ce306f77d11e659b7..065f63825627466ddd59bc68edfa72cd2ceef1c7 100644 +index 7fce419490b39409f876914ce306f77d11e659b7..2e15896df321c076cf1c3ef78e67cea9188e9ddb 100644 --- a/src/main/java/net/minecraft/world/entity/item/ItemEntity.java +++ b/src/main/java/net/minecraft/world/entity/item/ItemEntity.java @@ -130,6 +130,15 @@ public class ItemEntity extends Entity implements TraceableEntity { @@ -43,7 +43,7 @@ index 7fce419490b39409f876914ce306f77d11e659b7..065f63825627466ddd59bc68edfa72cd + // Leaf start - Optimize item updates in fluid check + public static boolean isInLiquid = false; + public static void checkInLiquid(Entity e) { -+ if (e.tickCount % org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateTickCount == 0) { ++ if (e.tickCount % org.dreeam.leaf.LeafConfig.optimizeItemsInFluidUpdateInterval == 0) { + isInLiquid = e.isInLiquid(); + } + } @@ -69,7 +69,7 @@ index 7fce419490b39409f876914ce306f77d11e659b7..065f63825627466ddd59bc68edfa72cd double d0 = this.getDeltaMovement().subtract(vec3d).lengthSqr(); diff --git a/src/main/java/org/dreeam/leaf/LeafConfig.java b/src/main/java/org/dreeam/leaf/LeafConfig.java -index 53bde816ca9bf8b704fb2e9794de260a9eba402f..98723f55a5557f10b75a299c586bf2caf31887f3 100644 +index 53bde816ca9bf8b704fb2e9794de260a9eba402f..82e51da38a66826feb58fd28b39858ef91ddf7ab 100644 --- a/src/main/java/org/dreeam/leaf/LeafConfig.java +++ b/src/main/java/org/dreeam/leaf/LeafConfig.java @@ -202,6 +202,8 @@ public class LeafConfig { @@ -77,7 +77,7 @@ index 53bde816ca9bf8b704fb2e9794de260a9eba402f..98723f55a5557f10b75a299c586bf2ca public static int asyncPathfindingKeepalive = 60; public static boolean cacheMinecartCollision = false; + public static boolean optimizeItemsInFluidUpdateEnabled = false; -+ public static int optimizeItemsInFluidUpdateTickCount = 20; ++ public static int optimizeItemsInFluidUpdateInterval = 20; private static void performance() { boolean asyncMobSpawning = getBoolean("performance.enable-async-mob-spawning", enableAsyncMobSpawning, "Whether or not asynchronous mob spawning should be enabled.", @@ -86,7 +86,7 @@ index 53bde816ca9bf8b704fb2e9794de260a9eba402f..98723f55a5557f10b75a299c586bf2ca "Cache the minecart collision result to prevent massive stacked minecart lag the server.", "The known issue: entity can't enter the minecart after enabling this!"); + optimizeItemsInFluidUpdateEnabled = getBoolean("performance.optimize-items-in-fluid-update.enabled", optimizeItemsInFluidUpdateEnabled); -+ optimizeItemsInFluidUpdateTickCount = getInt("performance.optimize-items-in-fluid-update.tick-count", optimizeItemsInFluidUpdateTickCount); ++ optimizeItemsInFluidUpdateInterval = getInt("performance.optimize-items-in-fluid-update.interval", optimizeItemsInFluidUpdateInterval); + }