Search in sources :

Example 16 with FluidActionResult

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;
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) FluidStack(net.minecraftforge.fluids.FluidStack) ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler)

Aggregations

FluidActionResult (net.minecraftforge.fluids.FluidActionResult)16 ItemStack (net.minecraft.item.ItemStack)12 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)5 TileEntity (net.minecraft.tileentity.TileEntity)4 RayTraceResult (net.minecraft.util.math.RayTraceResult)3 FluidStack (net.minecraftforge.fluids.FluidStack)3 IBlockState (net.minecraft.block.state.IBlockState)2 ActionResult (net.minecraft.util.ActionResult)2 EnumActionResult (net.minecraft.util.EnumActionResult)2 BlockPos (net.minecraft.util.math.BlockPos)2 TileEntityNuclearWasteTank (stevekung.mods.moreplanets.planets.nibiru.tileentity.TileEntityNuclearWasteTank)2 IInventorySlots (binnie.core.machines.inventory.IInventorySlots)1 InventorySlot (binnie.core.machines.inventory.InventorySlot)1 ITankMachine (binnie.core.machines.power.ITankMachine)1 TileInfiniteWaterSource (com.cjm721.overloaded.block.tile.TileInfiniteWaterSource)1 TileInfiniteTank (com.cjm721.overloaded.block.tile.infinity.TileInfiniteTank)1 LongFluidStack (com.cjm721.overloaded.storage.LongFluidStack)1 Random (java.util.Random)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 SoundEvent (net.minecraft.util.SoundEvent)1