diff --git a/leaves-server/minecraft-patches/features/0094-Vanilla-hopper.patch b/leaves-server/minecraft-patches/features/0094-Vanilla-hopper.patch index 490d7088..8e5159b6 100644 --- a/leaves-server/minecraft-patches/features/0094-Vanilla-hopper.patch +++ b/leaves-server/minecraft-patches/features/0094-Vanilla-hopper.patch @@ -6,10 +6,10 @@ Subject: [PATCH] Vanilla hopper This is a temporary solution designed to attempt to restore the vanilla behavior of the funnel while preserving optimizations as much as possible. It should ultimately be replaced by the optimization solution provided by lithium. diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java -index f1388ad51b7549e881cae36a5a9bcd4229442f3e..b24945b48ecb1a610afa850de5dd833b61bda1d9 100644 +index 3145b6ee853f720c5c201f5dd464645eb039100c..deb67f1636d7fcb24946019d36fbdf97c022e764 100644 --- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java +++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java -@@ -307,36 +307,48 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -307,36 +307,58 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen ItemStack movedItem = origItemStack; final int originalItemCount = origItemStack.getCount(); final int movedItemCount = Math.min(level.spigotConfig.hopperAmount, originalItemCount); @@ -25,6 +25,16 @@ index f1388ad51b7549e881cae36a5a9bcd4229442f3e..b24945b48ecb1a610afa850de5dd833b - // site for IMIE did not exhibit the same behavior + // Leaves start - fix vanilla + if (org.leavesmc.leaves.LeavesConfig.fix.vanillaHopper && movedItem.getCount() <= movedItemCount) { ++ if (!skipPullModeEventFire) { ++ movedItem = callPullMoveEvent(hopper, container, movedItem); ++ if (movedItem == null) { // cancelled ++ origItemStack.setCount(originalItemCount); ++ // Drastically improve performance by returning true. ++ // No plugin could have relied on the behavior of false as the other call ++ // site for IMIE did not exhibit the same behavior ++ return true; ++ } ++ } + movedItem = origItemStack.copy(); + final ItemStack remainingItem = addItem(container, hopper, container.removeItem(i, movedItemCount), null); + if (remainingItem.isEmpty()) { diff --git a/leaves-server/minecraft-patches/features/0095-Old-hopper-suckin-behavior.patch b/leaves-server/minecraft-patches/features/0095-Old-hopper-suckin-behavior.patch index 2d791526..81ec1446 100644 --- a/leaves-server/minecraft-patches/features/0095-Old-hopper-suckin-behavior.patch +++ b/leaves-server/minecraft-patches/features/0095-Old-hopper-suckin-behavior.patch @@ -5,10 +5,10 @@ Subject: [PATCH] Old hopper suckin behavior diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java -index b24945b48ecb1a610afa850de5dd833b61bda1d9..f6df4c049ed3460eb437a4637c122a5880f2bdbc 100644 +index deb67f1636d7fcb24946019d36fbdf97c022e764..09083d971ffc6e8af17cac9e71acbead2e666fc4 100644 --- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java +++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java -@@ -619,7 +619,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -629,7 +629,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen return false; } else { diff --git a/leaves-server/minecraft-patches/features/0138-Lithium-Sleeping-Block-Entity.patch b/leaves-server/minecraft-patches/features/0138-Lithium-Sleeping-Block-Entity.patch index 84146675..4e1423c1 100644 --- a/leaves-server/minecraft-patches/features/0138-Lithium-Sleeping-Block-Entity.patch +++ b/leaves-server/minecraft-patches/features/0138-Lithium-Sleeping-Block-Entity.patch @@ -1424,7 +1424,7 @@ index 363d85c96bd3fb1a1945595df36e30bd6dd2fa4e..542910b3d5faa85f2b14022932c058bc + // Leaves end - Lithium Sleeping Block Entity } diff --git a/net/minecraft/world/level/block/entity/HopperBlockEntity.java b/net/minecraft/world/level/block/entity/HopperBlockEntity.java -index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a5bd314cd 100644 +index f3d2d86b5065064013f37592ba7f53fdf4066629..8b101e41440bf78da1eae507153e118c04615934 100644 --- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java +++ b/net/minecraft/world/level/block/entity/HopperBlockEntity.java @@ -27,8 +27,30 @@ import net.minecraft.world.level.block.state.BlockState; @@ -1491,7 +1491,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a return true; } } -@@ -478,11 +510,19 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -488,11 +520,19 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen } } // Leaves end - hopper counter @@ -1512,7 +1512,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a if (isFullContainer(attachedContainer, opposite)) { return false; } else { -@@ -611,9 +651,17 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -621,10 +661,18 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen public static boolean suckInItems(Level level, Hopper hopper) { BlockPos blockPos = BlockPos.containing(hopper.getLevelX(), hopper.getLevelY() + 1.0, hopper.getLevelZ()); BlockState blockState = level.getBlockState(blockPos); @@ -1520,6 +1520,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a + Container sourceContainer = org.leavesmc.leaves.LeavesConfig.performance.sleepingBlockEntity ? getExtractInventory(level, hopper, blockPos, blockState) : getSourceContainer(level, hopper, blockPos, blockState); // Leaves - Lithium Sleeping Block Entity if (sourceContainer != null) { Direction direction = Direction.DOWN; + skipPullModeEventFire = skipHopperEvents; // Paper - Perf: Optimize Hoppers + // Leaves start - Lithium Sleeping Block Entity + if (org.leavesmc.leaves.LeavesConfig.performance.sleepingBlockEntity) { + Boolean res = lithiumExtract(level, hopper, sourceContainer); @@ -1528,10 +1529,10 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a + } + } + // Leaves end - Lithium Sleeping Block Entity - skipPullModeEventFire = skipHopperEvents; // Paper - Perf: Optimize Hoppers for (int i : getSlots(sourceContainer, direction)) { -@@ -626,7 +674,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen + if (tryTakeInItemFromSlot(hopper, sourceContainer, i, direction, level)) { // Spigot +@@ -636,7 +684,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen } else { boolean flag = hopper.isGridAligned() && (!org.leavesmc.leaves.LeavesConfig.modify.oldMC.oldHopperSuckInBehavior && blockState.isCollisionShapeFullBlock(level, blockPos)) && !blockState.is(BlockTags.DOES_NOT_BLOCK_HOPPERS); // Leaves - oldHopperSuckInBehavior if (!flag) { @@ -1540,7 +1541,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a if (addItem(hopper, itemEntity)) { return true; } -@@ -925,6 +973,19 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -935,6 +983,19 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen } public void setCooldown(int cooldownTime) { @@ -1560,7 +1561,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a this.cooldownTime = cooldownTime; } -@@ -944,6 +1005,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -954,6 +1015,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen @Override protected void setItems(NonNullList items) { this.items = items; @@ -1568,7 +1569,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a } public static void entityInside(Level level, BlockPos pos, BlockState state, Entity entity, HopperBlockEntity blockEntity) { -@@ -958,4 +1020,731 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen +@@ -968,4 +1030,742 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen protected AbstractContainerMenu createMenu(int id, Inventory player) { return new HopperMenu(id, player, this); } @@ -2204,20 +2205,25 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a + hopperBlockEntity.insertStackList.getOccupiedSlots() == 0; + + boolean insertInventoryHandlesModdedCooldown = -+ ((LithiumCooldownReceivingInventory) insertInventory).canReceiveTransferCooldown() && ++ insertInventory.canReceiveTransferCooldown() && + hopperBlockEntity.insertStackList != null ? + hopperBlockEntity.insertStackList.getOccupiedSlots() == 0 : + insertInventory.isEmpty(); + -+ ++ skipPushModeEventFire = skipHopperEvents; + //noinspection ConstantConditions + if (!(hopperBlockEntity.insertInventory == insertInventory && hopperBlockEntity.insertStackList.getFullSlots() == hopperBlockEntity.insertStackList.size())) { + Direction fromDirection = hopperBlockEntity.facing.getOpposite(); + int size = hopperStackList.size(); -+ //noinspection ForLoopReplaceableByForEach + for (int i = 0; i < size; ++i) { + ItemStack transferStack = hopperStackList.get(i); + if (!transferStack.isEmpty()) { ++ if (!skipPushModeEventFire && canTakeItemFromContainer(insertInventory, hopperBlockEntity, transferStack, i, Direction.DOWN)) { ++ transferStack = callPushMoveEvent(insertInventory, transferStack, hopperBlockEntity); ++ if (transferStack == null) { // cancelled ++ break; ++ } ++ } + boolean transferSuccess = HopperHelper.tryMoveSingleItem(insertInventory, transferStack, fromDirection); + if (transferSuccess) { + if (insertInventoryWasEmptyHopperNotDisabled) { @@ -2229,7 +2235,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a + receivingHopper.setCooldown(k); + } + if (insertInventoryHandlesModdedCooldown) { -+ ((LithiumCooldownReceivingInventory) insertInventory).setTransferCooldown(hopperBlockEntity.tickedGameTime); ++ insertInventory.setTransferCooldown(hopperBlockEntity.tickedGameTime); + } + insertInventory.setChanged(); + return true; @@ -2272,6 +2278,12 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a + int fromSlot = availableSlots != null ? availableSlots[i] : i; + ItemStack itemStack = fromStackList.get(fromSlot); + if (!itemStack.isEmpty() && canTakeItemFromContainer(to, from, itemStack, fromSlot, Direction.DOWN)) { ++ if (!skipPullModeEventFire) { ++ itemStack = callPullMoveEvent(to, from, itemStack); ++ if (itemStack == null) { // cancelled ++ return true; ++ } ++ } + //calling removeStack is necessary due to its side effects (markDirty in LootableContainerBlockEntity) + ItemStack takenItem = from.removeItem(fromSlot, 1); + assert !takenItem.isEmpty(); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/lithium/common/tracking/entity/ChunkSectionInventoryEntityTracker.java b/leaves-server/src/main/java/org/leavesmc/leaves/lithium/common/tracking/entity/ChunkSectionInventoryEntityTracker.java index 60e9e039..b321c6a7 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/lithium/common/tracking/entity/ChunkSectionInventoryEntityTracker.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/lithium/common/tracking/entity/ChunkSectionInventoryEntityTracker.java @@ -14,9 +14,10 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; public class ChunkSectionInventoryEntityTracker extends ChunkSectionEntityMovementTracker { - public static final Map containerEntityMovementTrackerMap = new java.util.HashMap<>(); + public static final Map containerEntityMovementTrackerMap = new ConcurrentHashMap<>(); public ChunkSectionInventoryEntityTracker(long sectionKey, UUID levelId) { super(sectionKey, levelId); diff --git a/leaves-server/src/main/java/org/leavesmc/leaves/lithium/common/tracking/entity/ChunkSectionItemEntityMovementTracker.java b/leaves-server/src/main/java/org/leavesmc/leaves/lithium/common/tracking/entity/ChunkSectionItemEntityMovementTracker.java index 8b6bdc77..26893dbf 100644 --- a/leaves-server/src/main/java/org/leavesmc/leaves/lithium/common/tracking/entity/ChunkSectionItemEntityMovementTracker.java +++ b/leaves-server/src/main/java/org/leavesmc/leaves/lithium/common/tracking/entity/ChunkSectionItemEntityMovementTracker.java @@ -14,9 +14,10 @@ import java.util.Collections; import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; public class ChunkSectionItemEntityMovementTracker extends ChunkSectionEntityMovementTracker { - public static final Map itemEntityMovementTrackerMap = new java.util.HashMap<>(); + public static final Map itemEntityMovementTrackerMap = new ConcurrentHashMap<>(); public ChunkSectionItemEntityMovementTracker(long sectionKey, UUID levelId) { super(sectionKey, levelId);