-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathFluidCellModelDispatcher.java
More file actions
35 lines (25 loc) · 1.11 KB
/
FluidCellModelDispatcher.java
File metadata and controls
35 lines (25 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package gregtech.api.items.metaitem;
import gregtech.api.items.metaitem.stats.IItemModelDispatcher;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidUtil;
import com.github.bsideup.jabel.Desugar;
@Desugar
public record FluidCellModelDispatcher(int pixel) implements IItemModelDispatcher {
@Override
public int getModelIndex(ItemStack itemStack, int maxIndex) {
var singleStack = itemStack.copy();
if (singleStack.getCount() > 1) singleStack.setCount(1);
var handler = FluidUtil.getFluidHandler(singleStack);
if (handler == null) return pixel;
var tankProps = handler.getTankProperties();
if (tankProps.length != 1) return pixel;
var tankProp = tankProps[0];
var fluidStack = tankProp.getContents();
if (fluidStack == null) return pixel;
boolean isGas = fluidStack.getFluid().isGaseous();
int amount = fluidStack.amount;
int capacity = tankProp.getCapacity();
int fluidLevel = ((pixel - 1) * amount) / capacity;
return isGas ? 2 * (pixel - 1) - fluidLevel : fluidLevel;
}
}