Search in sources :

Example 16 with FluidTank

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

the class LampBlockItem method getTankInfo.

private FluidTank getTankInfo(ItemStack stack) {
    FluidTank tank = new FluidTank(TFCConfig.SERVER.lampCapacity.get());
    final CompoundTag tag = stack.getTagElement(Helpers.BLOCK_ENTITY_TAG);
    if (tag != null && tag.contains("tank")) {
        tank.readFromNBT(tag.getCompound("tank"));
        return tank;
    }
    return tank;
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 17 with FluidTank

use of net.minecraftforge.fluids.capability.templates.FluidTank in project Nuclear-Science by aurilisdev.

the class TileGasCentrifuge method process.

public void process(ComponentProcessor processor) {
    ComponentInventory inv = getComponent(ComponentType.Inventory);
    ComponentFluidHandlerMulti tank = getComponent(ComponentType.FluidHandler);
    spinSpeed = (int) processor.operatingSpeed;
    this.<ComponentPacketHandler>getComponent(ComponentType.PacketHandler).sendCustomPacket();
    int processed = (int) (REQUIRED / 60.0);
    for (Fluid fluid : NuclearScienceTags.Fluids.URANIUM_HEXAFLUORIDE.getValues()) {
        FluidTank fTank = tank.getTankFromFluid(fluid, true);
        if (fTank.getFluidAmount() >= processed) {
            fTank.getFluid().shrink(processed);
            break;
        }
    }
    stored235 += processed * PERCENT_U235;
    stored238 += processed * (1 - PERCENT_U235);
    storedWaste += processed * WASTE_MULTIPLIER;
    if (stored235 > REQUIRED) {
        ItemStack stack = inv.getItem(0);
        if (!stack.isEmpty()) {
            stack.setCount(stack.getCount() + 1);
        } else {
            inv.setItem(0, new ItemStack(DeferredRegisters.ITEM_URANIUM235.get()));
        }
        stored235 -= REQUIRED;
    }
    if (stored238 > REQUIRED) {
        ItemStack stack = inv.getItem(1);
        if (!stack.isEmpty()) {
            stack.setCount(stack.getCount() + 1);
        } else {
            inv.setItem(1, new ItemStack(DeferredRegisters.ITEM_URANIUM238.get()));
        }
        stored238 -= REQUIRED;
    }
    if (storedWaste > REQUIRED) {
        ItemStack stack = inv.getItem(2);
        if (!stack.isEmpty()) {
            stack.grow(1);
        } else {
            inv.setItem(2, new ItemStack(DeferredRegisters.ITEM_FISSILEDUST.get(), 1));
        }
        storedWaste -= REQUIRED;
    }
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) ComponentInventory(electrodynamics.prefab.tile.components.type.ComponentInventory) Fluid(net.minecraft.world.level.material.Fluid) ItemStack(net.minecraft.world.item.ItemStack) ComponentFluidHandlerMulti(electrodynamics.prefab.tile.components.type.ComponentFluidHandlerMulti)

Example 18 with FluidTank

use of net.minecraftforge.fluids.capability.templates.FluidTank in project Create by Creators-of-Create.

the class FluidTankRenderer method renderSafe.

@Override
protected void renderSafe(FluidTankTileEntity te, float partialTicks, PoseStack ms, MultiBufferSource buffer, int light, int overlay) {
    if (!te.isController())
        return;
    if (!te.window)
        return;
    InterpolatedChasingValue fluidLevel = te.getFluidLevel();
    if (fluidLevel == null)
        return;
    float capHeight = 1 / 4f;
    float tankHullWidth = 1 / 16f + 1 / 128f;
    float minPuddleHeight = 1 / 16f;
    float totalHeight = te.height - 2 * capHeight - minPuddleHeight;
    float level = fluidLevel.get(partialTicks);
    if (level < 1 / (512f * totalHeight))
        return;
    float clampedLevel = Mth.clamp(level * totalHeight, 0, totalHeight);
    FluidTank tank = te.tankInventory;
    FluidStack fluidStack = tank.getFluid();
    if (fluidStack.isEmpty())
        return;
    boolean top = fluidStack.getFluid().getAttributes().isLighterThanAir();
    float xMin = tankHullWidth;
    float xMax = xMin + te.width - 2 * tankHullWidth;
    float yMin = totalHeight + capHeight + minPuddleHeight - clampedLevel;
    float yMax = yMin + clampedLevel;
    if (top) {
        yMin += totalHeight - clampedLevel;
        yMax += totalHeight - clampedLevel;
    }
    float zMin = tankHullWidth;
    float zMax = zMin + te.width - 2 * tankHullWidth;
    ms.pushPose();
    ms.translate(0, clampedLevel - totalHeight, 0);
    FluidRenderer.renderFluidBox(fluidStack, xMin, yMin, zMin, xMax, yMax, zMax, buffer, ms, light, false);
    ms.popPose();
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) InterpolatedChasingValue(com.simibubi.create.foundation.utility.animation.InterpolatedChasingValue) FluidStack(net.minecraftforge.fluids.FluidStack)

Example 19 with FluidTank

use of net.minecraftforge.fluids.capability.templates.FluidTank in project Create by Creators-of-Create.

the class FluidTankConnectivityHandler method splitTankAndInvalidate.

private static void splitTankAndInvalidate(FluidTankTileEntity te, @Nullable TankSearchCache cache, boolean tryReconnect) {
    // tryReconnect helps whenever only few tanks have been removed
    te = te.getControllerTE();
    if (te == null)
        return;
    int height = te.height;
    int width = te.width;
    if (width == 1 && height == 1)
        return;
    Level world = te.getLevel();
    BlockPos origin = te.getBlockPos();
    List<FluidTankTileEntity> frontier = new ArrayList<>();
    FluidStack toDistribute = te.tankInventory.getFluid().copy();
    int maxCapacity = FluidTankTileEntity.getCapacityMultiplier();
    if (!toDistribute.isEmpty() && !te.isRemoved())
        toDistribute.shrink(maxCapacity);
    te.applyFluidTankSize(1);
    for (int yOffset = 0; yOffset < height; yOffset++) {
        for (int xOffset = 0; xOffset < width; xOffset++) {
            for (int zOffset = 0; zOffset < width; zOffset++) {
                BlockPos pos = origin.offset(xOffset, yOffset, zOffset);
                FluidTankTileEntity tankAt = tankAt(te.getType(), world, pos);
                if (tankAt == null)
                    continue;
                if (!tankAt.getController().equals(origin))
                    continue;
                FluidTankTileEntity controllerTE = tankAt.getControllerTE();
                tankAt.window = controllerTE == null || controllerTE.window;
                tankAt.removeController(true);
                if (!toDistribute.isEmpty() && tankAt != te) {
                    FluidStack copy = toDistribute.copy();
                    FluidTank tankInventory = tankAt.tankInventory;
                    if (tankInventory.isEmpty() && tankInventory instanceof CreativeSmartFluidTank)
                        ((CreativeSmartFluidTank) tankInventory).setContainedFluid(toDistribute);
                    else {
                        int split = Math.min(maxCapacity, toDistribute.getAmount());
                        copy.setAmount(split);
                        toDistribute.shrink(split);
                        tankInventory.fill(copy, FluidAction.EXECUTE);
                    }
                }
                if (tryReconnect) {
                    frontier.add(tankAt);
                    tankAt.updateConnectivity = false;
                }
                if (cache != null)
                    cache.put(pos, tankAt);
            }
        }
    }
    te.fluidCapability.invalidate();
    if (tryReconnect)
        formTanks(te.getType(), world, cache == null ? new TankSearchCache() : cache, frontier);
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) CreativeSmartFluidTank(com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity.CreativeSmartFluidTank) CreativeSmartFluidTank(com.simibubi.create.content.contraptions.fluids.tank.CreativeFluidTankTileEntity.CreativeSmartFluidTank) FluidStack(net.minecraftforge.fluids.FluidStack) ArrayList(java.util.ArrayList) Level(net.minecraft.world.level.Level) BlockPos(net.minecraft.core.BlockPos)

Example 20 with FluidTank

use of net.minecraftforge.fluids.capability.templates.FluidTank in project BiggerReactors by BiggerSeries.

the class CyaniteReprocessorTile method clearContent.

/**
 * Clears all data and inventory for this tile.
 */
@Override
public void clearContent() {
    // Reset work.
    this.workHandler = new WorkHandler(Config.CONFIG.CyaniteReprocessor.TotalWorkTime);
    // Reset items.
    this.itemHandler = new CyaniteReprocessorItemHandler();
    this.itemHandler.setSize(2);
    // Reset energy.
    this.energyStorage = new EnergyStorage(Config.CONFIG.CyaniteReprocessor.EnergyTankCapacity);
    // Reset fluids.
    this.fluidTank = new FluidTank(Config.CONFIG.CyaniteReprocessor.WaterTankCapacity, fluid -> fluid.getFluid() == Fluids.WATER);
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) IItemHandler(net.minecraftforge.items.IItemHandler) Items(net.minecraft.world.item.Items) Direction(net.minecraft.core.Direction) AbstractContainerMenu(net.minecraft.world.inventory.AbstractContainerMenu) CyaniteReprocessorState(net.roguelogix.biggerreactors.machine.state.CyaniteReprocessorState) IHasUpdatableState(net.roguelogix.phosphophyllite.client.gui.api.IHasUpdatableState) BlockState(net.minecraft.world.level.block.state.BlockState) FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) Inventory(net.minecraft.world.entity.player.Inventory) LazyOptional(net.minecraftforge.common.util.LazyOptional) ServerPlayer(net.minecraft.server.level.ServerPlayer) IWorkHandler(net.roguelogix.biggerreactors.api.IWorkHandler) CyaniteReprocessor(net.roguelogix.biggerreactors.machine.blocks.CyaniteReprocessor) BlutoniumIngot(net.roguelogix.biggerreactors.items.ingots.BlutoniumIngot) CyaniteReprocessorItemHandler(net.roguelogix.biggerreactors.machine.tiles.impl.CyaniteReprocessorItemHandler) net.minecraft.world(net.minecraft.world) Fluids(net.minecraft.world.level.material.Fluids) BiggerReactors(net.roguelogix.biggerreactors.BiggerReactors) Nonnull(javax.annotation.Nonnull) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Nullable(javax.annotation.Nullable) CapabilityEnergy(net.minecraftforge.energy.CapabilityEnergy) EnergyStorage(net.minecraftforge.energy.EnergyStorage) CyaniteReprocessorContainer(net.roguelogix.biggerreactors.machine.containers.CyaniteReprocessorContainer) RegisterTile(net.roguelogix.phosphophyllite.registry.RegisterTile) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) Component(net.minecraft.network.chat.Component) CapabilityFluidHandler(net.minecraftforge.fluids.capability.CapabilityFluidHandler) DebugTool(net.roguelogix.phosphophyllite.debug.DebugTool) BlockHitResult(net.minecraft.world.phys.BlockHitResult) Capability(net.minecraftforge.common.capabilities.Capability) Player(net.minecraft.world.entity.player.Player) Objects(java.util.Objects) TextComponent(net.minecraft.network.chat.TextComponent) CompoundTag(net.minecraft.nbt.CompoundTag) WorkHandler(net.roguelogix.biggerreactors.api.WorkHandler) BlockPos(net.minecraft.core.BlockPos) BlockEntityType(net.minecraft.world.level.block.entity.BlockEntityType) CapabilityItemHandler(net.minecraftforge.items.CapabilityItemHandler) Config(net.roguelogix.biggerreactors.Config) FluidStack(net.minecraftforge.fluids.FluidStack) IFluidTank(net.minecraftforge.fluids.IFluidTank) ItemStack(net.minecraft.world.item.ItemStack) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) Level(net.minecraft.world.level.Level) BaseContainerBlockEntity(net.minecraft.world.level.block.entity.BaseContainerBlockEntity) NetworkHooks(net.minecraftforge.network.NetworkHooks) CyaniteReprocessorItemHandler(net.roguelogix.biggerreactors.machine.tiles.impl.CyaniteReprocessorItemHandler) IWorkHandler(net.roguelogix.biggerreactors.api.IWorkHandler) WorkHandler(net.roguelogix.biggerreactors.api.WorkHandler) EnergyStorage(net.minecraftforge.energy.EnergyStorage) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage)

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