Search in sources :

Example 1 with TileInfiniteTank

use of com.cjm721.overloaded.block.tile.infinity.TileInfiniteTank in project Overloaded by CJ-MC-Mods.

the class BlockInfiniteTank method onBlockActivated.

@Override
public boolean onBlockActivated(@Nonnull World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        ItemStack heldItem = playerIn.getHeldItem(hand);
        if (heldItem.isEmpty() && hand == EnumHand.MAIN_HAND) {
            LongFluidStack storedFluid = ((TileInfiniteTank) worldIn.getTileEntity(pos)).getStorage().getFluidStack();
            if (storedFluid == null || storedFluid.fluidStack == null) {
                playerIn.sendStatusMessage(new TextComponentString("Fluid: EMPTY"), false);
            } else {
                playerIn.sendStatusMessage(new TextComponentString(String.format("Fluid: %s Amount %,d", storedFluid.fluidStack.getLocalizedName(), storedFluid.amount)), false);
            }
        } else {
            TileEntity te = worldIn.getTileEntity(pos);
            if (te != null && te instanceof TileInfiniteTank) {
                IFluidHandler handler = te.getCapability(FLUID_HANDLER_CAPABILITY, side);
                // FluidUtil.interactWithFluidHandler(playerIn.getHeldItem(hand), te.getCapability(FLUID_HANDLER_CAPABILITY, facing), playerIn);
                FluidActionResult result = FluidUtil.interactWithFluidHandler(heldItem, handler, playerIn);
                if (result.isSuccess())
                    playerIn.setHeldItem(hand, result.getResult());
            }
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) LongFluidStack(com.cjm721.overloaded.storage.LongFluidStack) TileInfiniteTank(com.cjm721.overloaded.block.tile.infinity.TileInfiniteTank) ItemStack(net.minecraft.item.ItemStack) FluidActionResult(net.minecraftforge.fluids.FluidActionResult) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) TextComponentString(net.minecraft.util.text.TextComponentString)

Aggregations

TileInfiniteTank (com.cjm721.overloaded.block.tile.infinity.TileInfiniteTank)1 LongFluidStack (com.cjm721.overloaded.storage.LongFluidStack)1 ItemStack (net.minecraft.item.ItemStack)1 TileEntity (net.minecraft.tileentity.TileEntity)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 FluidActionResult (net.minecraftforge.fluids.FluidActionResult)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1