Java Code Examples for net.minecraftforge.fluids.FluidStack#copy()
The following examples show how to use
net.minecraftforge.fluids.FluidStack#copy() .
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: 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 2
Source File: FluidHelper.java From BigReactors with MIT License | 6 votes |
public int fill(int idx, FluidStack incoming, boolean doFill) { if(incoming == null || idx < 0 || idx >= fluids.length) { return 0; } if(!canAddToStack(idx, incoming)) { return 0; } int amtToAdd = Math.min(incoming.amount, getRemainingSpaceForFluid(idx)); if(amtToAdd <= 0) { return 0; } if(!doFill) { return amtToAdd; } if(fluids[idx] == null) { fluids[idx] = incoming.copy(); fluids[idx].amount = amtToAdd; } else { fluids[idx].amount += amtToAdd; } return amtToAdd; }
Example 3
Source File: LogisticsManager.java From PneumaticCraft with GNU General Public License v3.0 | 6 votes |
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 instanceof IFluidHandler) { IFluidHandler fluidHandler = (IFluidHandler)te; for(ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) { int fluidFilled = fluidHandler.fill(d, remainder, false); if(fluidFilled > 0) { remainder.amount -= fluidFilled; break; } } } providingStack.amount -= remainder.amount; if(providingStack.amount <= 0) return 0; return providingStack.amount; }
Example 4
Source File: FluidHelper.java From BigReactors with MIT License | 6 votes |
public FluidStack drain(int idx, FluidStack resource, boolean doDrain) { if(resource == null || resource.amount <= 0 || idx < 0 || idx >= fluids.length) { return null; } Fluid existingFluid = getFluidType(idx); if(existingFluid == null || existingFluid.getID() != resource.getFluid().getID()) { return null; } FluidStack drained = resource.copy(); if(!doDrain) { drained.amount = Math.min(resource.amount, getFluidAmount(idx)); } else { drained.amount = drainFluidFromStack(idx, resource.amount); } return drained; }
Example 5
Source File: GenericTank.java From OpenModsLib with MIT License | 5 votes |
private static int tryFillNeighbour(FluidStack drainedFluid, EnumFacing side, TileEntity otherTank) { final FluidStack toFill = drainedFluid.copy(); final EnumFacing fillSide = side.getOpposite(); final IFluidHandler fluidHandler = CompatibilityUtils.getFluidHandler(otherTank, fillSide); return fluidHandler != null? fluidHandler.fill(toFill, true) : 0; }
Example 6
Source File: FluidPipeNet.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override protected void transferNodeData(Map<BlockPos, Node<FluidPipeProperties>> transferredNodes, PipeNet<FluidPipeProperties> parentNet1) { super.transferNodeData(transferredNodes, parentNet1); FluidPipeNet parentNet = (FluidPipeNet) parentNet1; FluidStack parentFluid = parentNet.getFluidNetTank().getFluid(); if (parentFluid != null && parentFluid.amount > 0) { if (parentNet.getAllNodes().isEmpty()) { //if this is merge of pipe nets, just add all fluid to our internal tank //use fillInternal to ignore throughput restrictions getFluidNetTank().fillInternal(parentFluid, true); } else { //otherwise, it is donating of some nodes to our net in result of split //so, we should estabilish equal amount of fluid in networks int firstNetCapacity = getAllNodes().size() * getNodeData().throughput; int secondNetCapacity = parentNet.getAllNodes().size() * parentNet.getNodeData().throughput; int totalFluidAmount = getFluidNetTank().getFluidAmount() + parentFluid.amount; int fluidAmount1 = totalFluidAmount * firstNetCapacity / (firstNetCapacity + secondNetCapacity); int fluidAmount2 = totalFluidAmount - fluidAmount1; if (fluidAmount1 > 0) { FluidStack fluidStack1 = parentFluid.copy(); fluidStack1.amount = fluidAmount1; fluidNetTank.setFluid(fluidStack1); } else fluidNetTank.setFluid(null); if (fluidAmount2 > 0) { FluidStack fluidStack2 = parentFluid.copy(); fluidStack2.amount = fluidAmount2; parentNet.getFluidNetTank().setFluid(fluidStack2); } else parentNet.getFluidNetTank().setFluid(null); } } }
Example 7
Source File: LPRoutedFluid.java From Logistics-Pipes-2 with MIT License | 5 votes |
public LPRoutedFluid(double x, double y, double z, FluidStack content, EnumFacing initVector, TileGenericPipe holder, Deque<EnumFacing> routingInfo, TileGenericPipe destination) { setHeading(initVector); setHolding(holder); route = routingInfo; ticks = 0; this.stack = content.copy(); this.position=new Triple<Double, Double, Double>(x, y, z); ID=UUID.randomUUID(); this.destination = destination; }
Example 8
Source File: MetaTileEntityTank.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
private void handleTankSyncing() { if (networkStatus == NetworkStatus.ATTACHED_TO_MULTIBLOCK) { writeCustomData(1, buf -> buf.writeBlockPos(controllerPos)); this.needsFluidResync = false; this.networkStatus = null; this.needsShapeResync = false; } if (networkStatus == NetworkStatus.DETACHED_FROM_MULTIBLOCK) { writeCustomData(2, buf -> {}); this.networkStatus = null; } if (isTankController() && needsShapeResync) { writeCustomData(4, buf -> { ByteBufUtils.writeRelativeBlockList(buf, getPos(), connectedTanks); buf.writeBlockPos(new BlockPos(multiblockSize)); }); this.needsShapeResync = false; } if (isTankController() && needsFluidResync) { if (timeSinceLastFluidSync++ >= FLUID_SYNC_THROTTLE) { FluidStack fluidStack = multiblockFluidTank.getFluid(); writeCustomData(3, buf -> ByteBufUtils.writeFluidStackDelta(buf, lastSentFluidStack, fluidStack)); this.lastSentFluidStack = fluidStack == null ? null : fluidStack.copy(); this.timeSinceLastFluidSync = 0; this.needsFluidResync = false; } } }
Example 9
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 10
Source File: BetterTank.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
@Override public FluidStack getFluid() { FluidStack fs = super.getFluid(); if (fs != null && fs.amount > getCapacity()) { fs = fs.copy(); fs.amount = getCapacity(); } return fs; }
Example 11
Source File: WatchedFluidTank.java From GregTech with GNU Lesser General Public License v3.0 | 5 votes |
@Override public final void onContentsChanged() { FluidStack newFluidStack = getFluid(); if (hasFluidChanged(newFluidStack, oldFluidStack)) { onFluidChanged(newFluidStack, oldFluidStack); if (oldFluidStack != null && oldFluidStack.isFluidEqual(newFluidStack)) { //noinspection ConstantConditions oldFluidStack.amount = newFluidStack.amount; } else { this.oldFluidStack = newFluidStack == null ? null : newFluidStack.copy(); } } }
Example 12
Source File: SimpleFluidFilter.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
public void setFluidInSlot(int slotIndex, FluidStack fluidStack) { this.fluidFilterSlots[slotIndex] = fluidStack == null ? null : fluidStack.copy(); }
Example 13
Source File: SyncedField.java From Signals with GNU General Public License v3.0 | 4 votes |
@Override protected FluidStack copyWhenNecessary(FluidStack oldValue){ return oldValue.copy(); }
Example 14
Source File: FuelRecipe.java From GregTech with GNU Lesser General Public License v3.0 | 4 votes |
public FuelRecipe(FluidStack recipeFluid, int duration, long minVoltage) { this.recipeFluid = recipeFluid.copy(); this.duration = duration; this.minVoltage = minVoltage; }
Example 15
Source File: PositionedFluidTank.java From NEI-Integration with MIT License | 4 votes |
public PositionedFluidTank(FluidStack fluid, int capacity, Rectangle position, String overlayTexture, Point overlayTexturePos) { this(new FluidTank(fluid != null ? fluid.copy() : null, capacity), position, overlayTexture, overlayTexturePos); }
Example 16
Source File: FluidUtils.java From CodeChickenCore with MIT License | 4 votes |
public static FluidStack copy(FluidStack liquid, int quantity) { liquid = liquid.copy(); liquid.amount = quantity; return liquid; }
Example 17
Source File: ItemEnderBucket.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
public int getCapacityAvailable(ItemStack stack, FluidStack fluidStackIn, EntityPlayer player) { FluidStack existingFluidStack; // Linked to a tank if (LinkMode.fromStack(stack) == LinkMode.ENABLED) { IFluidHandler handler = this.getLinkedTank(stack); if (handler != null) { IFluidTankProperties[] tank = handler.getTankProperties(); if (tank == null || tank.length < 1 || tank[0] == null) { return 0; } existingFluidStack = tank[0].getContents(); if (fluidStackIn == null) { return tank[0].getCapacity() - (existingFluidStack != null ? existingFluidStack.amount : 0); } else { fluidStackIn = fluidStackIn.copy(); fluidStackIn.amount = Integer.MAX_VALUE; return handler.fill(fluidStackIn, false); } } return 0; } // Not linked to a tank, get the bucket's internal free capacity existingFluidStack = this.getFluid(stack, player); if (existingFluidStack != null) { return this.getCapacity(stack, player) - existingFluidStack.amount; } return this.getCapacity(stack, player); }
Example 18
Source File: ItemEnderBucket.java From enderutilities with GNU Lesser General Public License v3.0 | 4 votes |
public int getCapacity(ItemStack stack, @Nullable EntityPlayer player) { if (LinkMode.fromStack(stack) == LinkMode.DISABLED) { return Configs.enderBucketCapacity; } // Linked to a tank if (OwnerData.canAccessSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL, player) == false) { return 0; } TargetData targetData = this.getLinkedTankTargetData(stack); IFluidHandler handler = this.getLinkedTank(stack); if (targetData != null && handler != null) { IFluidTankProperties[] tank = handler.getTankProperties(); // If we have tank info, it is the easiest and simplest way to get the tank capacity if (tank != null && tank.length > 0 && tank[0] != null) { return tank[0].getCapacity(); } // No tank info available, get the capacity via simulating filling FluidStack fluidStack = handler.drain(Integer.MAX_VALUE, false); // Tank has fluid if (fluidStack != null) { FluidStack fs = fluidStack.copy(); fs.amount = Integer.MAX_VALUE; // Filled amount plus existing amount return handler.fill(fs, false) + fluidStack.amount; } // Tank has no fluid else { // Since we have no fluid stored, get the capacity via simulating filling water into the tank return handler.fill(new FluidStack(FluidRegistry.WATER, Integer.MAX_VALUE), false); } } return 0; }
Example 19
Source File: SyncableTank.java From OpenModsLib with MIT License | 4 votes |
@Override public FluidStack getValue() { FluidStack stack = super.getFluid(); return stack != null? stack.copy() : null; }
Example 20
Source File: SyncedField.java From PneumaticCraft with GNU General Public License v3.0 | 4 votes |
@Override protected FluidStack copyWhenNecessary(FluidStack oldValue){ return oldValue.copy(); }