use of net.minecraftforge.fluids.FluidActionResult in project Random-Things by lumien231.
the class BlockPitcherPlant method onBlockActivated.
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
ItemStack equipped = playerIn.getHeldItemMainhand();
if (equipped.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) {
IFluidHandler fluidHandler = equipped.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
FluidTank waterTank = new FluidTank(new FluidStack(FluidRegistry.WATER, 1000), 1000);
FluidActionResult result = FluidUtil.tryFillContainer(equipped, waterTank, 1000, playerIn, true);
if (result.success) {
if (equipped.getCount() == 1) {
playerIn.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, result.result);
} else {
if (!playerIn.capabilities.isCreativeMode) {
equipped.shrink(1);
}
playerIn.inventory.addItemStackToInventory(result.result);
}
return true;
}
} else if (equipped.getItem() == Items.GLASS_BOTTLE) {
if (!playerIn.capabilities.isCreativeMode) {
equipped.shrink(1);
}
if (!playerIn.inventory.addItemStackToInventory(PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER))) {
equipped.grow(1);
}
return true;
}
return false;
}
Aggregations