fix dispensers
This commit is contained in:
parent
43b097eac3
commit
bed1537d9a
2 changed files with 15 additions and 55 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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--;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue