Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidTank;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import gregtech.api.capability.IMultipleTankHandler;
import gregtech.api.gui.resources.TextureArea;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.interfaces.IGregTechTileEntity;
import gregtech.api.metatileentity.multiblock.IMultiblockPart;
import gregtech.api.metatileentity.multiblock.IProgressBarMultiblock;
import gregtech.api.metatileentity.multiblock.MultiblockAbility;
import gregtech.api.metatileentity.multiblock.RecipeMapMultiblockController;
import gregtech.api.pattern.BlockPattern;
import gregtech.api.pattern.FactoryBlockPattern;
Expand Down Expand Up @@ -135,31 +136,20 @@ protected ICubeRenderer getFrontOverlay() {
}

// IProgressBarMultiblock implementation
@Override
public boolean showProgressBar() {
return true;
}

@Override
public int getNumProgressBars() {
return 2;
}

@Override
public double getFillPercentage(int index) {
if (!isStructureFormed() || getInputFluidInventory() == null) {
return 0;
}

if (index == 0) {
// EnderPearl fluid
int[] amount = getTotalFluidAmount(Materials.EnderPearl.getFluid(Integer.MAX_VALUE),
getInputFluidInventory());
int[] amount = getTotalFluidAmount(Materials.EnderPearl.getFluid(Integer.MAX_VALUE));
return amount[1] != 0 ? 1.0 * amount[0] / amount[1] : 0;
} else {
// Drilling Fluid
int[] amount = getTotalFluidAmount(Materials.DrillingFluid.getFluid(Integer.MAX_VALUE),
getInputFluidInventory());
int[] amount = getTotalFluidAmount(Materials.DrillingFluid.getFluid(Integer.MAX_VALUE));
return amount[1] != 0 ? 1.0 * amount[0] / amount[1] : 0;
}
}
Expand All @@ -175,14 +165,9 @@ public TextureArea getProgressBarTexture(int index) {

@Override
public void addBarHoverText(List<ITextComponent> hoverList, int index) {
if (!isStructureFormed() || getInputFluidInventory() == null) {
return;
}

if (index == 0) {
// EnderPearl fluid
int[] amount = getTotalFluidAmount(Materials.EnderPearl.getFluid(Integer.MAX_VALUE),
getInputFluidInventory());
int[] amount = getTotalFluidAmount(Materials.EnderPearl.getFluid(Integer.MAX_VALUE));
ITextComponent fluidInfo = TextComponentUtil.stringWithColor(
TextFormatting.GREEN,
TextFormattingUtil.formatNumbers(amount[0]) + " / " +
Expand All @@ -193,8 +178,7 @@ public void addBarHoverText(List<ITextComponent> hoverList, int index) {
fluidInfo));
} else {
// Drilling Fluid
int[] amount = getTotalFluidAmount(Materials.DrillingFluid.getFluid(Integer.MAX_VALUE),
getInputFluidInventory());
int[] amount = getTotalFluidAmount(Materials.DrillingFluid.getFluid(Integer.MAX_VALUE));
ITextComponent fluidInfo = TextComponentUtil.stringWithColor(
TextFormatting.GOLD,
TextFormattingUtil.formatNumbers(amount[0]) + " / " +
Expand All @@ -206,19 +190,19 @@ public void addBarHoverText(List<ITextComponent> hoverList, int index) {
}
}

private int[] getTotalFluidAmount(FluidStack testStack, IMultipleTankHandler tanks) {
int stored = 0;
int capacity = 0;
for (var tank : tanks.getFluidTanks()) {
FluidStack contained = tank.getFluid();
if (contained != null && contained.isFluidEqual(testStack)) {
stored += contained.amount;
capacity += tank.getCapacity();
} else if (contained == null) {
// Empty tank that could hold this fluid
capacity += tank.getCapacity();
private int[] getTotalFluidAmount(FluidStack testStack) {
if (!isStructureFormed()) return new int[] { 0, 0 };
List<IFluidTank> tanks = getAbilities(MultiblockAbility.IMPORT_FLUIDS);
int fluidAmount = 0;
int fluidCapacity = 0;
for (IFluidTank tank : tanks) {
if (tank == null || tank.getFluid() == null) continue;
if (tank.getFluid().isFluidEqual(testStack)) {
fluidAmount += tank.getFluidAmount();
int capacity = tank.getCapacity();
fluidCapacity += capacity > 0 ? capacity : tank.getFluidAmount();
}
}
return new int[] { stored, capacity };
return new int[] { fluidAmount, fluidCapacity };
}
}