@Override protected DroneAIBlockCondition getEvaluator(IDroneBase drone, IProgWidget widget) { return new DroneAIBlockCondition(drone, (ProgWidgetAreaItemBase) widget) { @Override protected boolean evaluate(BlockPos pos) { TileEntity te = drone.world().getTileEntity(pos); int count = 0; if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null) ) { IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); for (IFluidTankProperties prop : handler.getTankProperties()) { FluidStack stack = prop.getContents(); if (stack != null) { if (ProgWidgetLiquidFilter.isLiquidValid(stack.getFluid(), widget, 1)) { count += stack.amount; } } } } else { Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.world().getBlockState(pos).getBlock()); if (fluid != null && ProgWidgetLiquidFilter.isLiquidValid(fluid, widget, 1) && FluidUtils.isSourceBlock(drone.world(), pos)) { count += 1000; } } return ((ICondition) widget).getOperator() == ICondition.Operator.EQUALS ? count == ((ICondition) widget).getRequiredCount() : count >= ((ICondition) widget).getRequiredCount(); } }; }
public static int getRequestedAmount(SemiBlockLogistics requester, FluidStack providingStack) { int requestedAmount = requester instanceof ISpecificRequester ? ((ISpecificRequester) requester).amountRequested(providingStack) : providingStack.amount; if (requestedAmount == 0) return 0; providingStack = providingStack.copy(); providingStack.amount = requestedAmount; FluidStack remainder = providingStack.copy(); remainder.amount += requester.getIncomingFluid(remainder.getFluid()); TileEntity te = requester.getTileEntity(); if (te == null) return 0; for (EnumFacing d : EnumFacing.VALUES) { if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, d)) { IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, d); int fluidFilled = handler.fill(remainder, false); if (fluidFilled > 0) { remainder.amount -= fluidFilled; break; } } } providingStack.amount -= remainder.amount; if (providingStack.amount <= 0) return 0; return providingStack.amount; }
@Override @Optional.Method(modid = "theoneprobe") public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) { TileEntity te = world.getTileEntity(data.getPos()); if(te instanceof IInfoForwarder){ te = ((IInfoForwarder)te).getInfoTileEntity(); } if (te instanceof IPneumaticMachine) { TOPCallback.handlePneumatic(mode, probeInfo, (IPneumaticMachine)te); } if (te instanceof IHeatExchanger) { TOPCallback.handleHeat(mode, probeInfo, (IHeatExchanger) te); } if (ConfigHandler.client.topShowsFluids && te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, data.getSideHit())) { IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, data.getSideHit()); TOPCallback.handleFluidTanks(mode, probeInfo, handler); } if (te instanceof TileEntityBase) { TOPCallback.handleRedstoneMode(mode, probeInfo, (TileEntityBase) te); } if (te instanceof TileEntityPressureTube) { TOPCallback.handlePressureTube(mode, probeInfo, (TileEntityPressureTube) te, data.getSideHit()); } }
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; }
public void autoExportLiquid() { if (hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) { IFluidHandler handler = getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); FluidStack toDrain = handler.drain(1000, false); if (toDrain != null && toDrain.amount > 0) { for (EnumFacing d : EnumFacing.VALUES) { TileEntity te = getTileCache()[d.ordinal()].getTileEntity(); if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, d.getOpposite())) { IFluidHandler destHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, d.getOpposite()); FluidStack sent = FluidUtil.tryFluidTransfer(destHandler, handler, toDrain, true); toDrain.amount -= sent == null ? 0 : sent.amount; if (toDrain.amount <= 0) break; } } } } }
@Override public int amountRequested(FluidStack stack) { int totalRequestingAmount = getTotalRequestedAmount(stack); if (totalRequestingAmount > 0) { TileEntity te = getTileEntity(); int count = 0; for (EnumFacing facing : EnumFacing.VALUES) { if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)) { IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing); for (IFluidTankProperties properties : handler.getTankProperties()) { FluidStack contents = properties.getContents(); if (contents != null && contents.getFluid() == stack.getFluid()) { count += contents.amount; } } if (count > 0) break; } } if (count == 0) return 0; count += getIncomingFluid(stack.getFluid()); return Math.max(0, Math.min(stack.amount, totalRequestingAmount - count)); } return 0; }
@Override public IFluidTankProperties[] getTankProperties() { if(properties == null) { //Fingers crossed ArrayList<IFluidTankProperties> importedProperties = new ArrayList<>(); if (tile != null) for (EnumFacing facing : EnumFacing.HORIZONTALS) { if (tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing)) { IFluidHandler capability = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing); IFluidTankProperties[] faceProperties = capability.getTankProperties(); importedProperties.addAll(Arrays.asList(faceProperties)); } } properties = importedProperties.toArray(new IFluidTankProperties[importedProperties.size()]); } return properties; }
@Nullable @Override public FluidStack drain(FluidStack resource, boolean doDrain) { FluidStack drained = null; if(tile != null) for (EnumFacing facing : EnumFacing.HORIZONTALS) { if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,facing)) { IFluidHandler capability = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,facing); drained = capability.drain(resource,doDrain); if(drained != null) break; } } return drained; }
@Nullable @Override public FluidStack drain(int maxDrain, boolean doDrain) { FluidStack drained = null; if(tile != null) for (EnumFacing facing : EnumFacing.HORIZONTALS) { if(tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,facing)) { IFluidHandler capability = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY,facing); drained = capability.drain(maxDrain,doDrain); if(drained != null) break; } } return drained; }
@SuppressWarnings("ConstantConditions") @Override public void onFinish(TileCauldron tile, World world, BlockPos pos) { for (int i = 0; i < 20; i++) { final float x = pos.getX() + 0.2F + MathHelper.clamp(world.rand.nextFloat(), 0F, 0.5F); final float y = pos.getY() + 0.2F + world.rand.nextFloat(); final float z = pos.getZ() + 0.2F + MathHelper.clamp(world.rand.nextFloat(), 0F, 0.5F); PacketHandler.spawnParticle(ParticleF.STEAM, world, x, y, z, 10, 0, 0, 0); } if (!stack.isEmpty()) { if (tile.getContainer().isEmpty()) { tile.setContainer(stack); } else { spawnItem(world, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D); } } world.playSound(null, pos, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1F, 1F); IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); handler.drain(1000, true); }
@Nullable @Override public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFacing facing) { if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY){ IItemHandler inventory = getInventory(facing); if(inventory != null){ return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(inventory); } } if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY){ IFluidHandler tank = getTank(facing); if(tank != null){ return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(tank); } } if(capability == CapabilityEnergy.ENERGY){ IEnergyStorage energy = getEnergy(facing); if(energy != null){ return CapabilityEnergy.ENERGY.cast(energy); } } return null; }
protected void readCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side){ IItemHandler inventory = this.getInventory(side); if(inventory != null && inventory instanceof IItemHandlerModifiable && nbt.hasKey("Inventory")){ for(int i = 0; i < inventory.getSlots(); i++){ // clear the inventory, otherwise empty stacks doesn't get overriden while syncing. Forge Bug? ((IItemHandlerModifiable) inventory).setStackInSlot(i, ItemStack.EMPTY); } CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(inventory, side, nbt.getTag("Inventory")); } IFluidHandler tank = getTank(side); if(tank != null && tank instanceof IFluidTank && nbt.hasKey("FluidTank")){ CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(tank, side, nbt.getCompoundTag("FluidTank")); } IEnergyStorage energy = getEnergy(side); if(energy != null && energy instanceof EnergyStorage && nbt.hasKey("Energy")){ CapabilityEnergy.ENERGY.readNBT(energy, side, nbt.getTag("Energy")); } }
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack heldItem = player.getHeldItem(hand); // TODO: Examine Prep1_11.isValid(). This current snippet always evaluates to true. if(Prep1_11.isValid(heldItem) && CapUtils.hasFluidHandler(heldItem)) { IFluidHandler lavaTank = CapUtils.getFluidHandler(world.getTileEntity(pos)); if(Util.isEmptyFluidContainer(heldItem)) { FluidUtil.tryFillContainerAndStow(heldItem, lavaTank, CapUtils.getItemHandler(player), 1000, player); } else { FluidUtil.tryEmptyContainerAndStow(heldItem, lavaTank, CapUtils.getItemHandler(player), 1000, player); } } else player.openGui(ModMain.modInstance, BBGuiHandler.NETHERBRICKOVEN_ID, world, pos.getX(), pos.getY(), pos.getZ()); return true; }
/** * Fill a destination fluid handler from a source fluid handler. * * @param fluidDestination The fluid handler to be filled. * @param fluidSource The fluid handler to be drained. * @param maxAmount The largest amount of fluid that should be transferred. * @param doTransfer True if the transfer should actually be done, false if it should be simulated. * @return the fluidStack that was transferred from the source to the destination. null on failure. */ @Nullable public static FluidStack tryFluidTransfer(IFluidHandler fluidDestination, IFluidHandler fluidSource, int maxAmount, boolean doTransfer) { FluidStack drainable = fluidSource.drain(maxAmount, false); if (drainable != null && drainable.amount > 0) { int fillableAmount = fluidDestination.fill(drainable, false); if (fillableAmount > 0) { FluidStack drained = fluidSource.drain(fillableAmount, doTransfer); if (drained != null) { drained.amount = fluidDestination.fill(drained, doTransfer); return drained; } } } return null; }
/** * Helper method to get the fluid contained in an itemStack */ @Nullable public static FluidStack getFluidContained(ItemStack container) { if (container != null) { container = container.copy(); container.stackSize = 1; IFluidHandler fluidHandler = FluidUtil.getFluidHandler(container); if (fluidHandler != null) { return fluidHandler.drain(Integer.MAX_VALUE, false); } } return null; }
/** * Helper method to get an IFluidHandler for at a block position. * * Returns null if there is no valid fluid handler. */ @Nullable public static IFluidHandler getFluidHandler(World world, BlockPos blockPos, @Nullable EnumFacing side) { IBlockState state = world.getBlockState(blockPos); Block block = state.getBlock(); if (block.hasTileEntity(state)) { TileEntity tileEntity = world.getTileEntity(blockPos); if (tileEntity != null && tileEntity.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side)) { return tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); } } else if (block instanceof IFluidBlock) { return new FluidBlockWrapper((IFluidBlock) block, world, blockPos); } else if (block instanceof BlockLiquid) { return new BlockLiquidWrapper((BlockLiquid) block, world, blockPos); } return null; }
/** * Attempts to pick up a fluid in the world and put it in an empty container item. * * @param emptyContainer The empty container to fill. Will not be modified. * @param playerIn The player filling the container. Optional. * @param worldIn The world the fluid is in. * @param pos The position of the fluid in the world. * @param side The side of the fluid that is being drained. * @return a filled container if it was successful. returns null on failure. */ @Nullable public static ItemStack tryPickUpFluid(ItemStack emptyContainer, @Nullable EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side) { if (emptyContainer == null || worldIn == null || pos == null) { return null; } IBlockState state = worldIn.getBlockState(pos); Block block = state.getBlock(); if (block instanceof IFluidBlock || block instanceof BlockLiquid) { IFluidHandler targetFluidHandler = FluidUtil.getFluidHandler(worldIn, pos, side); if (targetFluidHandler != null) { return FluidUtil.tryFillContainer(emptyContainer, targetFluidHandler, Integer.MAX_VALUE, playerIn, true); } } return null; }
@Override public int fill(FluidStack resource, boolean doFill) { if (resource == null || resource.amount <= 0) return 0; resource = resource.copy(); int totalFillAmount = 0; for (IFluidHandler handler : subHandlers) { int fillAmount = handler.fill(resource, doFill); totalFillAmount += fillAmount; resource.amount -= fillAmount; if (resource.amount <= 0) break; } return totalFillAmount; }
public static ItemStack getEmptyContainer(ItemStack stack){ if (ItemStackTools.isNullStack(stack)) { return null; } ItemStack ret = stack.copy(); ItemStackTools.setStackSize(ret, 1); IFluidHandler handler = getFluidHandlerCapability(ret); if (handler != null) { try{ handler.drain(Integer.MAX_VALUE, true); } catch(Exception e){ e.printStackTrace(); FluidStack fluid = getFluidTypeFromItem(stack); if(fluid !=null && hasFluidBucket(fluid)){ return getFluidBucket(fluid); } } return ret; } return ItemStackTools.getEmptyStack(); }
public static FluidStack getFluidTypeFromItem(ItemStack stack) { if (ItemStackTools.isNullStack(stack)) { return null; } stack = stack.copy(); ItemStackTools.setStackSize(stack, 1); IFluidHandler handler = getFluidHandlerCapability(stack); if (handler != null) { return handler.drain(Fluid.BUCKET_VOLUME, false); } if (Block.getBlockFromItem(stack.getItem()) instanceof IFluidBlock) { Fluid fluid = ((IFluidBlock) Block.getBlockFromItem(stack.getItem())).getFluid(); if (fluid != null) { return new FluidStack(fluid, 1000); } } return null; }
@Override public FluidStack extractFluid(EStorageNetwork network, FluidStack stack, int amount, FluidExtractFilter filter, boolean sim) { IFluidHandler handler = getTank(); if (handler !=null) { FluidStack copy = stack.copy(); copy.amount = amount; FluidStack received = handler.drain(copy, !sim); if(received !=null){ Iterator<IInsertListener> iter = network.listeners.iterator(); while (iter.hasNext()) { iter.next().onFluidExtracted(received, received.amount); } } return received; } return null; }
public boolean extractFrom(TileEntityPipeLiquid pipe, EnumFacing conDir) { NetworkTank tank = getTank(pipe, conDir); if(tank == null || !tank.isValid()) { return false; } IFluidHandler fluidhandler = tank.externalTank.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, conDir.getOpposite()); FluidStack drained = fluidhandler.drain(MAX_EXTRACT, false); if(drained == null || drained.amount <= 0 || !pipe.matchedFilter(drained, conDir, true)) { return false; } int amountAccepted = fillFrom(tank, drained.copy(), true); if(amountAccepted <= 0) { return false; } drained = fluidhandler.drain(amountAccepted, true); if(drained == null || drained.amount <= 0) { return false; } return true; }
public IFluidTankProperties[] getTankInfo(TileEntityPipeLiquid pipe, EnumFacing conDir) { List<IFluidTankProperties> res = new ArrayList<IFluidTankProperties>(tanks.size()); NetworkTank tank = getTank(pipe, conDir); for (NetworkTank target : tanks) { if(!target.equals(tank) && target.isValid()) { IFluidHandler fHandler = target.externalTank.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.tankDir); IFluidTankProperties[] tTanks = fHandler.getTankProperties(); if(tTanks != null) { for (IFluidTankProperties info : tTanks) { res.add(info); } } } } return res.toArray(new IFluidTankProperties[res.size()]); }
public static boolean fillTankWithContainer(IFluidHandler tank, EntityPlayer player) { ItemStack stack = player.getHeldItem(EnumHand.MAIN_HAND); FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(stack); if (liquid == null) { return false; } if (tank.fill(liquid, false) != liquid.amount && !player.capabilities.isCreativeMode) { return false; } tank.fill(liquid, true); if (!player.capabilities.isCreativeMode) { InventoryUtils.consumeItem(player.inventory, player.inventory.currentItem); } player.inventoryContainer.detectAndSendChanges(); return true; }
private void ejectLiquid() { for (EnumFacing side : EnumFacing.values()) { TileEntity tile = world.getTileEntity(getPos().offset(side)); if (tile == null || !tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())) { continue; } IFluidHandler c = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite()); FluidStack liquid = getStorage().drain(100, false); if (liquid == null) { continue; } int qty = c.fill(liquid, true); if (qty > 0) { getStorage().drain(qty, true); } } }
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (state.getValue(STATE) != 0) { TileEntityRefinery te = (TileEntityRefinery) worldIn.getTileEntity(pos); boolean gui = true; if (pos instanceof MultiBlockPos) { IFluidHandler c = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side, ((MultiBlockPos) pos).getOther(), ((MultiBlockPos) pos).getId()); if (c != null) { gui = !TomsModUtils.interactWithFluidHandler(c, playerIn, hand); } } if (gui) { if (!worldIn.isRemote) playerIn.openGui(CoreInit.modInstance, GuiIDs.refinery.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ()); return true; } } return pos instanceof MultiBlockPos; }
@Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) { if (state.getValue(STATE) != 0) { TileEntityPlasticProcessor te = (TileEntityPlasticProcessor) worldIn.getTileEntity(pos); boolean gui = true; if (pos instanceof MultiBlockPos) { IFluidHandler c = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side, ((MultiBlockPos) pos).getOther(), ((MultiBlockPos) pos).getId()); if (c != null) { gui = !TomsModUtils.interactWithFluidHandler(c, playerIn, hand); } } if (gui) { if (!worldIn.isRemote) playerIn.openGui(CoreInit.modInstance, GuiIDs.plasticProcessor.ordinal(), worldIn, pos.getX(), pos.getY(), pos.getZ()); return true; } } return pos instanceof MultiBlockPos; }
private void spreadOutput(FluidStack move, int src, int[] outputs, IFluidHandler[] attached, ArrayList<LiquidTransfer> transfers) { for (int k = 0; k < outputs.length && move.amount > 0; k++) { int dst = outputs[k]; IFluidHandler outaccess = attached[dst]; int fit = outaccess.fill(move, false); int spread = outputs.length - k; fit = Math.min(fit, move.amount / spread + world.rand.nextInt(move.amount % spread + 1)); if (fit == 0) { continue; } FluidStack add = FluidUtils.copy(move, fit); outaccess.fill(add, true); move.amount -= fit; transfers.add(new LiquidTransfer(src, dst, add)); } }
@Override public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) { if (world.isRemote) return null; IFluidHandler h = FluidUtil.getFluidHandler(world, pos, side); if (h != null) { for (Entry<FluidStack, ItemStack> e : fluidToItem.entrySet()) { FluidStack drain = h.drain(new FluidStack(e.getKey(), e.getKey().amount), false); if (e.getKey().isFluidStackIdentical(drain)) { h.drain(drain, true); ItemStack s = e.getValue().copy(); stack.shrink(1); player.setHeldItem(hand, stack); if (!player.inventory.addItemStackToInventory(s)) { InventoryHelper.spawnItemStack(world, player.posX, player.posY, player.posZ, s); } player.inventoryContainer.detectAndSendChanges(); return EnumActionResult.SUCCESS; } } } return null; }
@Override public void pushOutput(EnumFacing side) { if (tankOut.getFluidAmount() > 0) { TileEntity tile = world.getTileEntity(pos.offset(side)); if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite())) { IFluidHandler t = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite()); if (t != null) { int filled = t.fill(tankOut.getFluid(), false); if (filled > 0) { FluidStack drained = tankOut.drain(filled, false); if (drained != null && drained.amount > 0) { int canDrain = Math.min(filled, Math.min(100, drained.amount)); t.fill(tankOut.drain(canDrain, true), true); } } } } } }
@Override public void onGridReload() { grid.rec.removeAll(rec); //grid.addTank(tank); rec.clear(); for (EnumFacing f : EnumFacing.VALUES) { if (connectsInv(f)) { TileEntity tile = world.getTileEntity(pos.offset(f)); if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, f.getOpposite())) { IFluidHandler t = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, f.getOpposite()); if (t != null) { rec.add(t); grid.rec.add(t); } } } } }
@Override public void updateEntityI() { if (!world.isRemote) { if (grid.getData().getFluid() == null || grid.getData().getCapacity() >= grid.getData().getFluidAmount()) { EnumFacing facing = getFacing(); TileEntity tile = world.getTileEntity(pos.offset(facing)); if (tile != null && tile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite())) { IFluidHandler t = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite()); if (t != null) { FluidStack drained = t.drain(Configs.fluidDuctMaxExtract, false); if (drained != null && drained.amount > 0) { // if(t.canDrain(f, t.drain(1, false).getFluid())){ int filled = grid.getData().fill(drained, false); if (filled > 0) { int canDrain = Math.min(filled, Math.min(Configs.fluidDuctMaxExtract, drained.amount)); grid.getData().fill(t.drain(canDrain, true), true); } } } } } } }
public FluidStack takeFluidFromInventoryOnSide(EnumFacing face, FluidStack fluid) { if (!hasInventoryOnSide(face.getIndex())) { return null; } TileEntity te = world.getTileEntity(getPos().offset(face)); if (!te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face.getOpposite())) { return null; } IFluidHandler fluidHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face.getOpposite()); FluidStack result = new FluidStack(fluid.getFluid(), 0); for (int i = 0; i < fluidHandler.getTankProperties().length; i++) { if (fluidHandler.getTankProperties()[i].getContents().isFluidEqual(fluid)) { FluidStack tmp = fluidHandler.drain(fluid, true); result = new FluidStack(fluid.getFluid(), tmp.amount + result.amount); fluid = new FluidStack(fluid.getFluid(), fluid.amount - tmp.amount); } if (fluid.amount <= 0) { break; } } if (result.amount == 0) return null; return result; }
@Override public void addProblems(List<String> curInfo) { super.addProblems(curInfo); IFluidHandler fluidHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); if (!te.isProducing && (fluidHandler == null || fluidHandler.getTankProperties()[0].getContents() == null)) { curInfo.add("gui.tab.problems.liquidCompressor.noFuel"); } }
public static void handleFluidTanks(ProbeMode mode, IProbeInfo probeInfo, IFluidHandler handler) { int n = 1; for (IFluidTankProperties properties : handler.getTankProperties()) { FluidStack fluidStack = properties.getContents(); String fluidDesc = fluidStack == null ? I18n.translateToLocalFormatted("gui.liquid.empty") : fluidStack.amount + "mB " + fluidStack.getLocalizedName(); probeInfo.text(I18n.translateToLocalFormatted("waila.fluid", n++, fluidDesc)); } }
private boolean emptyTank(BlockPos pos, boolean simulate) { if (drone.getTank().getFluidAmount() == drone.getTank().getCapacity()) { drone.addDebugEntry("gui.progWidget.liquidImport.debug.fullDroneTank"); abort(); return false; } else { TileEntity te = drone.world().getTileEntity(pos); if (te != null) { for (int i = 0; i < 6; i++) { if (((ISidedWidget) widget).getSides()[i] && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.getFront(i))) { IFluidHandler handler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.getFront(i)); FluidStack importedFluid = handler.drain(Integer.MAX_VALUE, false); if (importedFluid != null && ((ILiquidFiltered) widget).isFluidValid(importedFluid.getFluid())) { int filledAmount = drone.getTank().fill(importedFluid, false); if (filledAmount > 0) { if (((ICountWidget) widget).useCount()) filledAmount = Math.min(filledAmount, getRemainingCount()); if (!simulate) { decreaseCount(drone.getTank().fill(handler.drain(filledAmount, true), true)); } return true; } } } } drone.addDebugEntry("gui.progWidget.liquidImport.debug.emptiedToMax", pos); } else if (!((ICountWidget) widget).useCount() || getRemainingCount() >= 1000) { Fluid fluid = FluidRegistry.lookupFluidForBlock(drone.world().getBlockState(pos).getBlock()); if (fluid != null && ((ILiquidFiltered) widget).isFluidValid(fluid) && drone.getTank().fill(new FluidStack(fluid, 1000), false) == 1000 && FluidUtils.isSourceBlock(drone.world(), pos)) { if (!simulate) { decreaseCount(1000); drone.getTank().fill(new FluidStack(fluid, 1000), true); drone.world().setBlockToAir(pos); } return true; } } return false; } }
public static IFluidHandler getLiquidProvider(ItemStack tablet) { BlockPos pos = getLiquidProvidingLocation(tablet); if (pos != null) { int dimension = getLiquidProvidingDimension(tablet); return FluidUtil.getFluidHandler(DimensionManager.getWorld(dimension), pos, null); } return null; }
public ContainerAmadron(EntityPlayer player) { super(null); for (int y = 0; y < ROWS; y++) { for (int x = 0; x < 2; x++) { addSlotToContainer(new SlotUntouchable(inv, y * 4 + x * 2, x * 73 + 12, y * 35 + 70)); addSlotToContainer(new SlotUntouchable(inv, y * 4 + x * 2 + 1, x * 73 + 57, y * 35 + 70)); } } addSyncedFields(this); Arrays.fill(shoppingItems, -1); if (!player.world.isRemote) { IItemHandler itemHandler = ItemAmadronTablet.getItemProvider(player.getHeldItemMainhand()); IFluidHandler fluidHandler = ItemAmadronTablet.getLiquidProvider(player.getHeldItemMainhand()); for (int i = 0; i < offers.size(); i++) { int amount = capShoppingAmount(offers.get(i), 1, itemHandler, fluidHandler, this); buyableOffers[i] = amount > 0; } problemState = EnumProblemState.NO_PROBLEMS; Map<AmadronOffer, Integer> shoppingCart = ItemAmadronTablet.getShoppingCart(player.getHeldItemMainhand()); for (Map.Entry<AmadronOffer, Integer> cartItem : shoppingCart.entrySet()) { int offerId = offers.indexOf(cartItem.getKey()); if (offerId >= 0) { int index = getCartSlot(offerId); if (index >= 0) { shoppingItems[index] = offerId; shoppingAmounts[index] = cartItem.getValue(); } } } currentOffers = AmadronOfferManager.getInstance().countOffers(player.getGameProfile().getId().toString()); maxOffers = PneumaticCraftUtils.isPlayerOp(player) ? Integer.MAX_VALUE : AmadronOfferSettings.maxTradesPerPlayer; } }
/** * Attempt to extract fluid from the given fluid handler into the given fluid-containing item. * * @param srcHandler fluid handler into which to place the fluid * @param destStack the fluid container item to extract from * @param returnedItems the modified fluid container after extraction * @return true if any fluid was moved, false otherwise */ public static boolean tryFluidExtraction(IFluidHandler srcHandler, ItemStack destStack, NonNullList<ItemStack> returnedItems) { FluidActionResult result = FluidUtil.tryFillContainer(destStack, srcHandler, 1000, null, true); if (result.isSuccess()) { returnedItems.add(result.getResult()); destStack.shrink(1); return true; } else { return false; } }
/** * Attempt to insert fluid into the given fluid handler from the given fluid container item. * * @param handler the handler to extract from * @param srcStack the fluid container item to insert to * @param returnedItems the modified fluid container after insertion * @return true if any fluid was moved, false otherwise */ public static boolean tryFluidInsertion(IFluidHandler handler, ItemStack srcStack, NonNullList<ItemStack> returnedItems) { FluidActionResult result = FluidUtil.tryEmptyContainer(srcStack, handler, 1000, null, true); if (result.isSuccess()) { returnedItems.add(result.getResult()); srcStack.shrink(1); return true; } else { return false; } }