net.minecraftforge.fluids.capability.IFluidHandler Java Examples
The following examples show how to use
net.minecraftforge.fluids.capability.IFluidHandler.
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: FillerTileEntity.java From EmergingTechnology with MIT License | 6 votes |
private void fillAdjacent() { for (EnumFacing facing : EnumFacing.VALUES) { TileEntity neighbour = this.world.getTileEntity(this.pos.offset(facing)); // Return if no tile entity or another filler if (neighbour == null || neighbour instanceof FillerTileEntity) { continue; } IFluidHandler neighbourFluidHandler = neighbour .getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite()); // Return if neighbour has no fluid tank if (neighbourFluidHandler == null) { continue; } // Fill the neighbour neighbourFluidHandler.fill(new FluidStack(FluidRegistry.WATER, EmergingTechnologyConfig.HYDROPONICS_MODULE.FILLER.fillerFluidTransferRate), true); } }
Example #2
Source File: GenericTank.java From OpenModsLib with MIT License | 6 votes |
private int fillInternal(World world, BlockPos coord, EnumFacing side, int maxDrain) { final TileEntity otherTank = BlockUtils.getTileInDirection(world, coord, side); final EnumFacing drainSide = side.getOpposite(); final IFluidHandler handler = CompatibilityUtils.getFluidHandler(otherTank, drainSide); if (handler != null) { final FluidStack drained = handler.drain(maxDrain, false); if (drained != null && filter.canAcceptFluid(drained)) { final int filled = fill(drained, true); if (filled > 0) { handler.drain(filled, true); return filled; } } } return 0; }
Example #3
Source File: SimpleMachineMetaTileEntity.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override public <T> T getCapability(Capability<T> capability, EnumFacing side) { if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) { IFluidHandler fluidHandler = (side == getOutputFacing() && !allowInputFromOutputSide) ? outputFluidInventory : fluidInventory; if(fluidHandler.getTankProperties().length > 0) { return CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.cast(fluidHandler); } return null; } else if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { IItemHandler itemHandler = (side == getOutputFacing() && !allowInputFromOutputSide) ? outputItemInventory : itemInventory; if(itemHandler.getSlots() > 0) { return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(itemHandler); } return null; } return super.getCapability(capability, side); }
Example #4
Source File: SingleFluidBucketFillHandler.java From OpenModsLib with MIT License | 6 votes |
@SubscribeEvent(priority = EventPriority.HIGH) 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 (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit)) { final IFluidHandler source = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, target.sideHit); final FluidStack drained = source.drain(containedFluid, false); if (containedFluid.isFluidStackIdentical(drained)) { source.drain(containedFluid, true); evt.setFilledBucket(filledBucket.copy()); evt.setResult(Result.ALLOW); } } }
Example #5
Source File: MetaTileEntity.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
public void pullFluidsFromNearbyHandlers(EnumFacing... allowedFaces) { PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain(); for (EnumFacing nearbyFacing : allowedFaces) { blockPos.setPos(getPos()).move(nearbyFacing); TileEntity tileEntity = getWorld().getTileEntity(blockPos); if (tileEntity == null) { continue; } IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing.getOpposite()); //use getCoverCapability so fluid tank index filtering and fluid filtering covers will work properly IFluidHandler myFluidHandler = getCoverCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing); if (fluidHandler == null || myFluidHandler == null) { continue; } CoverPump.moveHandlerFluids(fluidHandler, myFluidHandler, Integer.MAX_VALUE, fluid -> true); } blockPos.release(); }
Example #6
Source File: MetaTileEntity.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
public void pushFluidsIntoNearbyHandlers(EnumFacing... allowedFaces) { PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain(); for (EnumFacing nearbyFacing : allowedFaces) { blockPos.setPos(getPos()).move(nearbyFacing); TileEntity tileEntity = getWorld().getTileEntity(blockPos); if (tileEntity == null) { continue; } IFluidHandler fluidHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing.getOpposite()); //use getCoverCapability so fluid tank index filtering and fluid filtering covers will work properly IFluidHandler myFluidHandler = getCoverCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, nearbyFacing); if (fluidHandler == null || myFluidHandler == null) { continue; } CoverPump.moveHandlerFluids(myFluidHandler, fluidHandler, Integer.MAX_VALUE, fluid -> true); } blockPos.release(); }
Example #7
Source File: TileEntityEnderFurnace.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
/** * Checks if the given ItemStack contains a valid fluid fuel source for the furnace. * Valid fuels are currently just lava. * @param stack * @return */ private static boolean itemContainsFluidFuel(ItemStack stack) { if (stack.isEmpty() || stack.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null) == false) { return false; } IFluidHandler handler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); if (handler == null) { return false; } FluidStack fluidStack = handler.drain(Fluid.BUCKET_VOLUME, false); //System.out.printf("itemContainsFluidFuelFluidCapability: %s - %d\n", (fluidStack != null ? fluidStack.getFluid().getName() : "null"), fluidStack != null ? fluidStack.amount : 0); if (fluidStack == null || fluidStack.amount <= 0) { return false; } return fluidStack.getFluid() == FluidRegistry.LAVA; }
Example #8
Source File: BlockBTank.java From BetterChests with GNU Lesser General Public License v3.0 | 6 votes |
@Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) { ItemStack original = player.getHeldItem(hand); if (!original.isEmpty()) { ItemStack stack = original.copy(); stack.setCount(1); TileEntity tank = getTileEntity(world, pos); if (tank instanceof TileEntityBTank) { IFluidHandler handler = ((TileEntityBTank) tank).getFluidHandler(); FluidActionResult result = FluidUtil.tryEmptyContainer(stack, handler, Fluid.BUCKET_VOLUME, player, true); if (!result.success) { result = FluidUtil.tryFillContainer(stack, handler, Fluid.BUCKET_VOLUME, player, true); } if (result.success) { original.setCount(original.getCount() - 1); stack = InvUtil.putStackInInventory(result.result, player.inventory, true, false, false, null); if (!stack.isEmpty()) { WorldUtil.dropItemsRandom(world, stack, player.getPosition()); } return true; } } } return super.onBlockActivated(world, pos, state, player, hand, facing, hitX, hitY, hitZ); }
Example #9
Source File: MetaTileEntityPump.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
private void tryPumpFirstBlock() { BlockPos fluidBlockPos = fluidSourceBlocks.poll(); if (fluidBlockPos == null) return; IBlockState blockHere = getWorld().getBlockState(fluidBlockPos); if (blockHere.getBlock() instanceof BlockLiquid || blockHere.getBlock() instanceof IFluidBlock) { IFluidHandler fluidHandler = FluidUtil.getFluidHandler(getWorld(), fluidBlockPos, null); FluidStack drainStack = fluidHandler.drain(Integer.MAX_VALUE, false); if (drainStack != null && exportFluids.fill(drainStack, false) == drainStack.amount) { exportFluids.fill(drainStack, true); fluidHandler.drain(drainStack.amount, true); this.fluidSourceBlocks.remove(fluidBlockPos); energyContainer.changeEnergy(-GTValues.V[getTier()]); } } }
Example #10
Source File: TileEntityEnderFurnace.java From enderutilities with GNU Lesser General Public License v3.0 | 6 votes |
/** * Uses one dose (1000 mB) of fluid fuel, returns the amount of burn time that was gained from it. * @param stack * @return burn time gained, in ticks */ private static int consumeFluidFuelDosage(ItemStack stack) { if (itemContainsFluidFuel(stack) == false) { return 0; } // All the null checks happened already in itemContainsFluidFuel() IFluidHandler handler = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null); // Consume max 1000 mB per use. FluidStack fluidStack = handler.drain(new FluidStack(FluidRegistry.LAVA, Fluid.BUCKET_VOLUME), true); //System.out.printf("consumeFluidFuelDosageFluidCapability: %s - %d\n", (fluidStack != null ? fluidStack.getFluid().getName() : "null"), fluidStack != null ? fluidStack.amount : 0); // 1.5 times vanilla lava fuel value (150 items per bucket) return fluidStack != null ? (fluidStack.amount * 15 * COOKTIME_DEFAULT / 100) : 0; }
Example #11
Source File: CoverPump.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
public static int moveHandlerFluids(IFluidHandler sourceHandler, IFluidHandler destHandler, int transferLimit, Predicate<FluidStack> fluidFilter) { int fluidLeftToTransfer = transferLimit; for (IFluidTankProperties tankProperties : sourceHandler.getTankProperties()) { FluidStack currentFluid = tankProperties.getContents(); if (currentFluid == null || currentFluid.amount == 0 || !fluidFilter.test(currentFluid)) continue; currentFluid.amount = fluidLeftToTransfer; FluidStack fluidStack = sourceHandler.drain(currentFluid, false); if (fluidStack == null || fluidStack.amount == 0) continue; int canInsertAmount = destHandler.fill(fluidStack, false); if (canInsertAmount > 0) { fluidStack.amount = canInsertAmount; fluidStack = sourceHandler.drain(fluidStack, true); if (fluidStack != null && fluidStack.amount > 0) { destHandler.fill(fluidStack, true); fluidLeftToTransfer -= fluidStack.amount; if (fluidLeftToTransfer == 0) break; } } } return transferLimit - fluidLeftToTransfer; }
Example #12
Source File: ItemBlockFluidTank.java From AdvancedRocketry with MIT License | 6 votes |
@Override public boolean placeBlockAt(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, IBlockState newState) { super.placeBlockAt(stack, player, world, pos, side, hitX, hitY, hitZ, newState); TileEntity tile = world.getTileEntity(pos); if(tile != null && tile instanceof TileFluidTank) { IFluidHandler handler = tile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, EnumFacing.DOWN); ItemStack stack2 = stack.copy(); stack2.setCount(1); handler.fill(drain(stack2, Integer.MAX_VALUE), true); } return true; }
Example #13
Source File: TileAtmosphereTerraformer.java From AdvancedRocketry with MIT License | 6 votes |
@Override public List<ModuleBase> getModules(int ID, EntityPlayer player) { List<ModuleBase> modules = super.getModules(ID, player); //Backgrounds if(world.isRemote) { modules.add(new ModuleImage(173, 0, new IconResource(90, 0, 84, 88, CommonResources.genericBackground))); } modules.add(radioButton); modules.add(new ModuleProgress(30, 57, 0, zmaster587.advancedRocketry.inventory.TextureResources.terraformProgressBar, this)); modules.add(text); setText(); modules.add(new ModuleLimitedSlotArray(150, 114, this, 0, 1)); int i = 0; modules.add(new ModuleText(180, 10, "Gas Status", 0x282828)); for(IFluidHandler tile : fluidInPorts) { modules.add(new ModuleLiquidIndicator(180 + i*16, 30, tile)); i++; } return modules; }
Example #14
Source File: TileEntityFluidPipeTickable.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
public static void pushFluidsFromTank(IPipeTile<FluidPipeType, FluidPipeProperties> pipeTile) { PooledMutableBlockPos blockPos = PooledMutableBlockPos.retain(); int blockedConnections = pipeTile.getBlockedConnections(); BlockFluidPipe blockFluidPipe = (BlockFluidPipe) pipeTile.getPipeBlock(); for (EnumFacing side : EnumFacing.VALUES) { if ((blockedConnections & 1 << side.getIndex()) > 0) { continue; //do not dispatch energy to blocked sides } blockPos.setPos(pipeTile.getPipePos()).move(side); if (!pipeTile.getPipeWorld().isBlockLoaded(blockPos)) { continue; //do not allow cables to load chunks } TileEntity tileEntity = pipeTile.getPipeWorld().getTileEntity(blockPos); if (tileEntity == null) { continue; //do not emit into multiparts or other fluid pipes } IFluidHandler sourceHandler = pipeTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); IFluidHandler receiverHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side.getOpposite()); if (sourceHandler != null && receiverHandler != null && blockFluidPipe.canPushIntoFluidHandler(pipeTile, tileEntity, sourceHandler, receiverHandler)) { CoverPump.moveHandlerFluids(sourceHandler, receiverHandler, Integer.MAX_VALUE, FLUID_FILTER_ALWAYS_TRUE); } } blockPos.release(); }
Example #15
Source File: BlockFluidPipe.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override protected int getActiveVisualConnections(IPipeTile<FluidPipeType, FluidPipeProperties> selfTile) { int activeNodeConnections = 0; for (EnumFacing side : EnumFacing.VALUES) { BlockPos offsetPos = selfTile.getPipePos().offset(side); TileEntity tileEntity = selfTile.getPipeWorld().getTileEntity(offsetPos); if(tileEntity != null) { EnumFacing opposite = side.getOpposite(); IFluidHandler sourceHandler = selfTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); IFluidHandler receivedHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, opposite); if (sourceHandler != null && receivedHandler != null) { activeNodeConnections |= 1 << side.getIndex(); } } } return activeNodeConnections; }
Example #16
Source File: BlockFluidPipe.java From GregTech with GNU Lesser General Public License v3.0 | 6 votes |
@Override public int getActiveNodeConnections(IBlockAccess world, BlockPos nodePos, IPipeTile<FluidPipeType, FluidPipeProperties> selfTileEntity) { int activeNodeConnections = 0; for (EnumFacing side : EnumFacing.VALUES) { BlockPos offsetPos = nodePos.offset(side); TileEntity tileEntity = world.getTileEntity(offsetPos); if(tileEntity != null) { EnumFacing opposite = side.getOpposite(); IFluidHandler sourceHandler = selfTileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); IFluidHandler receivedHandler = tileEntity.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, opposite); if (sourceHandler != null && receivedHandler != null && canPushIntoFluidHandler(selfTileEntity, tileEntity, sourceHandler, receivedHandler)) { activeNodeConnections |= 1 << side.getIndex(); } } } return activeNodeConnections; }
Example #17
Source File: TileFluidTank.java From AdvancedRocketry with MIT License | 6 votes |
@Override public int fill(FluidStack resource, boolean doFill) { if(resource == null) return 0; IFluidHandler handler = this.getFluidTankInDirection(EnumFacing.DOWN); int amt = 0; if(handler != null) { amt = handler.fill(resource, doFill); } //Copy to avoid modifiying the passed one FluidStack resource2 = resource.copy(); resource2.amount -= amt; if(resource2.amount > 0) amt += super.fill(resource2, doFill); if(amt > 0 && doFill) fluidChanged = true; checkForUpdate(); return amt; }
Example #18
Source File: TileGenericPipe.java From Logistics-Pipes-2 with MIT License | 6 votes |
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; }
Example #19
Source File: GTTileTranslocatorFluid.java From GT-Classic with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void onBufferTick() { BlockPos importPos = this.pos.offset(this.getFacing().getOpposite()); BlockPos exportPos = this.pos.offset(this.getFacing()); if (!world.isBlockLoaded(importPos) || !world.isBlockLoaded(exportPos)) { return; } IFluidHandler start = FluidUtil.getFluidHandler(world, importPos, getFacing()); IFluidHandler end = FluidUtil.getFluidHandler(world, exportPos, getFacing().getOpposite()); boolean canExport = start != null && end != null; if (canExport && filter == null) { FluidUtil.tryFluidTransfer(end, start, 500, true); } if (canExport && filter != null) { FluidStack fake = FluidUtil.tryFluidTransfer(end, start, 500, false); if (fake != null && (fake.getFluid().getName().equals(filter.getFluid().getName()))) { FluidUtil.tryFluidTransfer(end, start, 500, true); } } }
Example #20
Source File: TileRocketFluidUnloader.java From AdvancedRocketry with MIT License | 5 votes |
@Override public void update() { //Move a stack of items if( !world.isRemote && rocket != null ) { boolean isAllowToOperate = (inputstate == RedstoneState.OFF || isStateActive(inputstate, getStrongPowerForSides(world, getPos()))); List<TileEntity> tiles = rocket.storage.getFluidTiles(); boolean rocketContainsItems = false; //Function returns if something can be moved for(TileEntity tile : tiles) { IFluidHandler handler = (IFluidHandler)tile; if(handler.drain( 1, false) != null) rocketContainsItems = true; if(isAllowToOperate) { FluidStack stack = fluidTank.getFluid(); if(stack == null) { this.fill(handler.drain(fluidTank.getCapacity(), true), true); } else { stack = stack.copy(); stack.amount = fluidTank.getCapacity() - fluidTank.getFluidAmount(); if(stack.amount != 0) { this.fill(handler.drain( stack, true), true); } } } } //Update redstone state setRedstoneState(!rocketContainsItems); } }
Example #21
Source File: TileRollingMachine.java From AdvancedRocketry with MIT License | 5 votes |
@Override public boolean canProcessRecipe(IRecipe recipe) { if(!fluidInPorts.isEmpty()) { IFluidHandler fluidHandler = fluidInPorts.get(0); FluidStack fluid; if(fluidHandler == null || (fluid = fluidHandler.drain(new FluidStack(FluidRegistry.WATER, 100), false)) == null || fluid.amount != 100) return false; } return super.canProcessRecipe(recipe); }
Example #22
Source File: CompatibilityUtils.java From OpenModsLib with MIT License | 5 votes |
@Nullable public static IFluidHandler getFluidHandler(TileEntity te, EnumFacing side) { if (te == null) return null; final IFluidHandler nativeCapability = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side); if (nativeCapability != null) return nativeCapability; return null; }
Example #23
Source File: ItemEnderBucket.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public IFluidHandler getLinkedTank(ItemStack stack) { TargetData targetData = this.getLinkedTankTargetData(stack); MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance(); if (targetData != null && server != null) { World world = server.getWorld(targetData.dimension); if (world != null) { // Force load the target chunk where the tank is located with a 30 second unload delay. if (ChunkLoading.getInstance().loadChunkForcedWithModTicket(targetData.dimension, targetData.pos.getX() >> 4, targetData.pos.getZ() >> 4, 30)) { TileEntity te = world.getTileEntity(targetData.pos); if (te != null && te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetData.facing)) { return te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, targetData.facing); } } } } return null; }
Example #24
Source File: ItemEnderBucket.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
public FluidStack getFluid(ItemStack stack, @Nullable EntityPlayer player) { NBTTagCompound nbt = stack.getTagCompound(); if (nbt == null) { return null; } // The Bucket has been linked to a tank if (LinkMode.fromStack(stack) == LinkMode.ENABLED) { if (OwnerData.canAccessSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL, player) == false) { return null; } IFluidHandler handler = this.getLinkedTank(stack); if (handler != null) { FluidStack fluidStack = handler.drain(Integer.MAX_VALUE, false); // Cache the fluid stack into the link crystal's NBT for easier/faster access for tooltip and rendering stuffs this.cacheFluid(stack, fluidStack); return fluidStack; } return null; } // Not linked to a tank, get the internal FluidStack if (nbt.hasKey("Fluid", Constants.NBT.TAG_COMPOUND)) { return FluidStack.loadFluidStackFromNBT(nbt.getCompoundTag("Fluid")); } return null; }
Example #25
Source File: ItemEnderBucket.java From enderutilities with GNU Lesser General Public License v3.0 | 5 votes |
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); } } }
Example #26
Source File: TileRocketFluidLoader.java From AdvancedRocketry with MIT License | 5 votes |
@Override public void update() { //Move a stack of items if(!world.isRemote && rocket != null) { boolean isAllowToOperate = (inputstate == RedstoneState.OFF || isStateActive(inputstate, getStrongPowerForSides(world, getPos()))); List<TileEntity> tiles = rocket.storage.getFluidTiles(); boolean rocketContainsItems = false; //Function returns if something can be moved for(TileEntity tile : tiles) { IFluidHandler handler = (IFluidHandler)tile; //See if we have anything to fill because redstone output FluidStack stack = handler.drain(1, false); if(stack == null || handler.fill(stack, false) > 0) rocketContainsItems = true; if(isAllowToOperate) { stack = fluidTank.drain(fluidTank.getCapacity(), false); if(stack != null && stack.amount > 0) fluidTank.drain(handler.fill(stack, true), true); } } //Update redstone state setRedstoneState(!rocketContainsItems); } }
Example #27
Source File: TileFluidTank.java From AdvancedRocketry with MIT License | 5 votes |
@Override protected boolean useBucket(int slot, ItemStack stack) { boolean bucketUsed = super.useBucket(slot, stack); if(bucketUsed) { IFluidHandler handler = getFluidTankInDirection(EnumFacing.DOWN); if(handler != null) { FluidStack othertank = handler.getTankProperties()[0].getContents(); if(othertank == null || (othertank.amount < handler.getTankProperties()[0].getCapacity())) fluidTank.drain(handler.fill(fluidTank.getFluid(), true),true); } } return bucketUsed; }
Example #28
Source File: TileFluidTank.java From AdvancedRocketry with MIT License | 5 votes |
@Override public FluidStack drain(int maxDrain, boolean doDrain) { IFluidHandler handler = this.getFluidTankInDirection(EnumFacing.UP); FluidStack stack = null; if(handler != null && handler.getTankProperties()[0].getContents() != null && fluidTank.getFluid() != null && fluidTank.getFluid().getFluid() == handler.getTankProperties()[0].getContents().getFluid()) { stack = handler.drain(maxDrain, doDrain); } if(stack != null) return stack; FluidStack stack2 = super.drain(maxDrain - (stack != null ? stack.amount : 0), doDrain); if(stack != null && stack2 != null) stack2.amount += stack.amount; if(stack2 != null && doDrain) { fluidChanged = true; } checkForUpdate(); return stack2; }
Example #29
Source File: InjectorTileEntity.java From EmergingTechnology with MIT License | 5 votes |
private void pushToFluidConsumers() { for (EnumFacing facing : EnumFacing.VALUES) { if (this.getNutrientFluid() < EmergingTechnologyConfig.HYDROPONICS_MODULE.INJECTOR.injectorFluidTransferRate) { return; } TileEntity neighbour = this.world.getTileEntity(this.pos.offset(facing)); // Return if no tile entity if (neighbour == null) { continue; } IFluidHandler neighbourFluidHandler = neighbour .getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing.getOpposite()); // Return if neighbour has no fluid tank if (neighbourFluidHandler == null) { continue; } // Fill the neighbour int filled = neighbourFluidHandler.fill(new FluidStack(ModFluids.NUTRIENT, EmergingTechnologyConfig.HYDROPONICS_MODULE.INJECTOR.injectorFluidTransferRate), true); this.nutrientFluidHandler.drain(filled, true); } }
Example #30
Source File: TileEnderTank.java From EnderStorage with MIT License | 5 votes |
private void ejectLiquid() { IFluidHandler source = getStorage(); for (Direction side : Direction.BY_INDEX) { IFluidHandler dest = capCache.getCapabilityOr(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, side, EmptyFluidHandler.INSTANCE); FluidStack drain = source.drain(100, IFluidHandler.FluidAction.SIMULATE); if (!drain.isEmpty()) { int qty = dest.fill(drain, IFluidHandler.FluidAction.EXECUTE); if (qty > 0) { source.drain(qty, IFluidHandler.FluidAction.EXECUTE); } } } }