private static boolean doFluidInteraction(TileEntity te, EnumFacing face, EntityPlayer player, EnumHand hand, boolean isInserting) { ItemStack stack = player.getHeldItem(hand); IFluidHandlerItem stackHandler = FluidUtil.getFluidHandler(stack); if (stackHandler != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face)) { int capacity = stackHandler.getTankProperties()[0].getCapacity(); IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face); PlayerInvWrapper invWrapper = new PlayerInvWrapper(player.inventory); FluidActionResult result = isInserting ? FluidUtil.tryEmptyContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player) : FluidUtil.tryFillContainerAndStow(player.getHeldItem(hand), handler, invWrapper, capacity, player); if (result.isSuccess()) { player.setHeldItem(hand, result.getResult()); return true; } } return false; }
@SideOnly(Side.CLIENT) @Override public void getSubItems(@Nullable CreativeTabs tab, @Nonnull NonNullList<ItemStack> subItems) { if (isInCreativeTab(tab)) { subItems.add(new ItemStack(this)); for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) { if (!fluid.getName().equals("milk")) { // add all fluids that the bucket can be filled with FluidStack fs = new FluidStack(fluid, content.capacity); ItemStack stack = new ItemStack(this); IFluidHandlerItem fluidHandler = new FluidHandlerItemStack(stack, content.capacity); if (fluidHandler.fill(fs, true) == fs.amount) { ItemStack filled = fluidHandler.getContainer(); subItems.add(filled); } } } } }
private boolean isValidInContainer(ItemStack stack) { if (!ItemStackUtil.isEmpty(stack)) { if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { IFluidHandlerItem handler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); if (handler != null) { IFluidTankProperties[] tanks = handler.getTankProperties(); if ((tanks != null) && (tanks.length > 0)) { for(IFluidTankProperties tank: tanks) { if (tank.canDrain()) { FluidStack content = tank.getContents(); if ((content != null) && (content.amount > 0) && (content.getFluid() == FluidsRegistry.liquidXP)) { return true; } } } } } } } return false; }
private boolean isValidOutContainer(ItemStack stack) { if (!ItemStackUtil.isEmpty(stack)) { Item item = stack.getItem(); if ((item == Items.GLASS_BOTTLE) || (item == Items.BUCKET)) { return true; } if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { IFluidHandlerItem handler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); if (handler != null) { IFluidTankProperties[] tanks = handler.getTankProperties(); if ((tanks != null) && (tanks.length > 0)) { for(IFluidTankProperties tank: tanks) { if (tank.canFill()) { FluidStack content = tank.getContents(); if ((content == null) || ((content.amount < tank.getCapacity()) && (content.getFluid() == FluidsRegistry.liquidXP))) { return true; } } } } } } } return false; }
/** * Drains a filled container and places the fluid. * * RETURN new item stack that has been drained after placing in world if it works null otherwise */ public static ItemStack dumpContainer(World world, BlockPos pos, ItemStack stackIn) { // BlockSourceImpl blocksourceimpl = new BlockSourceImpl(world, pos); ItemStack dispensedStack = stackIn.copy(); dispensedStack.setCount(1); IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(dispensedStack); if (fluidHandler == null) { return null; } FluidStack fluidStack = fluidHandler.drain(Fluid.BUCKET_VOLUME, false); if (fluidStack != null && fluidStack.amount >= Fluid.BUCKET_VOLUME) { // FluidActionResult placeResult = FluidUtil.tryPlaceFluid(null, world, pos, dispensedStack, fluidStack); if (FluidUtil.tryPlaceFluid(null, world, pos, dispensedStack, fluidStack).isSuccess()) { //http://www.minecraftforge.net/forum/topic/56265-1112-fluidhandler-capability-on-buckets/ fluidHandler.drain(Fluid.BUCKET_VOLUME, true); ItemStack returnMe = fluidHandler.getContainer(); // stackIn.deserializeNBT(returnMe.serializeNBT()); return returnMe; } } return null; }
@Override public void update() { ItemStack stack = inventory.get(0); if(!stack.isEmpty() && stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.DOWN)) { IFluidHandlerItem fh = FluidUtil.getFluidHandler(stack); FluidStack fluid = FluidUtil.getFluidContained(stack); if(fh != null && fluid != null) { int amountFilled = fluidTanks[0].fillInternal(fluid, false); FluidStack amountDrained = fh.drain(amountFilled, true); if(amountDrained != null && amountDrained.amount > 0) { fluidTanks[0].fillInternal(amountDrained, true); inventory.set(0, fh.getContainer()); } } } super.update(); }
public static Predicate<ItemStack> getFluidPredicate(Fluid fluid) { return new Predicate<ItemStack>() { @Override public boolean test(ItemStack itemStack) { IFluidHandlerItem handler = FluidUtil.getFluidHandler(itemStack); if (handler == null) { return false; } for (IFluidTankProperties properties : handler.getTankProperties()) { FluidStack stack = properties.getContents(); if (stack != null && stack.getFluid() == fluid) { return true; } } return false; } }; }
public ItemStack getFilled(CaskLiquid liquid) { ItemStack filled = new ItemStack(this); IFluidHandlerItem tank = filled.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY,null); if(tank != null) tank.fill(new FluidStack(liquid.fluid,capacity),true); return filled; }
public Fluid getRecipeFluid() { if (tank.getFluid() != null) { return tank.getFluid().getFluid(); } for (ItemStack stack : crafting.getFilter()) { if (stack.isEmpty()) continue; if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { IFluidHandlerItem fluidHandlerItem = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); return fluidHandlerItem.drain(Integer.MAX_VALUE, false).getFluid(); } } return null; }
public boolean hasOnlyOneFluid() { Fluid tankFluid = tank.getFluid() != null ? tank.getFluid().getFluid() : null; List<Fluid> fluids = new ArrayList<>(); for (ItemStack stack : crafting.getFilter()) { if (stack.isEmpty()) continue; if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { IFluidHandlerItem fluidHandlerItem = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); FluidStack fluid = fluidHandlerItem.drain(Integer.MAX_VALUE, false); if (fluid != null && !fluids.contains(fluid.getFluid())) fluids.add(fluid.getFluid()); } } if (tankFluid != null) fluids.remove(tankFluid); return fluids.size() <= 1; }
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { if (world.isRemote) return true; TileEntityBarrel barrel = (TileEntityBarrel) world.getTileEntity(pos); world.notifyBlockUpdate(pos, state, state, 3); ItemStack stack = player.getHeldItem(hand); if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { IFluidHandlerItem itemHandler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); IFluidHandler barrelHandler = barrel.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); FluidStack fluidInItem = itemHandler.drain(Fluid.BUCKET_VOLUME, false); FluidStack fluidInBarrel = barrelHandler.drain(Fluid.BUCKET_VOLUME, false); if ((fluidInBarrel != null && fluidInBarrel.amount > 0) && (fluidInItem == null || fluidInItem.amount == 0 || (fluidInItem.isFluidEqual(fluidInBarrel) && fluidInItem.amount < Fluid.BUCKET_VOLUME))) { itemHandler.fill(barrelHandler.drain(Fluid.BUCKET_VOLUME, true), true); player.setHeldItem(hand, itemHandler.getContainer()); } else if (fluidInItem != null && fluidInItem.amount > 0 && fluidInItem.getFluid() != null && (fluidInBarrel == null || fluidInBarrel.amount == 0 || (fluidInBarrel.amount < Fluid.BUCKET_VOLUME && fluidInBarrel.isFluidEqual(fluidInItem)))) { FluidStack fsin = itemHandler.drain(Fluid.BUCKET_VOLUME, true); if (fsin != null && fsin.amount > 0 && fsin.getFluid() != null) { barrelHandler.fill(fsin, true); player.setHeldItem(hand, itemHandler.getContainer()); player.inventory.markDirty(); } } return true; } player.openGui(Bewitchment.instance, LibGui.BARREL.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); return true; }
public void tryHydrateBlock(EntityPlayer player, int tier, BlockPos pos, World w, IBlockState state, IFluidHandlerItem cap, ItemStack is) { while ((state.getMaterial() == Material.PLANTS || w.isAirBlock(pos)) && pos.getY() > 0) { pos = pos.down(); state = w.getBlockState(pos); } if (state.getBlock() instanceof IAcceptsWaterCan) { ((IAcceptsWaterCan)state.getBlock()).acceptWatering(player, w, pos, state, cap, is, tier); } w.spawnParticle(EnumParticleTypes.WATER_SPLASH, pos.getX() + w.rand.nextFloat(), pos.getY() + 1, pos.getZ() + w.rand.nextFloat(), 0, 0, 0); }
public void tryFillWithWater(EntityLivingBase player, int tier, BlockPos pos, World w, IBlockState blockHit, Fluid f, IFluidHandlerItem cap) { if (player.ticksExisted % (60 / (tier + 1)) == 0) { if (blockHit.getBlock() instanceof BlockFluidFinite) { BlockFluidFinite fluidBlock = (BlockFluidFinite) blockHit.getBlock(); FluidStack toFill = new FluidStack(f, 100); if (cap.fill(toFill, false) == 100) { int quantaCurrent = fluidBlock.getQuantaValue(w, pos); if (quantaCurrent == 1) { w.setBlockToAir(pos); } else { w.setBlockState(pos, blockHit.withProperty(BlockFluidBase.LEVEL, quantaCurrent - 2), 3); } cap.fill(toFill, true); } } else { cap.fill(((IFluidBlock)blockHit.getBlock()).drain(w, pos, true), true); } } }
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer entityplayer, EnumHand hand, EnumFacing side, float par7, float par8, float par9) { ItemStack current = entityplayer.getHeldItem(hand); TileEntity tile = world.getTileEntity(pos); if (tile instanceof TileEntityTank) { TileEntityTank tank = (TileEntityTank) tile; if (ItemStackTools.isValid(current)) { if(ToolUtil.isToolEquipped(entityplayer, hand)){ return ToolUtil.breakBlockWithTool(this, world, pos, entityplayer, hand); } IFluidHandlerItem containerFluidHandler = FluidUtil.getFluidHandler(current); if (containerFluidHandler != null) { if(FluidUtil.interactWithFluidHandler(entityplayer, hand, world, pos, side)){ return true; } } } if(!world.isRemote){ if(tank.tank !=null){ FluidStack fluid = tank.tank.getFluid(); if(fluid == null){ ChatUtil.sendNoSpam(entityplayer, "Fluid: (Empty) 0 mB / "+tank.tank.getCapacity()+" mB"); } else ChatUtil.sendNoSpam(entityplayer, "Fluid: ("+fluid.getLocalizedName()+") "+fluid.amount+" mB / "+tank.tank.getCapacity()+" mB"); } } return true; } return false; }
@Override public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) { NonNullList<ItemStack> remains = ForgeHooks.defaultRecipeGetRemainingItems(inv); for (int i = 0; i < height * width; i++) { ItemStack stack = inv.getStackInSlot(i); NonNullList<Ingredient> matchedIngredients = this.input; if (matchedIngredients.get(i) instanceof IngredientFluidStack) { if (!stack.isEmpty()) { ItemStack copy = stack.copy(); copy.setCount(1); remains.set(i, copy); } IFluidHandlerItem handler = FluidUtil.getFluidHandler(remains.get(i)); if (handler != null) { FluidStack fluid = ((IngredientFluidStack) matchedIngredients.get(i)).getFluid(); handler.drain(fluid.amount, true); remains.set(i, handler.getContainer()); } } } return remains; }
public static final boolean drainPlayerHand(final IFluidHandler fluidHandler, final EntityPlayer player) { final ItemStack input = player.getHeldItemMainhand(); ItemStack output; final IFluidHandlerItem inputFluidHandler = FluidUtils.getFluidHandler(input); if (fluidHandler != null && inputFluidHandler != null && inputFluidHandler.getTankProperties()[0].getContents() != null) { final int simulated = fluidHandler.fill(inputFluidHandler.drain(Integer.MAX_VALUE, false), false); if (simulated > 0) { fluidHandler.fill(inputFluidHandler.drain(simulated, true), true); if ((inputFluidHandler.getTankProperties()[0].getContents() == null || inputFluidHandler.getTankProperties()[0].getContents().amount == 0) && !player.isCreative()) { output = inputFluidHandler.getContainer(); if (input.getCount() == 1) player.inventory.setInventorySlotContents(player.inventory.currentItem, output); else { player.inventory.decrStackSize(player.inventory.currentItem, 1); if (!player.inventory.addItemStackToInventory(output)) player.entityDropItem(output, 0); } } return true; } } return false; }
public static final boolean fillPlayerHand(final IFluidHandler fluidHandler, final EntityPlayer player) { final ItemStack input = player.getHeldItemMainhand(); ItemStack output; final IFluidHandlerItem inputFluidHandler = FluidUtils.getFluidHandler(input); if (fluidHandler != null && inputFluidHandler != null && fluidHandler.getTankProperties()[0].getContents() != null) { final int simulated = inputFluidHandler.fill(fluidHandler.drain(Integer.MAX_VALUE, false), false); if (simulated > 0) { inputFluidHandler.fill(fluidHandler.drain(simulated, true), true); output = inputFluidHandler.getContainer(); if (input.getCount() == 1) { if (!player.isCreative()) player.inventory.setInventorySlotContents(player.inventory.currentItem, output); else player.inventory.addItemStackToInventory(output); } else { if (!player.isCreative()) player.inventory.decrStackSize(player.inventory.currentItem, 1); if (!player.inventory.addItemStackToInventory(output)) player.entityDropItem(output, 0); } return true; } } return false; }
@Nullable public static final IFluidHandlerItem getFluidHandler(final ItemStack container) { final ItemStack copy = container.copy(); copy.setCount(1); return FluidUtil.getFluidHandler(copy); }
@Nonnull public static ItemStack getFilledContainer(final Fluid fluid, final ItemStack empty) { if (fluid == null || empty == ItemStack.EMPTY) return ItemStack.EMPTY; final IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(empty); fluidHandler.fill(new FluidStack(fluid, fluidHandler.getTankProperties()[0].getCapacity()), true); return empty; }
@Override protected boolean acceptsFluidItem(ItemStack stack) { if (stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) { IFluidHandlerItem handler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); if (handler != null) { if (1 == handler.fill(new FluidStack(FluidsRegistry.sewage, 1), false)) { return true; } } } return (stack.getItem() == Items.BUCKET); }
@Override public void getSubItems(@Nullable CreativeTabs tab, @Nonnull NonNullList<ItemStack> subItems) { subItems.add(new ItemStack(this)); for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) { FluidStack fluidStack = new FluidStack(fluid, JAR_VOLUME); IFluidHandlerItem fluidHandler = new FluidHandlerItemStackAdvanced(new ItemStack(this, 1, 1), JAR_VOLUME, MAX_TEMPERATURE); if (fluidHandler.fill(fluidStack, true) == fluidStack.amount) { subItems.add(fluidHandler.getContainer()); } } }
public static ItemStack drainOneBucket(ItemStack d) { IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(d); if (fluidHandler == null) { return d; } //its empty, ok no problem fluidHandler.drain(Fluid.BUCKET_VOLUME, true); return fluidHandler.getContainer(); }
public void tryFillTankFromItems() { ItemStack maybeBucket = this.getStackInSlot(SLOT_INFLUID); FluidStack f = FluidUtil.getFluidContained(maybeBucket); IFluidHandlerItem bucketHandler = FluidUtil.getFluidHandler(maybeBucket); if (f != null && bucketHandler != null && f.getFluid().equals(FluidRegistry.WATER)) { //https://github.com/BluSunrize/ImmersiveEngineering/blob/fc022675bb550318cbadc879b3f28dde511e29c3/src/main/java/blusunrize/immersiveengineering/common/blocks/wooden/TileEntityWoodenBarrel.java FluidActionResult r = FluidUtil.tryEmptyContainer(maybeBucket, tank, Fluid.BUCKET_VOLUME, null, true); //in the case of a full bucket, it becomes empty. //also supports any other fluid holding item, simply draining that fixed amount each round if (r.success) { this.setInventorySlotContents(SLOT_INFLUID, r.result); } } }
protected FluidActionResult tryEmptyItem(EntityPlayer player, @Nonnull ItemStack container) { // not using FluidUtils.tryEmptyContainer, since it limits stack size to 1 final IFluidHandlerItem containerFluidHandler = FluidUtil.getFluidHandler(container); if (containerFluidHandler != null) { FluidStack transfer = FluidUtil.tryFluidTransfer(tankCapabilityWrapper, containerFluidHandler, Fluid.BUCKET_VOLUME, true); if (transfer != null) { SoundEvent soundevent = transfer.getFluid().getEmptySound(transfer); player.playSound(soundevent, 1f, 1f); return new FluidActionResult(containerFluidHandler.getContainer()); } } return FluidActionResult.FAILURE; }
@SubscribeEvent public void onBucketFill(FillBucketEvent evt) { if (evt.getResult() != Result.DEFAULT) return; if (evt.getEmptyBucket().getItem() != EMPTY_BUCKET) return; final RayTraceResult target = evt.getTarget(); if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) return; final TileEntity te = evt.getWorld().getTileEntity(target.getBlockPos()); if (te == null) return; if (!canFill(evt.getWorld(), target.getBlockPos(), te)) { return; } if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit)) { final IFluidHandler source = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit); final FluidStack fluidInContainer = source.drain(Fluid.BUCKET_VOLUME, false); if (fluidInContainer != null) { final ItemStack filledBucket = getFilledBucket(fluidInContainer); if (!filledBucket.isEmpty()) { final IFluidHandlerItem container = FluidUtil.getFluidHandler(filledBucket); if (container != null) { final FluidStack fluidInBucket = container.drain(Integer.MAX_VALUE, false); if (fluidInBucket != null && fluidInBucket.isFluidStackIdentical(source.drain(fluidInBucket, false))) { source.drain(fluidInBucket, true); evt.setFilledBucket(filledBucket.copy()); evt.setResult(Result.ALLOW); } } } } } }
private boolean isStackCurrentFluid(Fluid fluid, ItemStack stack) { if (!stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null)) return false; IFluidHandlerItem fluidHandlerItem = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); return fluidHandlerItem != null && fluidHandlerItem.drain(Integer.MAX_VALUE, false) != null && fluidHandlerItem.drain(Integer.MAX_VALUE, false).getFluid().equals(fluid); }
@SuppressWarnings("ConstantConditions") @Override public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) { if (!(player instanceof EntityPlayer)) { return; } int tier = this.getStats(stack).getTier(); RayTraceResult rtr = this.rayTrace(player.world, (EntityPlayer) player, true); if (rtr != null && rtr.typeOfHit == Type.BLOCK) { BlockPos pos = rtr.getBlockPos(); World w = player.getEntityWorld(); IBlockState blockHit = w.getBlockState(pos); Fluid f = FluidRegistry.lookupFluidForBlock(blockHit.getBlock()); if (f == null && blockHit.getBlock() instanceof IFluidBlock) { f = ((IFluidBlock)blockHit.getBlock()).getFluid(); } IFluidHandlerItem cap = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); if (FluidRegistry.WATER.equals(f)) { if (!player.world.isRemote) { this.tryFillWithWater(player, tier, pos, w, blockHit, f, cap); } } else { if (f == null) { tryWaterBasedOnTier(player, tier, pos, w, blockHit, cap, stack); } } } super.onUsingTick(stack, player, count); }
@Override public void addInformation(ItemStack stack, World world, List<String> tooltip, ITooltipFlag advanced) { super.addInformation(stack, world, tooltip, advanced); IFluidHandlerItem cap = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null); if (cap != null) { IFluidTankProperties[] props = cap.getTankProperties(); if (props != null && props.length > 0) { FluidStack fStack = props[0].getContents(); if (fStack == null || fStack.amount == 0) { tooltip.add(I18n.format("exp.txt.item.desc.water.none")); } else { EntityPlayer playerIn = VoidApi.proxy.getClientPlayer(); if (playerIn != null) { if (IExPPlayer.of(playerIn).getProgressionStage().ordinal() < EnumPlayerProgression.IRON_AGE.ordinal()) { float percentage = (float) fStack.amount / props[0].getCapacity(); if (percentage <= 0.25F) { tooltip.add(I18n.format("exp.txt.item.desc.water.leq25")); } else { if (percentage <= 0.5F) { tooltip.add(I18n.format("exp.txt.item.desc.water.leq50")); } else { if (percentage <= 0.75F) { tooltip.add(I18n.format("exp.txt.item.desc.water.leq75")); } else { tooltip.add(I18n.format("exp.txt.item.desc.water.100")); } } } } else { tooltip.add(I18n.format("exp.txt.item.desc.water", fStack.amount)); } } } } } }
public static final boolean drainContainers(final IFluidHandler fluidHandler, final IInventory inv, final int inputSlot, final int outputSlot) { final ItemStack input = inv.getStackInSlot(inputSlot); final ItemStack output = inv.getStackInSlot(outputSlot); final IFluidHandlerItem inputFluidHandler = FluidUtils.getFluidHandler(input); if (inputFluidHandler != null) { /* * Making a simulation to check if the fluid can be drained into the * fluidhandler. */ if (FluidUtil.tryFluidTransfer(fluidHandler, inputFluidHandler, inputFluidHandler.getTankProperties()[0].getCapacity(), false) != null) { // Changes are really applied and the fluid is drained. final FluidStack drained = FluidUtil.tryFluidTransfer(fluidHandler, inputFluidHandler, inputFluidHandler.getTankProperties()[0].getCapacity(), true); /* * If the drained container doesn't disappear we need to update * the inventory accordingly. */ if (drained != null && inputFluidHandler.getContainer() != ItemStack.EMPTY) if (output == ItemStack.EMPTY) { inv.setInventorySlotContents(outputSlot, inputFluidHandler.getContainer()); inv.decrStackSize(inputSlot, 1); } else { /* * When output is not EMPTY, it is needed to check if * the two stacks can be merged together, there was no * simple way to make that check before. */ if (ItemUtils.deepEquals(output, inputFluidHandler.getContainer())) { inv.getStackInSlot(outputSlot).setCount(inv.getStackInSlot(outputSlot).getCount() + 1); inv.decrStackSize(inputSlot, 1); } else { /* * Due to the late check of stacks merge we need to * reverse any changes made to the FluidHandlers * when the merge fail. */ FluidUtil.tryFluidTransfer(inputFluidHandler, fluidHandler, drained.amount, true); return false; } } return true; } } return false; }
public static boolean fillContainers(final IFluidHandler fluidHandler, final IInventory inv, final int inputSlot, final int outputSlot, final Fluid fluidToFill) { final ItemStack input = inv.getStackInSlot(inputSlot); final ItemStack output = inv.getStackInSlot(outputSlot); if (input != ItemStack.EMPTY) { final IFluidHandlerItem inputFluidHandler = FluidUtils.getFluidHandler(input); /* * The copy is needed to get the filled container without altering * the original ItemStack. */ final ItemStack containerCopy = input.copy(); containerCopy.setCount(1); /* * It's necessary to check before any alterations that the resulting * ItemStack can be placed into the outputSlot. */ if (inputFluidHandler != null && (output == ItemStack.EMPTY || output.getCount() < output.getMaxStackSize() && ItemUtils.deepEquals(FluidUtils.getFilledContainer(fluidToFill, containerCopy), output))) { /* * Making a simulation to check if the fluid can be transfered * into the fluidhandler. */ if (FluidUtil.tryFluidTransfer(inputFluidHandler, fluidHandler, inputFluidHandler.getTankProperties()[0].getCapacity(), false) != null) { // Changes are really applied and the fluid is transfered. FluidUtil.tryFluidTransfer(inputFluidHandler, fluidHandler, inputFluidHandler.getTankProperties()[0].getCapacity(), true); // The inventory is modified and stacks are merged. if (output == ItemStack.EMPTY) inv.setInventorySlotContents(outputSlot, inputFluidHandler.getContainer()); else inv.getStackInSlot(outputSlot).setCount(inv.getStackInSlot(outputSlot).getCount() + 1); inv.decrStackSize(inputSlot, 1); return true; } } } return false; }
public CapabilityProvider(IFluidHandlerItem fluidHandler, IItemTexture itemTexture) { this.fluidHandler = fluidHandler; this.itemTexture = itemTexture; }
void acceptWatering(EntityPlayer player, World w, BlockPos pos, IBlockState state, IFluidHandlerItem wateringCanCapability, ItemStack wateringCanStack, int wateringCanTier);