From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: MrPowerGamerBR Date: Fri, 23 Aug 2024 16:20:45 -0300 Subject: [PATCH] SparklyPaper: Allow throttling hopper checks if the target container is full Original project: https://github.com/SparklyPower/SparklyPaper diff --git a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java index 67425f4270c0745fc962c6ffb90e98bb4362d261..989e0f049805a734d6aa18434dd2a3b2d6c2ace1 100644 --- a/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java +++ b/src/main/java/net/minecraft/world/level/block/entity/HopperBlockEntity.java @@ -441,6 +441,11 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen Direction enumdirection = blockEntity.facing.getOpposite(); if (HopperBlockEntity.isFullContainer(iinventory, enumdirection)) { + // Leaf start - Throttle hopper when full + if (org.dreeam.leaf.config.modules.opt.ThrottleHopperWhenFull.enabled && org.dreeam.leaf.config.modules.opt.ThrottleHopperWhenFull.skipTicks > 0) { + blockEntity.setCooldown(org.dreeam.leaf.config.modules.opt.ThrottleHopperWhenFull.skipTicks); + } + // Leaf end - Throttle hopper when full return false; } else { // Paper start - Perf: Optimize Hoppers diff --git a/src/main/java/org/dreeam/leaf/config/modules/opt/ThrottleHopperWhenFull.java b/src/main/java/org/dreeam/leaf/config/modules/opt/ThrottleHopperWhenFull.java new file mode 100644 index 0000000000000000000000000000000000000000..3facc08ed627a710a1cf26c67abfbfa1b380fe44 --- /dev/null +++ b/src/main/java/org/dreeam/leaf/config/modules/opt/ThrottleHopperWhenFull.java @@ -0,0 +1,26 @@ +package org.dreeam.leaf.config.modules.opt; + +import org.dreeam.leaf.config.ConfigModules; +import org.dreeam.leaf.config.EnumConfigCategory; + +public class ThrottleHopperWhenFull extends ConfigModules { + + public String getBasePath() { + return EnumConfigCategory.PERF.getBaseKeyName() + ".throttle-hopper-when-full"; + } + + public static boolean enabled = false; + public static int skipTicks = 0; + + @Override + public void onLoaded() { + enabled = config.getBoolean(getBasePath() + ".enabled", enabled, config.pickStringRegionBased(""" + Throttles the hopper if target container is full.""", + """ + 是否在目标容器已满时阻塞漏斗.""")); + skipTicks = config.getInt(getBasePath() + ".skip-ticks", skipTicks, config.pickStringRegionBased(""" + How many ticks to throttle when the Hopper is throttled.""", + """ + 每次阻塞多少 tick.""")); + } +}