@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(); } }; }
@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; }
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()]); }
@Override public IFluidTankProperties[] getTankProperties() { if (this.fluids.isEmpty()) return new IFluidTankProperties[0]; IFluidTankProperties[] properties = new IFluidTankProperties[fluids.size()]; for (int i = 0; i < fluids.size(); i++) { boolean first = i == 0; int capacity2 = fluids.get(i).amount; if (first) capacity2 += getCapacity() - getFluidAmount(); properties[i] = new FluidTankProperties(fluids.get(i), capacity2, first, first); } return properties; }
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; }
public ArrayList<FluidStack> getFluidStacksInInventory(EnumFacing face){ ArrayList<FluidStack> result = new ArrayList<FluidStack>(); if (!hasInventoryOnSide(face.getIndex())) { return result; } TileEntity te = world.getTileEntity(getPos().offset(face)); if (!te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face.getOpposite())) { return result; } IFluidHandler fluidHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face.getOpposite()); for (IFluidTankProperties tank : fluidHandler.getTankProperties()) { if (!(tank.getContents() == null)) { result.add(tank.getContents()); } } return result; }
@Override public IFluidTankProperties[] getTankProperties() { IFluidTankProperties[] ret = new IFluidTankProperties[tanks.size()]; for(int i = 0; i < ret.length; i++) { IFluidTankProperties[] temp = tanks.get(i).getTankProperties(); if(temp == null || temp.length < 1) { ret[i] = new FluidTankProperties(null, 0); } else { ret[i] = temp[0]; } } return ret; }
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 void getRecieveTankInfo(List<IFluidTankProperties> infos, Set<Channel> channels) { if (inGetTankInfo) { return; } try { inGetTankInfo = true; if (!hasRecieveChannel(channels, ChannelType.FLUID)) { return; } Map<EnumFacing, IFluidHandler> fluidHandlers = getNeighbouringFluidHandlers(); for (Entry<EnumFacing, IFluidHandler> entry : fluidHandlers.entrySet()) { IFluidTankProperties[] tanks = entry.getValue().getTankProperties(); if (tanks != null) { for (IFluidTankProperties info : tanks) { infos.add(info); } } } } finally { inGetTankInfo = false; } }
public boolean render(@Nonnull ItemStack stack, int xPosition, int yPosition, int barOffset, boolean alwaysShow) { IFluidHandler cap = FluidUtil.getFluidHandlerCapability(stack); if (cap == null || cap.getTankProperties() == null || cap.getTankProperties().length <= 0) { return false; } IFluidTankProperties tank = cap.getTankProperties()[0]; if (tank == null || tank.getCapacity() <= 0) { return false; } int maxFluid = tank.getCapacity(); FluidStack fluidStack = tank.getContents(); int fluidAmount = fluidStack == null ? 0 : fluidStack.amount; if (alwaysShow || shouldShowBar(maxFluid, fluidAmount)) { double level = (double) fluidAmount / (double) maxFluid; boolean up = stack.getItem().showDurabilityBar(stack); boolean top = stack.getCount() != 1; render(level, xPosition, yPosition, top ? 12 - barOffset : up ? 2 + barOffset : barOffset, (barOffset & 1) == 0); return true; } return false; }
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)); } }
@Override public IFluidTankProperties[] getTankProperties() { updateXpFluid(); if (curXpFluid != null) { EntityPlayer player = getPlayer(); if (player != null) { return new FluidTankProperties[] { new FluidTankProperties( new FluidStack(curXpFluid, getPlayerXP(player) * PneumaticCraftAPIHandler.getInstance().liquidXPs.get(curXpFluid)), Integer.MAX_VALUE) }; } } return null; }
@Override public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World worldIn, EntityPlayer playerIn, EnumHand hand) { init(stack); if (getFluidStored(stack) >= FLUID_CAPACITY) { return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); } RayTraceResult ray = rayTrace(worldIn, playerIn, true); if (ray == null || ray.typeOfHit == null || hand == null) { return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); } if (ray.typeOfHit == RayTraceResult.Type.BLOCK && hand == EnumHand.MAIN_HAND && !worldIn.isRemote) { BlockPos blockpos = ray.getBlockPos(); IBlockState iblockstate = worldIn.getBlockState(blockpos); Material material = iblockstate.getMaterial(); if (material == Material.WATER && iblockstate.getValue(BlockLiquid.LEVEL).intValue() == 0) { worldIn.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 11); playerIn.addStat(StatList.getObjectUseStats(this)); playerIn.playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F); addFluid(stack, 1000); return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack); } else if (iblockstate.getBlock().hasTileEntity(iblockstate) && worldIn.getTileEntity(blockpos).hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, ray.sideHit)) { IFluidHandler fluidHandler = worldIn.getTileEntity(blockpos).getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, ray.sideHit); for (IFluidTankProperties property : fluidHandler.getTankProperties()) { if (property.getContents().getFluid() == FluidRegistry.WATER && property.getContents().amount >= 1000 && property.canDrain()) { fluidHandler.drain(new FluidStack(FluidRegistry.WATER, 1000), true); addFluid(stack, 1000); } } } } return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack); }
@Override public IFluidTankProperties[] getTankProperties() { if (this.tankProperties == null) { this.tankProperties = new IFluidTankProperties[] { new FluidTankPropertiesWrapper(this) }; } return this.tankProperties; }
@Override public IFluidTankProperties[] getTankProperties() { List<IFluidTankProperties> tanks = Lists.newArrayList(); for (IFluidHandler iFluidHandler : handlers.values()) { Collections.addAll(tanks, iFluidHandler.getTankProperties()); } return tanks.toArray(new IFluidTankProperties[tanks.size()]); }
@Override public IFluidTankProperties[] getTankProperties() { List<IFluidTankProperties> tanks = Lists.newArrayList(); for (IFluidHandler handler : subHandlers) { Collections.addAll(tanks, handler.getTankProperties()); } return tanks.toArray(new IFluidTankProperties[tanks.size()]); }
@Override public IFluidTankProperties[] getTankProperties() { float percentFilled = fluidBlock.getFilledPercentage(world, blockPos); if (percentFilled < 0) { percentFilled *= -1; } int amountFilled = Math.round(Fluid.BUCKET_VOLUME * percentFilled); FluidStack fluid = amountFilled > 0 ? new FluidStack(fluidBlock.getFluid(), amountFilled) : null; return new FluidTankProperties[]{ new FluidTankProperties(fluid, Fluid.BUCKET_VOLUME, false, true)}; }
@Override public IFluidTankProperties[] getTankProperties() { FluidStack containedStack = null; IBlockState blockState = world.getBlockState(blockPos); if (blockState.getBlock() == blockLiquid) { containedStack = getStack(blockState); } return new FluidTankProperties[]{new FluidTankProperties(containedStack, Fluid.BUCKET_VOLUME, false, true)}; }
@Override public IFluidTankProperties[] getTankProperties() { FluidStack fluid = FluidContainerRegistry.getFluidForFilledItem(container); int capacity = FluidContainerRegistry.getContainerCapacity(fluid, container); return new FluidTankProperties[] { new FluidTankProperties(fluid, capacity) }; }
@Override public FluidStackList getFluids() { FluidStackList fluids = new FluidStackList(); IFluidHandler handler = getTank(); if (handler !=null) { IFluidTankProperties prop = handler.getTankProperties()[0]; if (prop != null) { FluidStack stack = prop.getContents(); if(stack !=null && stack.amount > 0){ fluids.add(stack); } } } return fluids; }
@Override public int insertFluid(EStorageNetwork network, FluidStack stack, boolean matching, boolean sim) { IFluidHandler handler = getTank(); if (handler !=null) { int ret = 0; if(matching){ IFluidTankProperties prop = handler.getTankProperties()[0]; if (prop != null) { FluidStack internalStack = prop.getContents(); if(internalStack !=null){ if(FluidUtil.canCombine(stack, internalStack)){ ret = handler.fill(stack, !sim); } } } } else { ret = handler.fill(stack, !sim); } if(ret > 0){ FluidStack copy = stack.copy(); copy.amount = ret; Iterator<IInsertListener> iter = network.listeners.iterator(); while (iter.hasNext()) { iter.next().onFluidInserted(copy); } } return ret; } return 0; }
protected void transferFluid(EnumFacing face) { if (this.getIO(face) !=IOType.OUT || this.oMode == OutputMode.NONE) { return; } TileEntity tile = getWorld().getTileEntity(getPos().offset(face)); if(tile == null || !isFluidHandler(tile, face))return; IFluidHandler fHandler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, face.getOpposite()); int out = this.outputAmt; if(this.oMode == OutputMode.CHECK){ IFluidTankProperties[] infoArray = fHandler.getTankProperties(); for(int t = 0; t < infoArray.length; t++){ IFluidTankProperties info = infoArray[t]; if(info.getContents() !=null){ if(info.getContents().amount >= this.outputAmt){ return; }else{ out-=info.getContents().amount; break; } } } } FluidStack copy = tank.getFluid().copy(); copy.amount = Math.min(tank.getFluidAmount(), out); if(tank.getFluidAmount() == 0)return; this.drainInternal(fHandler.fill(copy, true), true); this.tankDirty = true; }
@Override public IFluidTankProperties[] getTankProperties() { if (world.isRemote) { return new IFluidTankProperties[] { new FluidTankProperties(liquid_state.s_liquid, EnderLiquidStorage.CAPACITY) }; } return getStorage().getTankProperties(); }
@Override public int comparatorInput() { IFluidTankProperties tank = getStorage().getTankProperties()[0]; FluidStack fluid = tank.getContents(); if (fluid == null) { fluid = FluidUtils.emptyFluid(); } return fluid.amount * 14 / tank.getCapacity() + (fluid.amount > 0 ? 1 : 0); }
@Override public IFluidTankProperties[] getTankProperties() { return new IFluidTankProperties[] { new FluidTankProperties(new FluidStack(FluidsRegistry.liquidXP, LiquidXPCollectorItem.getStoredXP(this.stack)), LiquidXPCollectorItem.MAX_CAPACITY, true, true) }; }
@Override public <T> T getCapability(Capability<T> capability, EnumFacing facing) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { if (facing == null) { final List<IFluidTankProperties> properties = new LinkedList<>(); for (Attachment a : attachments) { if (a != null) { properties.add(new FluidTankProperties(null, 0)); } } return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(new DummyFluidCapability() { @Override public IFluidTankProperties[] getTankProperties() { return properties.toArray(new IFluidTankProperties[0]); } }); } if (attachments[facing.ordinal()] != null) { return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(new DummyFluidCapability() { @Override public IFluidTankProperties[] getTankProperties() { return new IFluidTankProperties[] { new FluidTankProperties(null, 0) }; } }); } } return super.getCapability(capability, facing); }
@Override public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack stack = player.getHeldItem(hand); if(player.isSneaking()) { if(stack != null) { IFluidHandler fluidHandler = stack.getCapability(FLUID_HANDLER_ITEM_CAPABILITY, EnumFacing.DOWN); if(fluidHandler != null) { IFluidTankProperties[] props = fluidHandler.getTankProperties(); int number = 1; for(IFluidTankProperties prop : props) { FluidStack contents = prop.getContents(); if(contents == null) LogHelper.info("Tank " + number + ": EMPTY"); else LogHelper.info("Tank " + number + ": " + contents.getFluid().getName() + " (" + contents.amount + ")"); number++; } } } } else { IModeHandler modeHandler = stack.getCapability(MODE_CAPABILITY, EnumFacing.DOWN); if(modeHandler != null) { int mode = modeHandler.nextMode(); player.sendMessage(new TextComponentString("Current Mode: " + MODE.values()[mode].name())); } } return EnumActionResult.PASS; }
@Override public int getCapacity() { IFluidTankProperties[] tankInfo = fluidHandler.getTankProperties(); int capacity = 0; for (IFluidTankProperties tank : tankInfo) { capacity += tank.getCapacity(); } return capacity; }
@Override public int getFluidAmount(FluidStack like) { IFluidTankProperties[] tankInfo = fluidHandler.getTankProperties(); int amount = 0; for (IFluidTankProperties tank : tankInfo) { FluidStack contents = tank.getContents(); if(contents != null && contents.isFluidEqual(like)) { amount += contents.amount; } } return amount; }
@Override public FluidStack[] getFluids() { IFluidTankProperties[] tankInfo = fluidHandler.getTankProperties(); FluidStack[] content = new FluidStack[tankInfo.length]; for (int i = 0; i < tankInfo.length; i++) { content[i] = tankInfo[i].getContents(); } return content; }
public void cacheCapacity(ItemStack stack) { if (LinkMode.fromStack(stack) == LinkMode.ENABLED) { ItemStack moduleStack = this.getSelectedModuleStack(stack, ModuleType.TYPE_LINKCRYSTAL); if (moduleStack.isEmpty() == false && moduleStack.getTagCompound() != null) { NBTTagCompound moduleNbt = moduleStack.getTagCompound(); IFluidHandler handler = this.getLinkedTank(stack); if (handler != null) { IFluidTankProperties[] tank = handler.getTankProperties(); if (tank != null && tank.length > 0 && tank[0] != null) { moduleNbt.setInteger("CapacityCached", tank[0].getCapacity()); } else { moduleNbt.setInteger("CapacityCached", 0); } } else { moduleNbt.removeTag("CapacityCached"); } moduleStack.setTagCompound(moduleNbt); this.setSelectedModuleStack(stack, ModuleType.TYPE_LINKCRYSTAL, moduleStack); } } }
private int fillInternal(World world, BlockPos coord, EnumFacing side, int maxDrain) { int drain = 0; final TileEntity otherTank = BlockUtils.getTileInDirection(world, coord, side); final EnumFacing drainSide = side.getOpposite(); IFluidHandler handler = CompatibilityUtils.getFluidHandler(otherTank, drainSide); if (handler != null) { final IFluidTankProperties[] infos = handler.getTankProperties(); if (infos == null) return 0; for (IFluidTankProperties info : infos) { if (filter.canAcceptFluid(info.getContents())) { final FluidStack drained = handler.drain(maxDrain, true); if (drained != null) { fill(drained, true); drain += drained.amount; maxDrain -= drained.amount; if (maxDrain <= 0) break; } } } } return drain; }
@Override public IFluidTankProperties[] getTankProperties() { if (inGetTankInfo) { return new IFluidTankProperties[0]; } try { inGetTankInfo = true; return TransceiverRegistry.INSTANCE.getTankInfoForChannels(TileTransceiver.this, getSendChannels(ChannelType.FLUID)); } finally { inGetTankInfo = false; } }
@Override public IFluidTankProperties[] getTankProperties() { if(network == null) { return new FluidTankProperties[0]; } return network.getTankProperties(EnderLiquidConduit.this, side); }
@Override public IFluidTankProperties[] getTankProperties() { if (network == null) { return new FluidTankProperties[0]; } return new FluidTankProperties[] { new FluidTankProperties(tank.getFluid(), tank.getCapacity()) }; }
public IFluidTankProperties[] getTankProperties(@Nonnull EnderLiquidConduit con, @Nonnull EnumFacing conDir) { List<IFluidTankProperties> res = new ArrayList<IFluidTankProperties>(tanks.size()); NetworkTank tank = getTank(con, conDir); for (NetworkTank target : tanks) { if(!target.equals(tank) && target.isValid()) { for (ITankInfoWrapper info : target.externalTank.getTankInfoWrappers()) { res.add(info.getIFluidTankProperties()); } } } return res.toArray(new IFluidTankProperties[res.size()]); }