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