Corrected issues with filling fluid blocks
This commit is contained in:
parent
d620e24ba0
commit
b5fd22ff24
1 changed files with 60 additions and 41 deletions
|
@ -299,44 +299,63 @@ public class FluidHelper
|
||||||
/** Does all the work needed to fill or drain an item of fluid when a player clicks on the block. */
|
/** Does all the work needed to fill or drain an item of fluid when a player clicks on the block. */
|
||||||
public static boolean playerActivatedFluidItem(World world, int x, int y, int z, EntityPlayer entityplayer, int side)
|
public static boolean playerActivatedFluidItem(World world, int x, int y, int z, EntityPlayer entityplayer, int side)
|
||||||
{
|
{
|
||||||
if (world.isRemote)
|
ItemStack current = entityplayer.inventory.getCurrentItem();
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else if (entityplayer != null && !entityplayer.isSneaking())
|
|
||||||
{
|
|
||||||
ItemStack current = entityplayer.inventory.getCurrentItem().copy();
|
|
||||||
|
|
||||||
if (current != null && world.getBlockTileEntity(x, y, z) instanceof IFluidHandler)
|
if (current != null && world.getBlockTileEntity(x, y, z) instanceof IFluidHandler)
|
||||||
{
|
{
|
||||||
IFluidHandler tank = (IFluidHandler) world.getBlockTileEntity(x, y, z);
|
|
||||||
ItemStack reStack = FluidHelper.drainItem(current, tank, ForgeDirection.getOrientation(side));
|
|
||||||
boolean stackChanged = false;
|
|
||||||
if (reStack != null && reStack.isItemEqual(current))
|
|
||||||
{
|
|
||||||
reStack = FluidHelper.fillItem(current, tank, ForgeDirection.getOrientation(side));
|
|
||||||
}
|
|
||||||
stackChanged = reStack == null || !reStack.isItemEqual(current);
|
|
||||||
if (!entityplayer.capabilities.isCreativeMode && stackChanged)
|
|
||||||
{
|
|
||||||
if (current.stackSize > 1)
|
|
||||||
{
|
|
||||||
if (reStack != null && !entityplayer.inventory.addItemStackToInventory(reStack))
|
|
||||||
{
|
|
||||||
ItemWorldHelper.dropItemStack(world, new Vector3(x, y, z), reStack, true);
|
|
||||||
}
|
|
||||||
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, AutoCraftingManager.consumeItem(current, 1));
|
|
||||||
|
|
||||||
|
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
|
||||||
|
|
||||||
|
IFluidHandler tank = (IFluidHandler) world.getBlockTileEntity(x, y, z);
|
||||||
|
|
||||||
|
if (liquid != null)
|
||||||
|
{
|
||||||
|
int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
|
||||||
|
|
||||||
|
if (qty != 0 && !entityplayer.capabilities.isCreativeMode)
|
||||||
|
{
|
||||||
|
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, AutoCraftingManager.consumeItem(current, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, reStack);
|
|
||||||
|
FluidStack available = tank.drain(ForgeDirection.getOrientation(side), Integer.MAX_VALUE, false);
|
||||||
|
if (available != null)
|
||||||
|
{
|
||||||
|
ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current);
|
||||||
|
|
||||||
|
liquid = FluidContainerRegistry.getFluidForFilledItem(filled);
|
||||||
|
|
||||||
|
if (liquid != null)
|
||||||
|
{
|
||||||
|
if (!entityplayer.capabilities.isCreativeMode)
|
||||||
|
{
|
||||||
|
if (current.stackSize > 1)
|
||||||
|
{
|
||||||
|
if (!entityplayer.inventory.addItemStackToInventory(filled))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
entityplayer.inventoryContainer.detectAndSendChanges();
|
else
|
||||||
}
|
{
|
||||||
return stackChanged;
|
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, AutoCraftingManager.consumeItem(current, 1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, AutoCraftingManager.consumeItem(current, 1));
|
||||||
|
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filled);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue