use of com.infinityraider.agricraft.tiles.irrigation.TileEntityTank in project AgriCraft by AgriCraft.
the class BlockWaterTank method onBlockActivated.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing side, float hitX, float hitY, float hitZ) {
boolean update = false;
if (world.isRemote) {
return true;
}
TileEntityTank tank = WorldHelper.getTile(world, pos, TileEntityTank.class).orElse(null);
if (stack != null && stack.getItem() != null && tank != null) {
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack);
// put water from liquid container in tank
if (liquid != null && liquid.getFluid() == FluidRegistry.WATER) {
int quantity = tank.fill(null, liquid, false);
if (quantity == liquid.amount) {
tank.fill(null, liquid, true);
update = true;
// change the inventory if player is not in creative mode
if (!player.capabilities.isCreativeMode) {
if (stack.stackSize == 1) {
if (stack.getItem().hasContainerItem(stack)) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, stack.getItem().getContainerItem(stack));
} else {
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
} else {
stack.splitStack(1);
player.inventory.setInventorySlotContents(player.inventory.currentItem, stack);
}
}
}
} else // put water from tank in empty liquid container
{
FluidStack tankContents = tank.getTankInfo(null)[0].fluid;
if (tankContents != null) {
ItemStack filledContainer = FluidContainerRegistry.fillFluidContainer(tankContents, stack);
FluidStack filledLiquid = FluidContainerRegistry.getFluidForFilledItem(filledContainer);
if (filledLiquid != null) {
// change the inventory if the player is not in creative mode
if (!player.capabilities.isCreativeMode) {
if (stack.stackSize == 1) {
if (stack.getItem().hasContainerItem(stack)) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, stack.getItem().getContainerItem(stack));
} else {
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
}
player.inventory.setInventorySlotContents(player.inventory.currentItem, filledContainer);
} else if (!player.inventory.addItemStackToInventory(filledContainer)) {
return false;
} else {
stack.splitStack(1);
player.inventory.setInventorySlotContents(player.inventory.currentItem, stack);
player.inventory.addItemStackToInventory(filledContainer);
player.inventory.markDirty();
}
}
tank.drain(null, filledLiquid.amount, true);
update = true;
}
}
}
}
return update;
}
use of com.infinityraider.agricraft.tiles.irrigation.TileEntityTank in project AgriCraft by AgriCraft.
the class BlockWaterTank method getActualState.
@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
final Optional<TileEntityTank> tile = WorldHelper.getTile(world, pos, TileEntityTank.class);
if (!tile.isPresent()) {
return state;
}
tile.get().checkConnections();
final IrrigationConnection sides = new IrrigationConnection();
for (EnumFacing facing : EnumFacing.VALUES) {
sides.set(facing, tile.get().getConnectionType(facing));
}
return sides.write(state);
}
Aggregations