1
0
Fork 0

fix dispensers

This commit is contained in:
Sen 2025-08-12 17:18:51 +02:00
parent 43b097eac3
commit bed1537d9a
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
2 changed files with 15 additions and 55 deletions

View file

@ -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));
}

View file

@ -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--;