Java Code Examples for net.minecraftforge.fluids.FluidUtil#interactWithFluidHandler()

The following examples show how to use net.minecraftforge.fluids.FluidUtil#interactWithFluidHandler() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockTFBattery.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!worldIn.isRemote) {
        ItemStack stack = playerIn.getHeldItem(hand);
        TileEntity tileentity = worldIn.getTileEntity(pos);
        if (tileentity instanceof TileEntityTofuBattery) {
            IFluidHandlerItem handler = FluidUtil.getFluidHandler(ItemHandlerHelper.copyStackWithSize(stack, 1));
            if (handler != null) {
                FluidUtil.interactWithFluidHandler(playerIn, hand, tileentity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing));
                return true;
            } else {
                playerIn.openGui(TofuMain.instance, TofuGuiHandler.ID_BATTERY_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ());
            }
        }
    }
    return true;
}
 
Example 2
Source File: BlockTFStorage.java    From TofuCraftReload with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (worldIn.isRemote) {

        return true;

    } else {
        ItemStack stack = playerIn.getHeldItem(hand);
        TileEntity tileentity = worldIn.getTileEntity(pos);
        if (tileentity instanceof TileEntityTFStorage) {
            IFluidHandlerItem handler = FluidUtil.getFluidHandler(ItemHandlerHelper.copyStackWithSize(stack, 1));

            if (handler != null) {
                FluidUtil.interactWithFluidHandler(playerIn, hand, tileentity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side));

                return true;
            } else {
                playerIn.openGui(TofuMain.instance, TofuGuiHandler.ID_STORAGE_MACHINE_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ());
            }
        }
        return true;
    }
}
 
Example 3
Source File: BlockBarrelDistillation.java    From Sakura_mod with MIT License 6 votes vote down vote up
@Override
  public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
      if (world.isRemote) {
          return true;
      }
ItemStack stack = player.getHeldItem(hand);
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityDistillation) {
    IFluidHandlerItem handler = FluidUtil.getFluidHandler(ItemHandlerHelper.copyStackWithSize(stack, 1));
    if (handler != null) {
        FluidUtil.interactWithFluidHandler(player, hand, tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side));
        return true;
    }
    player.openGui(SakuraMain.instance, SakuraGuiHandler.ID_DISTILLATION, world, pos.getX(), pos.getY(), pos.getZ());
    return true;
}
return true;
  }
 
Example 4
Source File: BlockBarrel.java    From Sakura_mod with MIT License 6 votes vote down vote up
@Override
  public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
      if (world.isRemote) {
          return true;
      }
ItemStack stack = player.getHeldItem(hand);
TileEntity tile = world.getTileEntity(pos);
if (tile instanceof TileEntityBarrel) {
    IFluidHandlerItem handler = FluidUtil.getFluidHandler(ItemHandlerHelper.copyStackWithSize(stack, 1));
    if (handler != null) {
        FluidUtil.interactWithFluidHandler(player, hand, tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side));
        return true;
    }
    player.openGui(SakuraMain.instance, SakuraGuiHandler.ID_BARREL, world, pos.getX(), pos.getY(), pos.getZ());
    return true;
}
return true;
  }
 
Example 5
Source File: BlockMixin.java    From customstuff4 with GNU General Public License v3.0 6 votes vote down vote up
private boolean interactWithFluidItem(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing)
{
    if (getContent().canInteractWithFluidItem.get(getSubtype(state)).orElse(true))
    {
        TileEntity tile = worldIn.getTileEntity(pos);
        if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing))
        {
            if (worldIn.isRemote)
            {
                return true;
            }

            if (FluidUtil.interactWithFluidHandler(playerIn, hand, worldIn, pos, facing))
            {
                playerIn.inventoryContainer.detectAndSendChanges();
                return true;
            }
        }
    }
    return false;
}
 
Example 6
Source File: TileCrucible.java    From ExNihiloAdscensio with MIT License 6 votes vote down vote up
public boolean onBlockActivated(ItemStack stack, EntityPlayer player) {
	if (stack == null)
		return false;
	
	//Bucketing out the fluid.
	if (stack != null && stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) {
		boolean result = FluidUtil.interactWithFluidHandler(stack, tank, player);
		if (result) {
			PacketHandler.sendNBTUpdate(this);
		}
		return true;
	}
	
	//Adding a meltable.
	ItemStack addStack = stack.copy(); addStack.stackSize = 1;
	ItemStack insertStack = itemHandler.insertItem(0, addStack, true);
	if (!ItemStack.areItemStacksEqual(addStack, insertStack)) {
		itemHandler.insertItem(0, addStack, false);
		stack.stackSize--;
		PacketHandler.sendNBTUpdate(this);
		return true;
	}
	return true;
}
 
Example 7
Source File: BlockCampfirePot.java    From Sakura_mod with MIT License 5 votes vote down vote up
@Override
  public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
      if (worldIn.isRemote) {
          return true;
      }
ItemStack stack = playerIn.getHeldItem(hand);
TileEntity tile = worldIn.getTileEntity(pos);
if (hand == EnumHand.MAIN_HAND) {
    if (tile instanceof TileEntityCampfirePot) {
        TileEntityCampfirePot tileEntityCampfire = (TileEntityCampfirePot) tile;
        IFluidHandlerItem handler = FluidUtil.getFluidHandler(ItemHandlerHelper.copyStackWithSize(stack, 1));
        if (handler != null) {
            FluidUtil.interactWithFluidHandler(playerIn, hand, tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing));
            return true;
        }
        
        if (WorldUtil.isItemFuel(stack)) {
            tileEntityCampfire.setBurningTime(tileEntityCampfire.getBurningTime() + TileEntityFurnace.getItemBurnTime(stack));
            setState(true, worldIn, pos);
			if(stack.getItem().hasContainerItem(stack)) stack = stack.getItem().getContainerItem(stack);
				else stack.shrink(1);
            return true;
        }

        if (stack.getItem() == Items.FLINT_AND_STEEL) {
            tileEntityCampfire.setBurningTime(tileEntityCampfire.getBurningTime() + 10000);
            setState(true, worldIn, pos);
            stack.damageItem(1, playerIn);
            return true;
        }

        playerIn.openGui(SakuraMain.instance, SakuraGuiHandler.ID_CAMPFIREPOT, worldIn, pos.getX(), pos.getY(), pos.getZ());
        return true;
    }
}

return true;
  }
 
Example 8
Source File: BlockTank.java    From YouTubeModdingTutorial with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        FluidUtil.interactWithFluidHandler(player, hand, world, pos, side);
    }
    return true;
}
 
Example 9
Source File: TileEnderTank.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public boolean activate(PlayerEntity player, int subHit, Hand hand) {
    if (subHit == 4) {
        pressure_state.invert();
        return true;
    }
    return FluidUtil.interactWithFluidHandler(player, hand, getStorage());
}
 
Example 10
Source File: BlockWaterTank.java    From AgriCraft with MIT License 5 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    // Attempt to interact with fluid stuff.
    FluidUtil.interactWithFluidHandler(player, hand, world, pos, side);
    // Figure out if this is a fluid thing or not.
    final ItemStack stack = player.getHeldItem(hand);
    final FluidStack fluid = FluidUtil.getFluidContained(stack);
    // Return depending if holding a fluid stack to prevent accidental water placement.
    return (fluid != null);
}
 
Example 11
Source File: MetaTileEntityTank.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean onRightClick(EntityPlayer playerIn, EnumHand hand, EnumFacing facing, CuboidRayTraceResult hitResult) {
    return getWorld().isRemote || FluidUtil.interactWithFluidHandler(playerIn, hand, fluidInventory);
}
 
Example 12
Source File: BlockWaterPad.java    From AgriCraft with MIT License 4 votes vote down vote up
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    return FluidUtil.interactWithFluidHandler(player, hand, new FluidHandlerBlockWrapper(this, world, pos));
}