aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/logic
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/gregtech/api/logic')
-rw-r--r--src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java183
-rw-r--r--src/main/java/gregtech/api/logic/ModelRenderLogic.java5
-rw-r--r--src/main/java/gregtech/api/logic/PowerLogic.java15
-rw-r--r--src/main/java/gregtech/api/logic/interfaces/ModelRenderLogicHost.java10
-rw-r--r--src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java4
5 files changed, 216 insertions, 1 deletions
diff --git a/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java b/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java
new file mode 100644
index 0000000000..d38a3d98fd
--- /dev/null
+++ b/src/main/java/gregtech/api/logic/ComplexParallelProcessingLogic.java
@@ -0,0 +1,183 @@
+package gregtech.api.logic;
+
+import java.util.stream.LongStream;
+
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.FluidStack;
+
+import gregtech.api.multitileentity.multiblock.base.Controller;
+import gregtech.api.util.GT_OverclockCalculator;
+import gregtech.api.util.GT_ParallelHelper;
+import gregtech.api.util.GT_Recipe;
+
+public class ComplexParallelProcessingLogic {
+
+ protected Controller<?> tileEntity;
+ protected GT_Recipe.GT_Recipe_Map recipeMap;
+ protected boolean hasPerfectOverclock;
+ protected final int maxComplexParallels;
+ protected final ItemStack[][] outputItems;
+ protected final ItemStack[][] inputItems;
+ protected final FluidStack[][] inputFluids;
+ protected final FluidStack[][] outputFluids;
+ protected final long[] availableEut;
+ protected final long[] eut;
+ protected final long[] durations;
+ protected boolean[] isVoidProtected;
+
+ public ComplexParallelProcessingLogic(int maxComplexParallels) {
+ this(null, maxComplexParallels);
+ }
+
+ public ComplexParallelProcessingLogic(GT_Recipe.GT_Recipe_Map recipeMap, int maxComplexParallels) {
+ this.maxComplexParallels = maxComplexParallels;
+ this.recipeMap = recipeMap;
+ inputItems = new ItemStack[maxComplexParallels][];
+ outputItems = new ItemStack[maxComplexParallels][];
+ inputFluids = new FluidStack[maxComplexParallels][];
+ outputFluids = new FluidStack[maxComplexParallels][];
+ eut = new long[maxComplexParallels];
+ availableEut = new long[maxComplexParallels];
+ durations = new long[maxComplexParallels];
+ isVoidProtected = new boolean[maxComplexParallels];
+ }
+
+ public ComplexParallelProcessingLogic setRecipeMap(GT_Recipe.GT_Recipe_Map recipeMap) {
+ this.recipeMap = recipeMap;
+ return this;
+ }
+
+ public ComplexParallelProcessingLogic setInputItems(int index, ItemStack... itemInputs) {
+ if (index >= 0 && index < maxComplexParallels) {
+ inputItems[index] = itemInputs;
+ }
+ return this;
+ }
+
+ public ComplexParallelProcessingLogic setInputFluids(int index, FluidStack... inputFluids) {
+ if (index >= 0 && index < maxComplexParallels) {
+ this.inputFluids[index] = inputFluids;
+ }
+ return this;
+ }
+
+ public ComplexParallelProcessingLogic setTileEntity(Controller<?> tileEntity) {
+ this.tileEntity = tileEntity;
+ return this;
+ }
+
+ public ComplexParallelProcessingLogic setEut(int index, long eut) {
+ if (index >= 0 && index < maxComplexParallels) {
+ availableEut[index] = eut;
+ }
+ return this;
+ }
+
+ public ComplexParallelProcessingLogic setVoidProtection(int index, boolean shouldVoidProtect) {
+ if (index >= 0 && index < maxComplexParallels) {
+ isVoidProtected[index] = shouldVoidProtect;
+ }
+ return this;
+ }
+
+ public ComplexParallelProcessingLogic setPerfectOverclock(boolean shouldOverclockPerfectly) {
+ this.hasPerfectOverclock = shouldOverclockPerfectly;
+ return this;
+ }
+
+ public ComplexParallelProcessingLogic clear() {
+ for (int i = 0; i < maxComplexParallels; i++) {
+ outputItems[i] = null;
+ outputFluids[i] = null;
+ durations[i] = 0;
+ eut[i] = 0;
+ }
+ return this;
+ }
+
+ public ComplexParallelProcessingLogic clear(int index) {
+ if (index >= 0 && index < maxComplexParallels) {
+ inputItems[index] = null;
+ inputFluids[index] = null;
+ outputItems[index] = null;
+ outputFluids[index] = null;
+ durations[index] = 0;
+ availableEut[index] = 0;
+ eut[index] = 0;
+ }
+ return this;
+ }
+
+ public boolean process(int index) {
+ if (recipeMap == null) {
+ return false;
+ }
+ GT_Recipe recipe = recipeMap
+ .findRecipe(tileEntity, false, false, availableEut[index], inputFluids[index], inputItems[index]);
+ if (recipe == null) {
+ return false;
+ }
+
+ GT_ParallelHelper helper = new GT_ParallelHelper().setRecipe(recipe)
+ .setItemInputs(inputItems[index])
+ .setFluidInputs(inputFluids[index])
+ .setAvailableEUt(availableEut[index])
+ .enableConsumption()
+ .enableOutputCalculation();
+
+ if (isVoidProtected[index]) {
+ helper.enableVoidProtection(tileEntity);
+ }
+
+ helper.build();
+
+ if (helper.getCurrentParallel() <= 0) {
+ return false;
+ }
+
+ GT_OverclockCalculator calculator = new GT_OverclockCalculator().setRecipeEUt(recipe.mEUt)
+ .setDuration(recipe.mDuration)
+ .setEUt(availableEut[index]);
+
+ if (hasPerfectOverclock) {
+ calculator.enablePerfectOC();
+ }
+
+ if (calculator.getConsumption() == Long.MAX_VALUE - 1 || calculator.getDuration() == Integer.MAX_VALUE - 1) {
+ return false;
+ }
+
+ durations[index] = calculator.getDuration();
+ eut[index] = calculator.getConsumption();
+ outputItems[index] = helper.getItemOutputs();
+ outputFluids[index] = helper.getFluidOutputs();
+
+ return true;
+ }
+
+ public long getDuration(int index) {
+ if (index >= 0 && index < maxComplexParallels) {
+ return durations[index];
+ }
+ return 0;
+ }
+
+ public long getTotalEU() {
+ return LongStream.of(eut)
+ .sum();
+ }
+
+ public ItemStack[] getOutputItems(int index) {
+ if (index >= 0 && index < maxComplexParallels) {
+ return outputItems[index];
+ }
+ return null;
+ }
+
+ public FluidStack[] getOutputFluids(int index) {
+ if (index >= 0 && index < maxComplexParallels) {
+ return outputFluids[index];
+ }
+ return null;
+ }
+}
diff --git a/src/main/java/gregtech/api/logic/ModelRenderLogic.java b/src/main/java/gregtech/api/logic/ModelRenderLogic.java
new file mode 100644
index 0000000000..d9f2fdcf27
--- /dev/null
+++ b/src/main/java/gregtech/api/logic/ModelRenderLogic.java
@@ -0,0 +1,5 @@
+package gregtech.api.logic;
+
+public abstract class ModelRenderLogic {
+
+}
diff --git a/src/main/java/gregtech/api/logic/PowerLogic.java b/src/main/java/gregtech/api/logic/PowerLogic.java
index 8044a2f979..ac12ef8917 100644
--- a/src/main/java/gregtech/api/logic/PowerLogic.java
+++ b/src/main/java/gregtech/api/logic/PowerLogic.java
@@ -15,6 +15,7 @@ public class PowerLogic {
private long voltage = 0;
private long amperage = 0;
private int type = 0;
+ private boolean canUseLaser = false;
public PowerLogic() {}
@@ -38,6 +39,16 @@ public class PowerLogic {
return this;
}
+ public PowerLogic disableLaser() {
+ canUseLaser = false;
+ return this;
+ }
+
+ public PowerLogic enableLaser() {
+ canUseLaser = true;
+ return this;
+ }
+
public boolean addEnergyUnsafe(long totalEUAdded) {
if (storedEnergy + totalEUAdded >= energyCapacity) {
return false;
@@ -127,4 +138,8 @@ public class PowerLogic {
voltage = powerLogic.getLong(NBT.POWER_LOGIC_VOLTAGE);
type = powerLogic.getInteger(NBT.POWER_LOGIC_TYPE);
}
+
+ public boolean canUseLaser() {
+ return canUseLaser;
+ }
}
diff --git a/src/main/java/gregtech/api/logic/interfaces/ModelRenderLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/ModelRenderLogicHost.java
new file mode 100644
index 0000000000..9a0afaa539
--- /dev/null
+++ b/src/main/java/gregtech/api/logic/interfaces/ModelRenderLogicHost.java
@@ -0,0 +1,10 @@
+package gregtech.api.logic.interfaces;
+
+import gregtech.api.logic.ModelRenderLogic;
+
+public interface ModelRenderLogicHost {
+
+ ModelRenderLogic getRenderLogic();
+
+ boolean shouldRenderModel();
+}
diff --git a/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java
index 8e504674aa..1a66e5fe83 100644
--- a/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java
+++ b/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java
@@ -1,10 +1,12 @@
package gregtech.api.logic.interfaces;
+import net.minecraftforge.common.util.ForgeDirection;
+
import gregtech.api.logic.PowerLogic;
public interface PowerLogicHost {
- PowerLogic getPowerLogic(byte side);
+ PowerLogic getPowerLogic(ForgeDirection facing);
default boolean isEnergyReceiver() {
return false;