mirror of
https://github.com/LeavesMC/Leaves.git
synced 2025-12-19 14:59:32 +00:00
fix: fix sleeping block entity (#723)
This commit is contained in:
@@ -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.
|
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
|
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
|
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||||
+++ b/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;
|
ItemStack movedItem = origItemStack;
|
||||||
final int originalItemCount = origItemStack.getCount();
|
final int originalItemCount = origItemStack.getCount();
|
||||||
final int movedItemCount = Math.min(level.spigotConfig.hopperAmount, originalItemCount);
|
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
|
- // site for IMIE did not exhibit the same behavior
|
||||||
+ // Leaves start - fix vanilla
|
+ // Leaves start - fix vanilla
|
||||||
+ if (org.leavesmc.leaves.LeavesConfig.fix.vanillaHopper && movedItem.getCount() <= movedItemCount) {
|
+ 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();
|
+ movedItem = origItemStack.copy();
|
||||||
+ final ItemStack remainingItem = addItem(container, hopper, container.removeItem(i, movedItemCount), null);
|
+ final ItemStack remainingItem = addItem(container, hopper, container.removeItem(i, movedItemCount), null);
|
||||||
+ if (remainingItem.isEmpty()) {
|
+ if (remainingItem.isEmpty()) {
|
||||||
|
|||||||
@@ -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
|
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
|
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||||
+++ b/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;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1424,7 +1424,7 @@ index 363d85c96bd3fb1a1945595df36e30bd6dd2fa4e..542910b3d5faa85f2b14022932c058bc
|
|||||||
+ // Leaves end - Lithium Sleeping Block Entity
|
+ // 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
|
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
|
--- a/net/minecraft/world/level/block/entity/HopperBlockEntity.java
|
||||||
+++ b/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;
|
@@ -27,8 +27,30 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
@@ -1491,7 +1491,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a
|
|||||||
return true;
|
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
|
// Leaves end - hopper counter
|
||||||
@@ -1512,7 +1512,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a
|
|||||||
if (isFullContainer(attachedContainer, opposite)) {
|
if (isFullContainer(attachedContainer, opposite)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} 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) {
|
public static boolean suckInItems(Level level, Hopper hopper) {
|
||||||
BlockPos blockPos = BlockPos.containing(hopper.getLevelX(), hopper.getLevelY() + 1.0, hopper.getLevelZ());
|
BlockPos blockPos = BlockPos.containing(hopper.getLevelX(), hopper.getLevelY() + 1.0, hopper.getLevelZ());
|
||||||
BlockState blockState = level.getBlockState(blockPos);
|
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
|
+ 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) {
|
if (sourceContainer != null) {
|
||||||
Direction direction = Direction.DOWN;
|
Direction direction = Direction.DOWN;
|
||||||
|
skipPullModeEventFire = skipHopperEvents; // Paper - Perf: Optimize Hoppers
|
||||||
+ // Leaves start - Lithium Sleeping Block Entity
|
+ // Leaves start - Lithium Sleeping Block Entity
|
||||||
+ if (org.leavesmc.leaves.LeavesConfig.performance.sleepingBlockEntity) {
|
+ if (org.leavesmc.leaves.LeavesConfig.performance.sleepingBlockEntity) {
|
||||||
+ Boolean res = lithiumExtract(level, hopper, sourceContainer);
|
+ Boolean res = lithiumExtract(level, hopper, sourceContainer);
|
||||||
@@ -1528,10 +1529,10 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a
|
|||||||
+ }
|
+ }
|
||||||
+ }
|
+ }
|
||||||
+ // Leaves end - Lithium Sleeping Block Entity
|
+ // Leaves end - Lithium Sleeping Block Entity
|
||||||
skipPullModeEventFire = skipHopperEvents; // Paper - Perf: Optimize Hoppers
|
|
||||||
|
|
||||||
for (int i : getSlots(sourceContainer, direction)) {
|
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 {
|
} 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
|
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) {
|
if (!flag) {
|
||||||
@@ -1540,7 +1541,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a
|
|||||||
if (addItem(hopper, itemEntity)) {
|
if (addItem(hopper, itemEntity)) {
|
||||||
return true;
|
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) {
|
public void setCooldown(int cooldownTime) {
|
||||||
@@ -1560,7 +1561,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a
|
|||||||
this.cooldownTime = cooldownTime;
|
this.cooldownTime = cooldownTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -944,6 +1005,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
@@ -954,6 +1015,7 @@ public class HopperBlockEntity extends RandomizableContainerBlockEntity implemen
|
||||||
@Override
|
@Override
|
||||||
protected void setItems(NonNullList<ItemStack> items) {
|
protected void setItems(NonNullList<ItemStack> items) {
|
||||||
this.items = 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) {
|
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) {
|
protected AbstractContainerMenu createMenu(int id, Inventory player) {
|
||||||
return new HopperMenu(id, player, this);
|
return new HopperMenu(id, player, this);
|
||||||
}
|
}
|
||||||
@@ -2204,20 +2205,25 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a
|
|||||||
+ hopperBlockEntity.insertStackList.getOccupiedSlots() == 0;
|
+ hopperBlockEntity.insertStackList.getOccupiedSlots() == 0;
|
||||||
+
|
+
|
||||||
+ boolean insertInventoryHandlesModdedCooldown =
|
+ boolean insertInventoryHandlesModdedCooldown =
|
||||||
+ ((LithiumCooldownReceivingInventory) insertInventory).canReceiveTransferCooldown() &&
|
+ insertInventory.canReceiveTransferCooldown() &&
|
||||||
+ hopperBlockEntity.insertStackList != null ?
|
+ hopperBlockEntity.insertStackList != null ?
|
||||||
+ hopperBlockEntity.insertStackList.getOccupiedSlots() == 0 :
|
+ hopperBlockEntity.insertStackList.getOccupiedSlots() == 0 :
|
||||||
+ insertInventory.isEmpty();
|
+ insertInventory.isEmpty();
|
||||||
+
|
+
|
||||||
+
|
+ skipPushModeEventFire = skipHopperEvents;
|
||||||
+ //noinspection ConstantConditions
|
+ //noinspection ConstantConditions
|
||||||
+ if (!(hopperBlockEntity.insertInventory == insertInventory && hopperBlockEntity.insertStackList.getFullSlots() == hopperBlockEntity.insertStackList.size())) {
|
+ if (!(hopperBlockEntity.insertInventory == insertInventory && hopperBlockEntity.insertStackList.getFullSlots() == hopperBlockEntity.insertStackList.size())) {
|
||||||
+ Direction fromDirection = hopperBlockEntity.facing.getOpposite();
|
+ Direction fromDirection = hopperBlockEntity.facing.getOpposite();
|
||||||
+ int size = hopperStackList.size();
|
+ int size = hopperStackList.size();
|
||||||
+ //noinspection ForLoopReplaceableByForEach
|
|
||||||
+ for (int i = 0; i < size; ++i) {
|
+ for (int i = 0; i < size; ++i) {
|
||||||
+ ItemStack transferStack = hopperStackList.get(i);
|
+ ItemStack transferStack = hopperStackList.get(i);
|
||||||
+ if (!transferStack.isEmpty()) {
|
+ 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);
|
+ boolean transferSuccess = HopperHelper.tryMoveSingleItem(insertInventory, transferStack, fromDirection);
|
||||||
+ if (transferSuccess) {
|
+ if (transferSuccess) {
|
||||||
+ if (insertInventoryWasEmptyHopperNotDisabled) {
|
+ if (insertInventoryWasEmptyHopperNotDisabled) {
|
||||||
@@ -2229,7 +2235,7 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a
|
|||||||
+ receivingHopper.setCooldown(k);
|
+ receivingHopper.setCooldown(k);
|
||||||
+ }
|
+ }
|
||||||
+ if (insertInventoryHandlesModdedCooldown) {
|
+ if (insertInventoryHandlesModdedCooldown) {
|
||||||
+ ((LithiumCooldownReceivingInventory) insertInventory).setTransferCooldown(hopperBlockEntity.tickedGameTime);
|
+ insertInventory.setTransferCooldown(hopperBlockEntity.tickedGameTime);
|
||||||
+ }
|
+ }
|
||||||
+ insertInventory.setChanged();
|
+ insertInventory.setChanged();
|
||||||
+ return true;
|
+ return true;
|
||||||
@@ -2272,6 +2278,12 @@ index d9969741bb8efbf83df51692ebcd12e3d77c10f6..4ed998637ea724e95ba491534b1ca69a
|
|||||||
+ int fromSlot = availableSlots != null ? availableSlots[i] : i;
|
+ int fromSlot = availableSlots != null ? availableSlots[i] : i;
|
||||||
+ ItemStack itemStack = fromStackList.get(fromSlot);
|
+ ItemStack itemStack = fromStackList.get(fromSlot);
|
||||||
+ if (!itemStack.isEmpty() && canTakeItemFromContainer(to, from, itemStack, fromSlot, Direction.DOWN)) {
|
+ 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)
|
+ //calling removeStack is necessary due to its side effects (markDirty in LootableContainerBlockEntity)
|
||||||
+ ItemStack takenItem = from.removeItem(fromSlot, 1);
|
+ ItemStack takenItem = from.removeItem(fromSlot, 1);
|
||||||
+ assert !takenItem.isEmpty();
|
+ assert !takenItem.isEmpty();
|
||||||
|
|||||||
@@ -14,9 +14,10 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class ChunkSectionInventoryEntityTracker extends ChunkSectionEntityMovementTracker {
|
public class ChunkSectionInventoryEntityTracker extends ChunkSectionEntityMovementTracker {
|
||||||
public static final Map<ChunkSectionIdentifier, ChunkSectionInventoryEntityTracker> containerEntityMovementTrackerMap = new java.util.HashMap<>();
|
public static final Map<ChunkSectionIdentifier, ChunkSectionInventoryEntityTracker> containerEntityMovementTrackerMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public ChunkSectionInventoryEntityTracker(long sectionKey, UUID levelId) {
|
public ChunkSectionInventoryEntityTracker(long sectionKey, UUID levelId) {
|
||||||
super(sectionKey, levelId);
|
super(sectionKey, levelId);
|
||||||
|
|||||||
@@ -14,9 +14,10 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class ChunkSectionItemEntityMovementTracker extends ChunkSectionEntityMovementTracker {
|
public class ChunkSectionItemEntityMovementTracker extends ChunkSectionEntityMovementTracker {
|
||||||
public static final Map<ChunkSectionIdentifier, ChunkSectionItemEntityMovementTracker> itemEntityMovementTrackerMap = new java.util.HashMap<>();
|
public static final Map<ChunkSectionIdentifier, ChunkSectionItemEntityMovementTracker> itemEntityMovementTrackerMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public ChunkSectionItemEntityMovementTracker(long sectionKey, UUID levelId) {
|
public ChunkSectionItemEntityMovementTracker(long sectionKey, UUID levelId) {
|
||||||
super(sectionKey, levelId);
|
super(sectionKey, levelId);
|
||||||
|
|||||||
Reference in New Issue
Block a user