diff --git a/src/machines/java/com/enderio/machines/common/io/fluid/MachineTankLayout.java b/src/machines/java/com/enderio/machines/common/io/fluid/MachineTankLayout.java new file mode 100644 index 0000000000..741380ef21 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/io/fluid/MachineTankLayout.java @@ -0,0 +1,63 @@ +package com.enderio.machines.common.io.fluid; + +import net.minecraftforge.fluids.FluidStack; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Predicate; + +/** + * Describes the tank layout of a machine + */ +public class MachineTankLayout { + + /** + * Tank configurations + */ + private final List tanks; + + private MachineTankLayout(Builder builder) { + this.tanks = List.copyOf(builder.tanks); + } + + public static Builder builder() { + return new Builder(); + } + + public int getTankCount() { + return tanks.size(); + } + + public int getTankCapacity(int slot) { + return tanks.get(slot).capacity(); + } + + public boolean canInsert(int slot) { + return tanks.get(slot).insert(); + } + + public boolean canExtract(int slot) { + return tanks.get(slot).extract(); + } + + public boolean isFluidValid(int slot, FluidStack stack) { + return tanks.get(slot).filter().test(stack); + } + + public static class Builder { + private final ArrayList tanks = new ArrayList<>(); + + public Builder tank(TankAccess access, int capacity, boolean canInsert, boolean canRemove, Predicate filter) { + tanks.add(new TankConfig(capacity, canInsert, canRemove, filter)); + access.init(tanks.size() - 1); + return this; + } + + public MachineTankLayout build() { + return new MachineTankLayout(this); + } + } + + private record TankConfig(int capacity, boolean insert, boolean extract, Predicate filter) {} + +} diff --git a/src/machines/java/com/enderio/machines/common/io/fluid/TankAccess.java b/src/machines/java/com/enderio/machines/common/io/fluid/TankAccess.java new file mode 100644 index 0000000000..86256c00d8 --- /dev/null +++ b/src/machines/java/com/enderio/machines/common/io/fluid/TankAccess.java @@ -0,0 +1,14 @@ +package com.enderio.machines.common.io.fluid; + +public class TankAccess { + + private int index = Integer.MIN_VALUE; + + void init(int i) { + if (index == Integer.MIN_VALUE) { + index = i; + } else if (index != i) { + throw new IllegalArgumentException("TankLayout changed dynamically from " + index + " to " + i + ", don't do that"); + } + } +}