List of usage examples for net.minecraftforge.fluids FluidUtil tryFluidTransfer
@Nonnull public static FluidStack tryFluidTransfer(IFluidHandler fluidDestination, IFluidHandler fluidSource, FluidStack resource, boolean doTransfer)
From source file:com.teambrmodding.neotech.common.blocks.storage.BlockFluidStorage.java
License:Creative Commons License
/** * Called by ItemBlocks after a block is set in the world, to allow post-place logic *//* w w w.ja v a2s . co m*/ @Override public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) { if (worldIn.getTileEntity(pos) instanceof TileBasicTank && stack.hasTagCompound() && !worldIn.isRemote) { TileBasicTank tank = (TileBasicTank) worldIn.getTileEntity(pos); FluidUtil.tryFluidTransfer(tank, stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null), Integer.MAX_VALUE, true); tank.markForUpdate(3); } }
From source file:com.teambrmodding.neotech.common.blocks.storage.ItemBlockFluidStorage.java
License:Creative Commons License
/** * Called when this item is crafted, handle NBT moving or other stuff here * * @param craftingList The list of items that were used, can have null at locations, * you should already know where important items are and read from this, be sure to check size * to find out if what kind of grid it is * <p>/* ww w . j a v a 2 s . c o m*/ * Format Full Crafting: * 0 1 2 * 3 4 5 * 6 7 8 * <p> * Format Player Crafting: * 0 1 * 2 3 * @param craftingStack The output stack, modify this to modify what the player gets on crafting * @return The stack to give the player, should probably @param craftingStack but can be something different */ @Override public ItemStack onCrafted(ItemStack[] craftingList, ItemStack craftingStack) { if (craftingList.length > 5 && craftingList[4].hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) { IFluidHandler oldTank = craftingList[4].getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); IFluidHandler newTank = craftingStack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); FluidUtil.tryFluidTransfer(newTank, oldTank, Integer.MAX_VALUE, true); } return craftingStack; }
From source file:com.teambrmodding.neotech.common.tiles.machines.generators.TileFluidGenerator.java
License:Creative Commons License
/** * This will try to take things from other inventories and put it into ours *//*from ww w.j a va2 s. c om*/ @Override public void tryInput() { for (EnumFacing dir : EnumFacing.values()) { if (canInputFromSide(dir, true)) { if (world.getTileEntity(pos.offset(dir)) != null && world.getTileEntity(pos.offset(dir)) .hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, dir.getOpposite())) { IFluidHandler otherTank = world.getTileEntity(pos.offset(dir)) .getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, dir.getOpposite()); FluidStack drained = FluidUtil.tryFluidTransfer(this, otherTank, tanks[TANK].getCapacity() - tanks[TANK].getFluidAmount(), false); if (drained != null) { FluidUtil.tryFluidTransfer(this, otherTank, tanks[TANK].getCapacity() - tanks[TANK].getFluidAmount(), false); } } } } }
From source file:com.teambrmodding.neotech.common.tiles.machines.generators.TileFurnaceGenerator.java
License:Creative Commons License
/** * This will try to take things from other inventories and put it into ours *//* w w w.j av a 2s . co m*/ @Override public void tryInput() { for (EnumFacing dir : EnumFacing.values()) { if (canInputFromSide(dir, true)) { if (world.getTileEntity(pos.offset(dir)) != null && world.getTileEntity(pos.offset(dir)) .hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, dir.getOpposite())) { IFluidHandler otherTank = world.getTileEntity(pos.offset(dir)) .getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, dir.getOpposite()); FluidStack drained = FluidUtil.tryFluidTransfer(this, otherTank, tanks[TANK].getCapacity() - tanks[TANK].getFluidAmount(), false); if (drained != null) { FluidUtil.tryFluidTransfer(this, otherTank, tanks[TANK].getCapacity() - tanks[TANK].getFluidAmount(), false); return; } } else if (world.getTileEntity(pos.offset(dir)) != null && world.getTileEntity(pos.offset(dir)) .hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, dir.getOpposite())) { IItemHandler otherInv = world.getTileEntity(pos.offset(dir)) .getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, dir.getOpposite()); if (InventoryUtils.moveItemInto(otherInv, -1, this, INPUT_SLOT, 64, dir, true, true, false)) return; } } } }