From bed1537d9aeb5cf45a8d286287dca39b22d389f0 Mon Sep 17 00:00:00 2001 From: Sen Date: Tue, 12 Aug 2025 17:18:51 +0200 Subject: [PATCH] fix dispensers --- .../java/common/item/material/ItemBucket.java | 2 +- .../common/tileentity/DeviceDispenser.java | 68 ++++--------------- 2 files changed, 15 insertions(+), 55 deletions(-) diff --git a/common/src/main/java/common/item/material/ItemBucket.java b/common/src/main/java/common/item/material/ItemBucket.java index 5aca3a09..985459c6 100755 --- a/common/src/main/java/common/item/material/ItemBucket.java +++ b/common/src/main/java/common/item/material/ItemBucket.java @@ -358,7 +358,7 @@ public class ItemBucket extends Item stack.setItem(item); stack.setSize(1); } - else if (source instanceof DeviceDispenser dispenser && dispenser.addItemStack(new ItemStack(item)) < 0) + else if (source instanceof DeviceDispenser dispenser && !dispenser.addItemStack(new ItemStack(item))) { super.dispenseStack(world, source, position, blockpos, facing, new ItemStack(item)); } diff --git a/common/src/main/java/common/tileentity/DeviceDispenser.java b/common/src/main/java/common/tileentity/DeviceDispenser.java index 9857a2d7..a47d4892 100755 --- a/common/src/main/java/common/tileentity/DeviceDispenser.java +++ b/common/src/main/java/common/tileentity/DeviceDispenser.java @@ -19,38 +19,18 @@ public class DeviceDispenser extends Device private int cooldown = 0; public DeviceDispenser(boolean dropItems) { - super(9, 0); + super(1, 0); this.dropItems = dropItems; } - public int getDispenseSlot() + public boolean addItemStack(ItemStack stack) { - int i = -1; - int j = 1; - - for (int k = 0; k < this.getSizeInventory(); ++k) + if (this.getStackInSlot(0) == null) { - if (this.getStackInSlot(k) != null && RNG.zrange(j++) == 0) - { - i = k; - } + this.setInventorySlotContents(0, stack); + return true; } - - return i; - } - - public int addItemStack(ItemStack stack) - { - for (int i = 0; i < this.getSizeInventory(); ++i) - { - if (this.getStackInSlot(i) == null) - { - this.setInventorySlotContents(i, stack); - return i; - } - } - - return -1; + return false; } public void readTags(TagObject compound) @@ -82,40 +62,20 @@ public class DeviceDispenser extends Device return nstack; } - private boolean dispense(AWorldServer worldIn, BlockPos pos) - { - TileEntity te = worldIn.getTileEntity(pos); - - if (te instanceof DeviceDispenser tileentitydispenser) - { - int i = tileentitydispenser.getDispenseSlot(); - - if (i < 0) - { - return false; - } - else - { - ItemStack itemstack = tileentitydispenser.getStackInSlot(i); - if(itemstack != null) { - ItemStack itemstack1 = this.dispenseStack(itemstack, worldIn, pos); - tileentitydispenser.setInventorySlotContents(i, itemstack1 != null && itemstack1.isEmpty() ? null : itemstack1); - } - } - return true; - } - return false; - } - public boolean executeFunction() { if (this.cooldown <= 0) { State state = this.getBlockState(); if(!(state.getBlock() instanceof BlockDispenser) /* || !this.decrPower() */) //TODO: energy return false; - boolean flag = this.dispense((AWorldServer)this.worldObj, this.pos); - this.cooldown = Vars.dispenserDelay; - return flag; + ItemStack stack = this.getStackInSlot(0); + if(stack != null) { + ItemStack nstack = this.dispenseStack(stack, (AWorldServer)this.worldObj, this.pos); + this.setInventorySlotContents(0, nstack != null && nstack.isEmpty() ? null : nstack); + this.cooldown = Vars.dispenserDelay; + return true; + } + return false; } else { this.cooldown--;