Search in sources :

Example 6 with FluidTank

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

the class ComponentFluidHandlerMulti method saveToNBT.

@Override
public void saveToNBT(CompoundTag nbt) {
    nbt.putInt("inputSize", inputTanks.length);
    ListTag inputList = new ListTag();
    for (FluidTank tank : inputTanks) {
        CompoundTag tag = new CompoundTag();
        tag.putString("FluidName", tank.getFluid().getRawFluid().getRegistryName().toString());
        tag.putInt("Amount", tank.getFluid().getAmount());
        if (tank.getFluid().getTag() != null) {
            tag.put("Tag", tank.getFluid().getTag());
        }
        // tank capacities needed for JSON tanks
        tag.putInt("cap", tank.getCapacity());
        inputList.add(tag);
    }
    nbt.put("inputList", inputList);
    nbt.putInt("outputSize", outputTanks.length);
    ListTag outputList = new ListTag();
    for (FluidTank tank : outputTanks) {
        CompoundTag tag = new CompoundTag();
        tag.putString("FluidName", tank.getFluid().getRawFluid().getRegistryName().toString());
        tag.putInt("Amount", tank.getFluid().getAmount());
        if (tank.getFluid().getTag() != null) {
            tag.put("Tag", tank.getFluid().getTag());
        }
        tag.putInt("cap", tank.getCapacity());
        outputList.add(tag);
    }
    nbt.put("outputList", outputList);
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 7 with FluidTank

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

the class ComponentFluidHandlerMulti method loadFromNBT.

@Override
public void loadFromNBT(CompoundTag nbt) {
    inputTanks = new FluidTank[nbt.getInt("inputSize")];
    ListTag inputList = nbt.getList("inputList", 10);
    for (int i = 0; i < inputList.size(); i++) {
        CompoundTag compound = (CompoundTag) inputList.get(i);
        FluidTank tank = new FluidTank(compound.getInt("cap")).readFromNBT(compound);
        inputTanks[i] = tank;
    }
    outputTanks = new FluidTank[nbt.getInt("outputSize")];
    ListTag outputList = nbt.getList("outputList", 10);
    for (int i = 0; i < outputList.size(); i++) {
        CompoundTag compound = (CompoundTag) outputList.get(i);
        FluidTank tank = new FluidTank(compound.getInt("cap")).readFromNBT(compound);
        outputTanks[i] = tank;
    }
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 8 with FluidTank

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

the class ComponentFluidHandlerSimple method addFluidTank.

@Override
protected void addFluidTank(Fluid fluid, boolean isInput) {
    if (fluidTank == null) {
        fluidTank = new FluidTank(tankCapacity);
        fluidTank.setFluid(new FluidStack(fluid, 0));
    }
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) FluidStack(net.minecraftforge.fluids.FluidStack)

Example 9 with FluidTank

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

the class ComponentFluidHandlerSimple method loadFromNBT.

@Override
public void loadFromNBT(CompoundTag nbt) {
    CompoundTag compound = nbt.getCompound("fluidtank");
    int cap = compound.getInt("cap");
    FluidStack stack = FluidStack.loadFluidStackFromNBT(compound);
    FluidTank tank = new FluidTank(cap);
    tank.setFluid(stack);
    fluidTank = tank;
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) FluidStack(net.minecraftforge.fluids.FluidStack) CompoundTag(net.minecraft.nbt.CompoundTag)

Example 10 with FluidTank

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

the class RenderTankGeneric method render.

@Override
public void render(GenericTileTank entity, float ticks, PoseStack stack, MultiBufferSource source, int light, int overlay) {
    FluidTank tank = ((ComponentFluidHandlerSimple) entity.getComponent(ComponentType.FluidHandler)).getOutputTanks()[0];
    if (!tank.isEmpty() && tank.getFluidAmount() > 0) {
        FluidStack fluid = tank.getFluid();
        float yHeight = Math.max(Math.min((float) tank.getFluidAmount() / (float) tank.getCapacity(), MAX_Y), MIN_Y);
        AABB aabb = new AABB(MIN_X, MIN_Y, MIN_Z, MAX_X, yHeight, MAX_Z);
        VertexConsumer builder = source.getBuffer(Sheets.translucentCullBlockSheet());
        RenderingUtils.renderFluidBox(stack, Minecraft.getInstance(), builder, aabb, fluid, light, overlay);
    }
}
Also used : FluidTank(net.minecraftforge.fluids.capability.templates.FluidTank) FluidStack(net.minecraftforge.fluids.FluidStack) VertexConsumer(com.mojang.blaze3d.vertex.VertexConsumer) AABB(net.minecraft.world.phys.AABB)

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