fixed exception on too many items in a slot

This commit is contained in:
Jottyfan 2025-02-08 17:27:49 +01:00
parent 81e45c56ce
commit 17a11ce56a
2 changed files with 11 additions and 4 deletions

View File

@ -9,7 +9,7 @@ yarn_mappings=1.21.4+build.1
loader_version=0.16.9
# Mod Properties
mod_version=1.21.4.4
mod_version=1.21.4.5
maven_group=de.jottyfan.quickiemod
archives_base_name=quickiemod

View File

@ -30,7 +30,6 @@ import net.minecraft.world.World;
*/
public class ItemHoarderBlockEntity extends LootableContainerBlockEntity {
private DefaultedList<ItemStack> stacks;
private float suckradius;
@ -44,9 +43,17 @@ public class ItemHoarderBlockEntity extends LootableContainerBlockEntity {
public final static boolean setStackToSlots(ItemStack stack, List<ItemStack> stacks) {
for (ItemStack slot : stacks) {
Integer sum = stack.getCount() + slot.getCount();
if (slot.getItem().equals(stack.getItem())) {
if (slot.getItem().getMaxCount() >= sum) {
slot.increment(stack.getCount());
return true;
} else {
Integer transferSize = 64 - stack.getCount();
stack.setCount(stack.getCount() - transferSize);
slot.setCount(64);
// to not return sth. here so that the next loop will sum up the result
}
}
} // if not found, seek for an empty stack instead
for (ItemStack slot : stacks) {