13
0
geforkt von Mirrors/Paper

Make hoppers respect inventory max stack size

Dieser Commit ist enthalten in:
Jake Potrebic 2021-07-07 16:30:17 -07:00
Ursprung 0e4e270396
Commit 70262052bd

Datei anzeigen

@ -156,11 +156,10 @@
- private static boolean tryTakeInItemFromSlot(Hopper hopper, Container inventory, int slot, Direction side) { - private static boolean tryTakeInItemFromSlot(Hopper hopper, Container inventory, int slot, Direction side) {
- ItemStack itemstack = inventory.getItem(slot); - ItemStack itemstack = inventory.getItem(slot);
-
- if (!itemstack.isEmpty() && HopperBlockEntity.canTakeItemFromContainer(hopper, inventory, itemstack, slot, side)) {
+ private static boolean tryTakeInItemFromSlot(Hopper ihopper, Container iinventory, int i, Direction enumdirection, Level world) { // Spigot + private static boolean tryTakeInItemFromSlot(Hopper ihopper, Container iinventory, int i, Direction enumdirection, Level world) { // Spigot
+ ItemStack itemstack = iinventory.getItem(i); + ItemStack itemstack = iinventory.getItem(i);
+
- if (!itemstack.isEmpty() && HopperBlockEntity.canTakeItemFromContainer(hopper, inventory, itemstack, slot, side)) {
+ if (!itemstack.isEmpty() && HopperBlockEntity.canTakeItemFromContainer(ihopper, iinventory, itemstack, i, enumdirection)) { + if (!itemstack.isEmpty() && HopperBlockEntity.canTakeItemFromContainer(ihopper, iinventory, itemstack, i, enumdirection)) {
int j = itemstack.getCount(); int j = itemstack.getCount();
- ItemStack itemstack1 = HopperBlockEntity.addItem(inventory, hopper, inventory.removeItem(slot, 1), (Direction) null); - ItemStack itemstack1 = HopperBlockEntity.addItem(inventory, hopper, inventory.removeItem(slot, 1), (Direction) null);
@ -233,19 +232,28 @@
} else { } else {
itemEntity.setItem(itemstack1); itemEntity.setItem(itemstack1);
} }
@@ -383,6 +494,11 @@ @@ -383,11 +494,18 @@
boolean flag1 = to.isEmpty(); boolean flag1 = to.isEmpty();
if (itemstack1.isEmpty()) { if (itemstack1.isEmpty()) {
+ // Spigot start - SPIGOT-6693, InventorySubcontainer#setItem + // Spigot start - SPIGOT-6693, InventorySubcontainer#setItem
+ ItemStack leftover = ItemStack.EMPTY; // Paper - Make hoppers respect inventory max stack size
+ if (!stack.isEmpty() && stack.getCount() > to.getMaxStackSize()) { + if (!stack.isEmpty() && stack.getCount() > to.getMaxStackSize()) {
+ leftover = stack; // Paper - Make hoppers respect inventory max stack size
+ stack = stack.split(to.getMaxStackSize()); + stack = stack.split(to.getMaxStackSize());
+ } + }
+ // Spigot end + // Spigot end
to.setItem(slot, stack); to.setItem(slot, stack);
stack = ItemStack.EMPTY; - stack = ItemStack.EMPTY;
+ stack = leftover; // Paper - Make hoppers respect inventory max stack size
flag = true; flag = true;
@@ -410,7 +526,7 @@ } else if (HopperBlockEntity.canMergeItems(itemstack1, stack)) {
- int j = stack.getMaxStackSize() - itemstack1.getCount();
+ int j = Math.min(stack.getMaxStackSize(), to.getMaxStackSize()) - itemstack1.getCount(); // Paper - Make hoppers respect inventory max stack size
int k = Math.min(stack.getCount(), j);
stack.shrink(k);
@@ -410,7 +528,7 @@
} }
} }
@ -254,23 +262,21 @@
} }
} }
@@ -419,16 +535,40 @@ @@ -421,14 +539,38 @@
}
return stack; return stack;
+ } }
+
+ // CraftBukkit start + // CraftBukkit start
+ @Nullable @Nullable
+ private static Container runHopperInventorySearchEvent(Container inventory, CraftBlock hopper, CraftBlock searchLocation, HopperInventorySearchEvent.ContainerType containerType) { + private static Container runHopperInventorySearchEvent(Container inventory, CraftBlock hopper, CraftBlock searchLocation, HopperInventorySearchEvent.ContainerType containerType) {
+ HopperInventorySearchEvent event = new HopperInventorySearchEvent((inventory != null) ? new CraftInventory(inventory) : null, containerType, hopper, searchLocation); + HopperInventorySearchEvent event = new HopperInventorySearchEvent((inventory != null) ? new CraftInventory(inventory) : null, containerType, hopper, searchLocation);
+ Bukkit.getServer().getPluginManager().callEvent(event); + Bukkit.getServer().getPluginManager().callEvent(event);
+ CraftInventory craftInventory = (CraftInventory) event.getInventory(); + CraftInventory craftInventory = (CraftInventory) event.getInventory();
+ return (craftInventory != null) ? craftInventory.getInventory() : null; + return (craftInventory != null) ? craftInventory.getInventory() : null;
} + }
+ // CraftBukkit end + // CraftBukkit end
+
@Nullable + @Nullable
private static Container getAttachedContainer(Level world, BlockPos pos, HopperBlockEntity blockEntity) { private static Container getAttachedContainer(Level world, BlockPos pos, HopperBlockEntity blockEntity) {
- return HopperBlockEntity.getContainerAt(world, pos.relative(blockEntity.facing)); - return HopperBlockEntity.getContainerAt(world, pos.relative(blockEntity.facing));
+ // CraftBukkit start + // CraftBukkit start
@ -297,7 +303,7 @@
} }
public static List<ItemEntity> getItemsAtAndAbove(Level world, Hopper hopper) { public static List<ItemEntity> getItemsAtAndAbove(Level world, Hopper hopper) {
@@ -455,6 +595,7 @@ @@ -455,6 +597,7 @@
@Nullable @Nullable
private static Container getBlockContainer(Level world, BlockPos pos, BlockState state) { private static Container getBlockContainer(Level world, BlockPos pos, BlockState state) {
@ -305,7 +311,7 @@
Block block = state.getBlock(); Block block = state.getBlock();
if (block instanceof WorldlyContainerHolder) { if (block instanceof WorldlyContainerHolder) {
@@ -543,7 +684,7 @@ @@ -543,7 +686,7 @@
} }
@Override @Override