Search in sources :

Example 6 with FluidTank

use of net.minecraftforge.fluids.FluidTank in project MinecraftForge by MinecraftForge.

the class CapabilityFluidHandler method register.

public static void register() {
    CapabilityManager.INSTANCE.register(IFluidHandler.class, new DefaultFluidHandlerStorage<IFluidHandler>(), new Callable<IFluidHandler>() {

        @Override
        public IFluidHandler call() throws Exception {
            return new FluidTank(Fluid.BUCKET_VOLUME);
        }
    });
    CapabilityManager.INSTANCE.register(IFluidHandlerItem.class, new DefaultFluidHandlerStorage<IFluidHandlerItem>(), new Callable<IFluidHandlerItem>() {

        @Override
        public IFluidHandlerItem call() throws Exception {
            return new FluidHandlerItemStack(new ItemStack(Items.BUCKET), Fluid.BUCKET_VOLUME);
        }
    });
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) FluidHandlerItemStack(net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack) FluidHandlerItemStack(net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack) ItemStack(net.minecraft.item.ItemStack)

Example 7 with FluidTank

use of net.minecraftforge.fluids.FluidTank in project LogisticsPipes by RS485.

the class PipeFluidSupplierMk2 method throttledUpdateEntity.

@Override
public void throttledUpdateEntity() {
    if (!isEnabled()) {
        return;
    }
    if (MainProxy.isClient(container.getWorld())) {
        return;
    }
    super.throttledUpdateEntity();
    if (dummyInventory.getStackInSlot(0) == null) {
        return;
    }
    WorldCoordinatesWrapper worldCoordinates = new WorldCoordinatesWrapper(container);
    //@formatter:off
    worldCoordinates.getConnectedAdjacentTileEntities(ConnectionPipeType.ITEM).filter(adjacent -> adjacent.tileEntity instanceof IFluidHandler).filter(adjacent -> SimpleServiceLocator.pipeInformationManager.isItemPipe(adjacent.tileEntity)).map(adjacent -> new Pair<>((IFluidHandler) adjacent.tileEntity, adjacent.direction)).forEach(fluidHandlerDirectionPair -> {
        FluidTankInfo[] tankInfo = fluidHandlerDirectionPair.getValue1().getTankInfo(ForgeDirection.UNKNOWN);
        if (tankInfo == null || tankInfo.length == 0) {
            return;
        }
        Map<FluidIdentifier, Integer> wantFluids = new HashMap<>();
        FluidIdentifier fIdent = FluidIdentifier.get(dummyInventory.getIDStackInSlot(0).getItem());
        wantFluids.put(fIdent, amount);
        HashMap<FluidIdentifier, Integer> haveFluids = new HashMap<>();
        FluidTankInfo[] result = container.getTankInfo(ForgeDirection.UNKNOWN);
        for (FluidTankInfo slot : result) {
            if (slot == null || slot.fluid == null || slot.fluid.getFluidID() == 0 || !wantFluids.containsKey(FluidIdentifier.get(slot.fluid))) {
                continue;
            }
            Integer liquidWant = haveFluids.get(FluidIdentifier.get(slot.fluid));
            if (liquidWant == null) {
                haveFluids.put(FluidIdentifier.get(slot.fluid), slot.fluid.amount);
            } else {
                haveFluids.put(FluidIdentifier.get(slot.fluid), liquidWant + slot.fluid.amount);
            }
        }
        if (fluidHandlerDirectionPair.getValue2().ordinal() < ((PipeFluidTransportLogistics) transport).sideTanks.length) {
            FluidTank centerTank = ((PipeFluidTransportLogistics) transport).sideTanks[fluidHandlerDirectionPair.getValue2().ordinal()];
            if (centerTank != null && centerTank.getFluid() != null && wantFluids.containsKey(FluidIdentifier.get(centerTank.getFluid()))) {
                Integer liquidWant = haveFluids.get(FluidIdentifier.get(centerTank.getFluid()));
                if (liquidWant == null) {
                    haveFluids.put(FluidIdentifier.get(centerTank.getFluid()), centerTank.getFluid().amount);
                } else {
                    haveFluids.put(FluidIdentifier.get(centerTank.getFluid()), liquidWant + centerTank.getFluid().amount);
                }
            }
        }
        FluidTank centerTank = ((PipeFluidTransportLogistics) transport).internalTank;
        if (centerTank != null && centerTank.getFluid() != null && wantFluids.containsKey(FluidIdentifier.get(centerTank.getFluid()))) {
            Integer liquidWant = haveFluids.get(FluidIdentifier.get(centerTank.getFluid()));
            if (liquidWant == null) {
                haveFluids.put(FluidIdentifier.get(centerTank.getFluid()), centerTank.getFluid().amount);
            } else {
                haveFluids.put(FluidIdentifier.get(centerTank.getFluid()), liquidWant + centerTank.getFluid().amount);
            }
        }
        for (Entry<FluidIdentifier, Integer> liquidId : wantFluids.entrySet()) {
            Integer haveCount = haveFluids.get(liquidId.getKey());
            if (haveCount != null) {
                liquidId.setValue(liquidId.getValue() - haveCount);
            }
            _requestedItems.entrySet().stream().filter(requestedItem -> requestedItem.getKey().equals(liquidId.getKey())).forEach(requestedItem -> liquidId.setValue(liquidId.getValue() - requestedItem.getValue()));
        }
        setRequestFailed(false);
        for (FluidIdentifier need : wantFluids.keySet()) {
            int countToRequest = wantFluids.get(need);
            if (countToRequest < 1) {
                continue;
            }
            if (_bucketMinimum.getAmount() != 0 && countToRequest < _bucketMinimum.getAmount()) {
                continue;
            }
            if (!useEnergy(11)) {
                break;
            }
            boolean success = false;
            if (_requestPartials) {
                countToRequest = RequestTree.requestFluidPartial(need, countToRequest, this, null);
                if (countToRequest > 0) {
                    success = true;
                }
            } else {
                success = RequestTree.requestFluid(need, countToRequest, this, null);
            }
            if (success) {
                Integer currentRequest = _requestedItems.get(need);
                if (currentRequest == null) {
                    _requestedItems.put(need, countToRequest);
                } else {
                    _requestedItems.put(need, currentRequest + countToRequest);
                }
            } else {
                setRequestFailed(true);
            }
        }
    });
}
Also used : IRequireReliableFluidTransport(logisticspipes.interfaces.routing.IRequireReliableFluidTransport) Getter(lombok.Getter) IRequestFluid(logisticspipes.interfaces.routing.IRequestFluid) Textures(logisticspipes.textures.Textures) LogisticsPipes(logisticspipes.LogisticsPipes) Item(net.minecraft.item.Item) HashMap(java.util.HashMap) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) MainProxy(logisticspipes.proxy.MainProxy) FluidIdentifier(logisticspipes.utils.FluidIdentifier) Map(java.util.Map) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ConnectionPipeType(logisticspipes.routing.pathfinder.IPipeInformationProvider.ConnectionPipeType) ItemIdentifierInventory(logisticspipes.utils.item.ItemIdentifierInventory) TextureType(logisticspipes.textures.Textures.TextureType) PacketHandler(logisticspipes.network.PacketHandler) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) RequestTree(logisticspipes.request.RequestTree) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) FluidSupplierAmount(logisticspipes.network.packets.pipe.FluidSupplierAmount) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Pair(logisticspipes.utils.tuples.Pair) IInventory(net.minecraft.inventory.IInventory) Entry(java.util.Map.Entry) FluidTank(net.minecraftforge.fluids.FluidTank) GuiIDs(logisticspipes.network.GuiIDs) FluidRoutedPipe(logisticspipes.pipes.basic.fluid.FluidRoutedPipe) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) HashMap(java.util.HashMap) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) FluidTank(net.minecraftforge.fluids.FluidTank) WorldCoordinatesWrapper(network.rs485.logisticspipes.world.WorldCoordinatesWrapper) Pair(logisticspipes.utils.tuples.Pair)

Example 8 with FluidTank

use of net.minecraftforge.fluids.FluidTank in project LogisticsPipes by RS485.

the class FluidRoutedPipe method enabledUpdateEntity.

@Override
public void enabledUpdateEntity() {
    super.enabledUpdateEntity();
    if (canInsertFromSideToTanks()) {
        int validDirections = 0;
        List<Pair<TileEntity, ForgeDirection>> list = getAdjacentTanks(true);
        for (Pair<TileEntity, ForgeDirection> pair : list) {
            if (pair.getValue1() instanceof LogisticsTileGenericPipe) {
                if (((LogisticsTileGenericPipe) pair.getValue1()).pipe instanceof CoreRoutedPipe) {
                    continue;
                }
            }
            FluidTank tank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
            validDirections++;
            if (tank.getFluid() == null) {
                continue;
            }
            int filled = ((IFluidHandler) pair.getValue1()).fill(pair.getValue2().getOpposite(), tank.getFluid().copy(), true);
            if (filled == 0) {
                continue;
            }
            FluidStack drain = tank.drain(filled, true);
            if (drain == null || filled != drain.amount) {
                if (LPConstants.DEBUG) {
                    throw new UnsupportedOperationException("Fluid Multiplication");
                }
            }
        }
        if (validDirections == 0) {
            return;
        }
        FluidTank tank = ((PipeFluidTransportLogistics) transport).internalTank;
        FluidStack stack = tank.getFluid();
        if (stack == null) {
            return;
        }
        for (Pair<TileEntity, ForgeDirection> pair : list) {
            if (pair.getValue1() instanceof LogisticsTileGenericPipe) {
                if (((LogisticsTileGenericPipe) pair.getValue1()).pipe instanceof CoreRoutedPipe) {
                    continue;
                }
            }
            FluidTank tankSide = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
            stack = tank.getFluid();
            if (stack == null) {
                continue;
            }
            stack = stack.copy();
            int filled = tankSide.fill(stack, true);
            if (filled == 0) {
                continue;
            }
            FluidStack drain = tank.drain(filled, true);
            if (drain == null || filled != drain.amount) {
                if (LPConstants.DEBUG) {
                    throw new UnsupportedOperationException("Fluid Multiplication");
                }
            }
        }
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) PipeFluidTransportLogistics(logisticspipes.transport.PipeFluidTransportLogistics) CoreRoutedPipe(logisticspipes.pipes.basic.CoreRoutedPipe) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) FluidTank(net.minecraftforge.fluids.FluidTank) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) Pair(logisticspipes.utils.tuples.Pair)

Example 9 with FluidTank

use of net.minecraftforge.fluids.FluidTank in project ImmersiveEngineering by BluSunrize.

the class TileEntityAssembler method consumeItem.

public Optional<ItemStack> consumeItem(Object query, int querySize, ItemStack[] inventory, ArrayList<ItemStack> containerItems) {
    FluidStack fs = query instanceof FluidStack ? (FluidStack) query : (query instanceof IngredientStack && ((IngredientStack) query).fluid != null) ? ((IngredientStack) query).fluid : null;
    if (fs != null)
        for (FluidTank tank : tanks) if (tank.getFluid() != null && tank.getFluid().containsFluid(fs)) {
            tank.drain(fs.amount, true);
            markDirty();
            this.markContainingBlockForUpdate(null);
            return Optional.absent();
        }
    Optional<ItemStack> ret = null;
    for (int i = 0; i < inventory.length; i++) if (inventory[i] != null && Utils.stackMatchesObject(inventory[i], query, true)) {
        int taken = Math.min(querySize, inventory[i].stackSize);
        boolean doTake = true;
        if (doTake) {
            ret = Optional.of(inventory[i].splitStack(taken));
            if (inventory[i].stackSize <= 0)
                inventory[i] = null;
        }
        querySize -= taken;
        if (querySize <= 0)
            break;
    }
    if (query == null || querySize <= 0)
        return ret;
    return null;
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) FluidStack(net.minecraftforge.fluids.FluidStack) IngredientStack(blusunrize.immersiveengineering.api.crafting.IngredientStack) ItemStack(net.minecraft.item.ItemStack)

Aggregations

FluidTank (net.minecraftforge.fluids.FluidTank)9 IFluidTank (net.minecraftforge.fluids.IFluidTank)5 ItemStack (net.minecraft.item.ItemStack)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)3 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)3 PipeFluidTransportLogistics (logisticspipes.transport.PipeFluidTransportLogistics)2 FluidIdentifier (logisticspipes.utils.FluidIdentifier)2 Pair (logisticspipes.utils.tuples.Pair)2 TileEntity (net.minecraft.tileentity.TileEntity)2 FluidStack (net.minecraftforge.fluids.FluidStack)2 IngredientStack (blusunrize.immersiveengineering.api.crafting.IngredientStack)1 IComparatorOverride (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IComparatorOverride)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 LogisticsPipes (logisticspipes.LogisticsPipes)1 IRequestFluid (logisticspipes.interfaces.routing.IRequestFluid)1 IRequireReliableFluidTransport (logisticspipes.interfaces.routing.IRequireReliableFluidTransport)1