List of usage examples for net.minecraftforge.fluids FluidUtil getFluidHandler
public static LazyOptional<IFluidHandler> getFluidHandler(World world, BlockPos blockPos, @Nullable Direction side)
From source file:blusunrize.immersiveengineering.common.blocks.metal.TileEntityMixer.java
@Override public void update() { super.update(); if (isDummy() || isRSDisabled()) return;/*from w ww . j ava 2 s.c om*/ if (world.isRemote) { if (shouldRenderAsActive()) { if (Utils.RAND.nextInt(8) == 0) { FluidStack fs = !tank.fluids.isEmpty() ? tank.fluids.get(0) : null; if (fs != null) { float amount = tank.getFluidAmount() / (float) tank.getCapacity() * 1.125f; Vec3d partPos = new Vec3d( getPos().getX() + .5f + facing.getXOffset() * .5f + (mirrored ? facing.rotateYCCW() : facing.rotateY()).getXOffset() * .5f, getPos().getY() - .0625f + amount, getPos().getZ() + .5f + facing.getZOffset() * .5f + (mirrored ? facing.rotateYCCW() : facing.rotateY()).getZOffset() * .5f); float r = Utils.RAND.nextFloat() * .8125f; float angleRad = (float) Math.toRadians(animation_agitator); partPos = partPos.add(r * Math.cos(angleRad), 0, r * Math.sin(angleRad)); if (Utils.RAND.nextBoolean()) ImmersiveEngineering.proxy.spawnBubbleFX(world, fs, partPos.x, partPos.y, partPos.z, 0, 0, 0); else ImmersiveEngineering.proxy.spawnFluidSplashFX(world, fs, partPos.x, partPos.y, partPos.z, 0, 0, 0); } } animation_agitator = (animation_agitator + 9) % 360; } } else { boolean update = false; boolean foundRecipe = false; if (energyStorage.getEnergyStored() > 0 && processQueue.size() < this.getProcessQueueMaxLength()) { int tankAmount = tank.getFluidAmount(); if (tankAmount > 0) { Set<Integer> usedInvSlots = new HashSet<Integer>(); for (MultiblockProcess<MixerRecipe> process : processQueue) if (process instanceof MultiblockProcessInMachine) for (int i : ((MultiblockProcessInMachine<MixerRecipe>) process).inputSlots) usedInvSlots.add(i); NonNullList<ItemStack> components = NonNullList.withSize(this.inventory.size(), ItemStack.EMPTY); for (int i = 0; i < components.size(); i++) if (!usedInvSlots.contains(i)) components.set(i, inventory.get(i)); for (FluidStack fs : tank.fluids) { MixerRecipe recipe = MixerRecipe.findRecipe(fs, components); if (recipe != null) { foundRecipe = true; MultiblockProcessInMachine process = new MultiblockProcessMixer(recipe, recipe.getUsedSlots(fs, components)).setInputTanks(0); if (this.addProcessToQueue(process, true)) { this.addProcessToQueue(process, false); update = true; } } } } } if (this.tank.getFluidTypes() > 1 || !foundRecipe || outputAll) { BlockPos outputPos = this.getPos().down().offset(facing.getOpposite(), 2); IFluidHandler output = FluidUtil.getFluidHandler(world, outputPos, facing); if (output != null) { if (!outputAll) { FluidStack inTank = this.tank.getFluid(); if (inTank != null) { FluidStack out = Utils.copyFluidStackWithAmount(inTank, Math.min(inTank.amount, 80), false); int accepted = output.fill(out, false); if (accepted > 0) { int drained = output.fill( Utils.copyFluidStackWithAmount(out, Math.min(out.amount, accepted), false), true); this.tank.drain(drained, true); update = true; } } } else { int totalOut = 0; Iterator<FluidStack> it = this.tank.fluids.iterator(); while (it.hasNext()) { FluidStack fs = it.next(); if (fs != null) { FluidStack out = Utils.copyFluidStackWithAmount(fs, Math.min(fs.amount, 80 - totalOut), false); int accepted = output.fill(out, false); if (accepted > 0) { int drained = output.fill(Utils.copyFluidStackWithAmount(out, Math.min(out.amount, accepted), false), true); MultiFluidTank.drain(drained, fs, it, true); totalOut += drained; update = true; } if (totalOut >= 80) break; } } } } } if (update) { this.markDirty(); this.markContainingBlockForUpdate(null); } } }
From source file:blusunrize.immersiveengineering.common.blocks.metal.TileEntitySheetmetalTank.java
@Override public void update() { ApiUtils.checkForNeedlessTicking(this); if (pos == 4 && !world.isRemote && world.getRedstonePowerFromNeighbors(getPos()) > 0) for (int i = 0; i < 6; i++) if (i != 1 && tank.getFluidAmount() > 0) { EnumFacing f = EnumFacing.byIndex(i); int outSize = Math.min(144, tank.getFluidAmount()); FluidStack out = Utils.copyFluidStackWithAmount(tank.getFluid(), outSize, false); BlockPos outputPos = getPos().offset(f); IFluidHandler output = FluidUtil.getFluidHandler(world, outputPos, f.getOpposite()); if (output != null) { int accepted = output.fill(out, false); if (accepted > 0) { int drained = output.fill( Utils.copyFluidStackWithAmount(out, Math.min(out.amount, accepted), false), true);//from w w w.j a va 2 s .c o m this.tank.drain(drained, true); this.markContainingBlockForUpdate(null); updateComparatorValuesPart2(); } } } }
From source file:com.buuz135.industrial.tile.world.FluidPumpTile.java
License:Open Source License
@Override public float work() { if (WorkUtils.isDisabled(this.getBlockType()) || isWorkFinished || fluid == null) return 0; if (tank.getFluidAmount() + 1000 <= tank.getCapacity()) { if (lowestY == this.pos.getY()) { isWorkFinished = true;/*from w w w .ja va 2s .c om*/ allBlocks = null; return 0; } if (allBlocks == null || allBlocks.isEmpty()) { fillCache(); } BlockPos peeked = allBlocks.peek(); while (!allBlocks.isEmpty() && (this.world.isOutsideBuildHeight(peeked) || !isBlockSameFluid(peeked) || this.world.getBlockState(peeked).getBlock() .getMetaFromState(this.world.getBlockState(peeked)) != 0)) { allBlocks.poll(); if (!allBlocks.isEmpty()) peeked = allBlocks.peek(); } if (peeked == null) return 0; if (this.world.getTileEntity(peeked) != null) return 0; IFluidHandler handler = FluidUtil.getFluidHandler(this.world, peeked, null); FluidStack fluid = handler.drain(1000, true); if (fluid != null) { if (BlockRegistry.fluidPumpBlock.isReplaceFluidWithCobble()) { if (this.world.setBlockState(peeked, Blocks.COBBLESTONE.getDefaultState())) { tank.fill(fluid, true); } } else if (world.setBlockToAir(peeked)) { tank.fill(fluid, true); } } else { return 0; } allBlocks.poll(); return 1; } return 0; }
From source file:com.lothrazar.cyclicmagic.block.cablepump.fluid.TileEntityFluidPump.java
License:Open Source License
/** * for every side connected to me pull fluid in from it UNLESS its my current facing direction. for THAT side, i push fluid out from me pull first then push * * TODO: UtilFluid that does a position, a facing, and tries to move fluid across * * *//* ww w. jav a 2s . c o m*/ @Override public void update() { if (this.isPowered() == false && this.onlyRunIfPowered()) { return;//i am not powered, and i require it } //incoming target side BlockPos target = pos.offset(this.getCurrentFacing()); UtilFluid.tryFillTankFromPosition(world, target, this.getCurrentFacing().getOpposite(), tank, transferRate); if ( // world.containsAnyLiquid(new AxisAlignedBB(target)) || world.getBlockState(target).getMaterial().isLiquid()) { //here // IBlockState currentState = world.getBlockState(target); UtilParticle.spawnParticle(world, EnumParticleTypes.WATER_BUBBLE, target); IFluidHandler handle = FluidUtil.getFluidHandler(world, target, EnumFacing.UP); FluidStack fs = handle.getTankProperties()[0].getContents(); if (fs != null && this.tank.canFillFluidType(fs)) { this.tank.fill(fs, true); } } //eXPORT: now try to DEPOSIT fluid next door List<EnumFacing> sidesOut = getSidesNotFacing(); Collections.shuffle(sidesOut); for (EnumFacing exportToSide : sidesOut) { moveItems(exportToSide); } }
From source file:com.lothrazar.cyclicmagic.block.fluiddrain.TileEntityFluidDrain.java
License:Open Source License
@Override public void update() { this.shiftAllUp(); if (this.isRunning() == false || this.tank.isFull() || this.getStackInSlot(0).getItem() instanceof ItemBlock == false) { return;/*from w w w.jav a 2 s .com*/ } if (shape == null) { shape = this.getShape(); } //look for fluid if (this.shapePtr >= shape.size()) { shapePtr = 0; return; } BlockPos current = shape.get(shapePtr); shapePtr++; IBlockState currentState = world.getBlockState(current); if (currentState.getMaterial().isLiquid() && this.updateEnergyIsBurning()) { UtilParticle.spawnParticle(world, EnumParticleTypes.WATER_BUBBLE, current); IFluidHandler handle = FluidUtil.getFluidHandler(world, current, EnumFacing.UP); FluidStack fs = handle.getTankProperties()[0].getContents(); if (fs == null || tank.canFillFluidType(fs) == false) { return; } this.tank.fill(fs, true); UtilPlaceBlocks.placeItemblock(world, current, this.getStackInSlot(0), null); } }
From source file:com.lothrazar.cyclicmagic.util.UtilFluid.java
License:Open Source License
/** * Look for a fluid handler with gien position and direction try to extract from that pos and fill the tank * // w w w .j a va 2 s.co m * * @param world * @param posSide * @param sideOpp * @param tankTo * @param amount * @return */ public static boolean tryFillTankFromPosition(World world, BlockPos posSide, EnumFacing sideOpp, FluidTank tankTo, final int amount) { try { IFluidHandler fluidFrom = FluidUtil.getFluidHandler(world, posSide, sideOpp); if (fluidFrom != null) { //its not my facing dir // SO: pull fluid from that into myself FluidStack wasDrained = fluidFrom.drain(amount, false); if (wasDrained == null) { return false; } int filled = tankTo.fill(wasDrained, false); if (wasDrained != null && wasDrained.amount > 0 && filled > 0) { int realAmt = Math.min(filled, wasDrained.amount); wasDrained = fluidFrom.drain(realAmt, true); if (wasDrained == null) { return false; } return tankTo.fill(wasDrained, true) > 0; } } return false; } catch (Exception e) { ModCyclic.logger.error("External fluid block had an issue when we tried to drain", e); //charset crashes here i guess //https://github.com/PrinceOfAmber/Cyclic/issues/605 // https://github.com/PrinceOfAmber/Cyclic/issues/605https://pastebin.com/YVtMYsF6 return false; } }
From source file:com.lothrazar.cyclicmagic.util.UtilFluid.java
License:Open Source License
public static boolean tryFillPositionFromTank(World world, BlockPos posSide, EnumFacing sideOpp, FluidTank tankFrom, int amount) { try {/*from w w w .j av a 2 s . c o m*/ IFluidHandler fluidTo = FluidUtil.getFluidHandler(world, posSide, sideOpp); if (fluidTo != null) { //its not my facing dir // SO: pull fluid from that into myself FluidStack wasDrained = tankFrom.drain(amount, false); if (wasDrained == null) { return false; } int filled = fluidTo.fill(wasDrained, false); if (wasDrained != null && wasDrained.amount > 0 && filled > 0) { int realAmt = Math.min(filled, wasDrained.amount); wasDrained = tankFrom.drain(realAmt, true); if (wasDrained == null) { return false; } return fluidTo.fill(wasDrained, true) > 0; } } return false; } catch (Exception e) { ModCyclic.logger.error("A fluid tank had an issue when we tried to fill", e); //charset crashes here i guess //https://github.com/PrinceOfAmber/Cyclic/issues/605 // https://github.com/PrinceOfAmber/Cyclic/issues/605https://pastebin.com/YVtMYsF6 return false; } }