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);
}
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;
}
}
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));
}
}
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;
}
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);
}
}
Aggregations