Search in sources :

Example 11 with FluidTank

use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.

the class FluidUtilities method outputToPipe.

public static void outputToPipe(GenericTile tile, FluidTank[] tanks, Direction... outputDirections) {
    ComponentDirection componentDirection = tile.getComponent(ComponentType.Direction);
    for (Direction relative : outputDirections) {
        Direction direction = BlockEntityUtils.getRelativeSide(componentDirection.getDirection(), relative.getOpposite());
        BlockPos face = tile.getBlockPos().relative(direction.getOpposite());
        BlockEntity faceTile = tile.getLevel().getBlockEntity(face);
        if (faceTile != null) {
            boolean electroPipe = faceTile instanceof GenericTilePipe;
            LazyOptional<IFluidHandler> cap = faceTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, direction);
            if (cap.isPresent()) {
                IFluidHandler fHandler = cap.resolve().get();
                for (FluidTank fluidTank : tanks) {
                    FluidStack tankFluid = fluidTank.getFluid();
                    if (electroPipe) {
                        if (fluidTank.getFluidAmount() > 0) {
                            fluidTank.getFluid().shrink(fHandler.fill(tankFluid, FluidAction.EXECUTE));
                        }
                    } else {
                        int amtAccepted = fHandler.fill(tankFluid, FluidAction.SIMULATE);
                        FluidStack taken = new FluidStack(tankFluid.getFluid(), amtAccepted);
                        fHandler.fill(taken, FluidAction.EXECUTE);
                        fluidTank.drain(taken, FluidAction.EXECUTE);
                    }
                }
            }
        }
    }
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) FluidStack(net.minecraftforge.fluids.FluidStack) ComponentDirection(electrodynamics.prefab.tile.components.type.ComponentDirection) BlockPos(net.minecraft.core.BlockPos) Direction(net.minecraft.core.Direction) ComponentDirection(electrodynamics.prefab.tile.components.type.ComponentDirection) GenericTilePipe(electrodynamics.common.tile.generic.GenericTilePipe) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity)

Example 12 with FluidTank

use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.

the class FluidUtilities method drainItem.

public static void drainItem(GenericTile tile) {
    ComponentInventory inv = tile.getComponent(ComponentType.Inventory);
    AbstractFluidHandler<?> handler = tile.getComponent(ComponentType.FluidHandler);
    FluidTank[] tanks = handler.getInputTanks();
    List<ItemStack> buckets = inv.getInputBucketContents();
    for (int i = 0; i < buckets.size(); i++) {
        FluidTank tank = tanks[i];
        ItemStack stack = buckets.get(i);
        if (!stack.isEmpty() && !CapabilityUtils.isFluidItemNull()) {
            FluidStack containerFluid = CapabilityUtils.simDrain(stack, Integer.MAX_VALUE);
            if (handler.getValidInputFluids().contains(containerFluid.getFluid()) && tank.isFluidValid(containerFluid)) {
                int amtDrained = tank.fill(containerFluid, FluidAction.SIMULATE);
                FluidStack drained = new FluidStack(containerFluid.getFluid(), amtDrained);
                CapabilityUtils.drain(stack, drained);
                tank.fill(drained, FluidAction.EXECUTE);
                if (stack.getItem() instanceof BucketItem) {
                    inv.setItem(inv.getInputBucketStartIndex() + i, new ItemStack(Items.BUCKET, 1));
                }
            }
        }
    }
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) ComponentInventory(electrodynamics.prefab.tile.components.type.ComponentInventory) FluidStack(net.minecraftforge.fluids.FluidStack) BucketItem(net.minecraft.world.item.BucketItem) ItemStack(net.minecraft.world.item.ItemStack)

Example 13 with FluidTank

use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.

the class TileFluidVoid method tickServer.

private void tickServer(ComponentTickable tick) {
    ComponentInventory inv = getComponent(ComponentType.Inventory);
    ComponentFluidHandlerSimple handler = getComponent(ComponentType.FluidHandler);
    ItemStack input = inv.getItem(0);
    if (!input.isEmpty() && CapabilityUtils.hasFluidItemCap(input)) {
        FluidTank tank = handler.getInputTanks()[0];
        FluidStack containerFluid = CapabilityUtils.simDrain(input, Integer.MAX_VALUE);
        if (handler.getValidInputFluids().contains(containerFluid.getFluid()) && tank.isFluidValid(containerFluid)) {
            int amtDrained = tank.fill(containerFluid, FluidAction.SIMULATE);
            FluidStack drained = new FluidStack(containerFluid.getFluid(), amtDrained);
            CapabilityUtils.drain(input, drained);
            tank.fill(drained, FluidAction.EXECUTE);
            if (input.getItem() instanceof BucketItem) {
                inv.setItem(0, new ItemStack(Items.BUCKET, 1));
            }
        }
    }
    FluidTank tank = handler.getInputTanks()[0];
    tank.drain(tank.getFluidAmount(), FluidAction.EXECUTE);
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) ComponentInventory(electrodynamics.prefab.tile.components.type.ComponentInventory) FluidStack(net.minecraftforge.fluids.FluidStack) BucketItem(net.minecraft.world.item.BucketItem) ItemStack(net.minecraft.world.item.ItemStack) ComponentFluidHandlerSimple(electrodynamics.prefab.tile.components.type.ComponentFluidHandlerSimple)

Example 14 with FluidTank

use of net.minecraftforge.fluids.capability.templates.FluidTank in project Electrodynamics by aurilisdev.

the class TileCoolantResavoir method hasEnoughFluid.

public boolean hasEnoughFluid(int fluidAmnt) {
    ComponentFluidHandlerSimple simple = getComponent(ComponentType.FluidHandler);
    FluidTank tank = simple.getInputTanks()[0];
    return !tank.isEmpty() && tank.getFluidAmount() >= fluidAmnt;
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) ComponentFluidHandlerSimple(electrodynamics.prefab.tile.components.type.ComponentFluidHandlerSimple)

Example 15 with FluidTank

use of net.minecraftforge.fluids.capability.templates.FluidTank in project Beyond-Earth by MrScautHD.

the class FluidMultiTank method drain.

@Override
public FluidStack drain(FluidStack resource, FluidAction action) {
    resource = resource.copy();
    FluidStack drained = resource.copy();
    drained.setAmount(0);
    for (FluidTank tank : this.getTankList()) {
        int amount = tank.drain(resource, action).getAmount();
        drained.grow(amount);
        resource.shrink(amount);
    }
    return drained;
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) FluidStack(net.minecraftforge.fluids.FluidStack)

Aggregations

FluidTank (net.minecraftforge.fluids.capability.templates.FluidTank)35 FluidStack (net.minecraftforge.fluids.FluidStack)20 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)8 ItemStack (net.minecraft.world.item.ItemStack)7 BlockPos (net.minecraft.core.BlockPos)6 Direction (net.minecraft.core.Direction)6 ComponentInventory (electrodynamics.prefab.tile.components.type.ComponentInventory)5 CompoundTag (net.minecraft.nbt.CompoundTag)5 ArrayList (java.util.ArrayList)4 BucketItem (net.minecraft.world.item.BucketItem)4 Level (net.minecraft.world.level.Level)4 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)4 ComponentDirection (electrodynamics.prefab.tile.components.type.ComponentDirection)3 Nonnull (javax.annotation.Nonnull)3 Nullable (javax.annotation.Nullable)3 ItemStack (net.minecraft.item.ItemStack)3 BlockState (net.minecraft.world.level.block.state.BlockState)3 AABB (net.minecraft.world.phys.AABB)3 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)2 Iterate (com.simibubi.create.foundation.utility.Iterate)2