aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/api/logic
diff options
context:
space:
mode:
authorBlueWeabo <ilia.iliev2005@gmail.com>2023-04-01 17:06:06 +0300
committerGitHub <noreply@github.com>2023-04-01 16:06:06 +0200
commit655cc902d3df19a1ac2bfaa38cc928ed629d0171 (patch)
tree25e34b45705b8473e20af3f9b92af25cc87a1e0d /src/main/java/gregtech/api/logic
parenta01d019ed97101936210f16c7a362d852f081f09 (diff)
downloadGT5-Unofficial-655cc902d3df19a1ac2bfaa38cc928ed629d0171.tar.gz
GT5-Unofficial-655cc902d3df19a1ac2bfaa38cc928ed629d0171.tar.bz2
GT5-Unofficial-655cc902d3df19a1ac2bfaa38cc928ed629d0171.zip
Implement Power Logic, Pollution Logic and Processing Logic for MuTEs and many other things (#1823)
* update bs 2 * fuel consumption and energy implementation. clean up * don't register XD * some clean up * coke oven work * semi-working coke oven somehow i broke the activating of the multiblock * power logic * PowerLogic * clean up, saving loading nbt * small cleanup and pollution * pollution working :P * Energy mostly working, wallsharing * processing logic * fix npe and deregister * review requests * missed one * remove extra 0
Diffstat (limited to 'src/main/java/gregtech/api/logic')
-rw-r--r--src/main/java/gregtech/api/logic/PollutionLogic.java17
-rw-r--r--src/main/java/gregtech/api/logic/PowerLogic.java130
-rw-r--r--src/main/java/gregtech/api/logic/ProcessingLogic.java97
-rw-r--r--src/main/java/gregtech/api/logic/interfaces/PollutionLogicHost.java8
-rw-r--r--src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java16
-rw-r--r--src/main/java/gregtech/api/logic/interfaces/ProcessingLogicHost.java8
6 files changed, 276 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/logic/PollutionLogic.java b/src/main/java/gregtech/api/logic/PollutionLogic.java
new file mode 100644
index 0000000000..8e1172e105
--- /dev/null
+++ b/src/main/java/gregtech/api/logic/PollutionLogic.java
@@ -0,0 +1,17 @@
+package gregtech.api.logic;
+
+public class PollutionLogic {
+
+ private int pollutionAmount;
+
+ public PollutionLogic() {}
+
+ public PollutionLogic setPollutionAmount(int pollutionAmount) {
+ this.pollutionAmount = pollutionAmount;
+ return this;
+ }
+
+ public int getPollutionAmount() {
+ return pollutionAmount;
+ }
+}
diff --git a/src/main/java/gregtech/api/logic/PowerLogic.java b/src/main/java/gregtech/api/logic/PowerLogic.java
new file mode 100644
index 0000000000..8044a2f979
--- /dev/null
+++ b/src/main/java/gregtech/api/logic/PowerLogic.java
@@ -0,0 +1,130 @@
+package gregtech.api.logic;
+
+import net.minecraft.nbt.NBTTagCompound;
+
+import gregtech.api.enums.GT_Values.NBT;
+
+public class PowerLogic {
+
+ public static int NONE = 0;
+ public static int RECEIVER = 1;
+ public static int EMITTER = 2;
+ public static int BOTH = RECEIVER | EMITTER;
+ private long storedEnergy = 0;
+ private long energyCapacity = 0;
+ private long voltage = 0;
+ private long amperage = 0;
+ private int type = 0;
+
+ public PowerLogic() {}
+
+ public PowerLogic setMaxVoltage(long voltage) {
+ this.voltage = voltage;
+ return this;
+ }
+
+ public PowerLogic setEnergyCapacity(long energyCapacity) {
+ this.energyCapacity = energyCapacity;
+ return this;
+ }
+
+ public PowerLogic setAmperage(long amperage) {
+ this.amperage = amperage;
+ return this;
+ }
+
+ public PowerLogic setType(int type) {
+ this.type = type;
+ return this;
+ }
+
+ public boolean addEnergyUnsafe(long totalEUAdded) {
+ if (storedEnergy + totalEUAdded >= energyCapacity) {
+ return false;
+ }
+
+ storedEnergy += totalEUAdded;
+ return true;
+ }
+
+ public boolean addEnergy(long voltage, long amperage) {
+ if (voltage > this.voltage) {
+ return false;
+ }
+
+ return addEnergyUnsafe(voltage * amperage);
+ }
+
+ public boolean addEnergy(long voltage) {
+ return addEnergy(voltage, 1);
+ }
+
+ public long injectEnergy(long voltage, long availableAmperage) {
+ long usedAmperes = 0;
+ while (addEnergy(voltage, 1) && usedAmperes < amperage) {
+ usedAmperes++;
+ }
+
+ return usedAmperes;
+ }
+
+ public boolean removeEnergyUnsafe(long totalEURemoved) {
+ if (storedEnergy - totalEURemoved < 0) {
+ return false;
+ }
+
+ storedEnergy -= totalEURemoved;
+ return true;
+ }
+
+ public boolean removeEnergy(long voltage, long amperage) {
+ if (voltage > this.voltage) {
+ return false;
+ }
+
+ return removeEnergyUnsafe(voltage * amperage);
+ }
+
+ public boolean removeEnergy(long voltage) {
+ return removeEnergy(voltage, 1);
+ }
+
+ public long getCapacity() {
+ return energyCapacity;
+ }
+
+ public long getVoltage() {
+ return voltage;
+ }
+
+ public long getStoredEnergy() {
+ return storedEnergy;
+ }
+
+ public boolean isEnergyReceiver() {
+ return (type & RECEIVER) > 0;
+ }
+
+ public boolean isEnergyEmitter() {
+ return (type & EMITTER) > 0;
+ }
+
+ public void writeToNBT(NBTTagCompound nbt) {
+ NBTTagCompound powerLogic = new NBTTagCompound();
+ powerLogic.setLong(NBT.POWER_LOGIC_ENERGY_CAPACITY, energyCapacity);
+ powerLogic.setLong(NBT.POWER_LOGIC_STORED_ENERGY, storedEnergy);
+ powerLogic.setLong(NBT.POWER_LOGIC_AMPERAGE, amperage);
+ powerLogic.setLong(NBT.POWER_LOGIC_VOLTAGE, voltage);
+ powerLogic.setInteger(NBT.POWER_LOGIC_TYPE, type);
+ nbt.setTag(NBT.POWER_LOGIC, powerLogic);
+ }
+
+ public void loadFromNBT(NBTTagCompound nbt) {
+ NBTTagCompound powerLogic = nbt.getCompoundTag(NBT.POWER_LOGIC);
+ energyCapacity = powerLogic.getLong(NBT.POWER_LOGIC_ENERGY_CAPACITY);
+ storedEnergy = powerLogic.getLong(NBT.POWER_LOGIC_STORED_ENERGY);
+ amperage = powerLogic.getLong(NBT.POWER_LOGIC_AMPERAGE);
+ voltage = powerLogic.getLong(NBT.POWER_LOGIC_VOLTAGE);
+ type = powerLogic.getInteger(NBT.POWER_LOGIC_TYPE);
+ }
+}
diff --git a/src/main/java/gregtech/api/logic/ProcessingLogic.java b/src/main/java/gregtech/api/logic/ProcessingLogic.java
new file mode 100644
index 0000000000..fa0d285401
--- /dev/null
+++ b/src/main/java/gregtech/api/logic/ProcessingLogic.java
@@ -0,0 +1,97 @@
+package gregtech.api.logic;
+
+import net.minecraft.item.ItemStack;
+import net.minecraftforge.fluids.FluidStack;
+
+import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
+
+public abstract class ProcessingLogic {
+
+ protected GT_Recipe_Map recipeMap;
+ protected ItemStack[] inputItems;
+ protected ItemStack[] outputItems;
+ protected ItemStack[] currentOutputItems;
+ protected FluidStack[] inputFluids;
+ protected FluidStack[] outputFluids;
+ protected FluidStack[] currentOutputFluids;
+ protected long eut;
+ protected long duration;
+
+ public ProcessingLogic() {}
+
+ public ProcessingLogic setInputItems(ItemStack... itemInputs) {
+ this.inputItems = itemInputs;
+ return this;
+ }
+
+ public ProcessingLogic setInputFluids(FluidStack... fluidInputs) {
+ this.inputFluids = fluidInputs;
+ return this;
+ }
+
+ public ProcessingLogic setOutputItems(ItemStack... itemOutputs) {
+ this.outputItems = itemOutputs;
+ return this;
+ }
+
+ public ProcessingLogic setOutputFluids(FluidStack... fluidOutputs) {
+ this.outputFluids = fluidOutputs;
+ return this;
+ }
+
+ public ProcessingLogic setCurrentOutputItems(ItemStack... currentOutputItems) {
+ this.currentOutputItems = currentOutputItems;
+ return this;
+ }
+
+ public ProcessingLogic setCurrentOutputFluids(FluidStack... currentOutputFluids) {
+ this.currentOutputFluids = currentOutputFluids;
+ return this;
+ }
+
+ public ProcessingLogic setRecipeMap(GT_Recipe_Map recipeMap) {
+ this.recipeMap = recipeMap;
+ return this;
+ }
+
+ public ProcessingLogic setDuration(long duration) {
+ this.duration = duration;
+ return this;
+ }
+
+ public ProcessingLogic setEut(long eut) {
+ this.eut = eut;
+ return this;
+ }
+
+ /**
+ * Clears everything stored in the Processing Logic other than the Recipe map used
+ */
+ public ProcessingLogic clear() {
+ this.inputItems = null;
+ this.inputFluids = null;
+ this.outputItems = null;
+ this.outputFluids = null;
+ this.eut = 0;
+ this.duration = 0;
+ return this;
+ }
+
+ public abstract boolean process();
+
+ public ItemStack[] getOutputItems() {
+ return outputItems;
+ }
+
+ public FluidStack[] getOutputFluids() {
+ return outputFluids;
+ }
+
+ public long getDuration() {
+ return duration;
+ }
+
+ public long getEut() {
+ return eut;
+ }
+}
diff --git a/src/main/java/gregtech/api/logic/interfaces/PollutionLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/PollutionLogicHost.java
new file mode 100644
index 0000000000..657efbb74d
--- /dev/null
+++ b/src/main/java/gregtech/api/logic/interfaces/PollutionLogicHost.java
@@ -0,0 +1,8 @@
+package gregtech.api.logic.interfaces;
+
+import gregtech.api.logic.PollutionLogic;
+
+public interface PollutionLogicHost {
+
+ PollutionLogic getPollutionLogic();
+}
diff --git a/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java
new file mode 100644
index 0000000000..8e504674aa
--- /dev/null
+++ b/src/main/java/gregtech/api/logic/interfaces/PowerLogicHost.java
@@ -0,0 +1,16 @@
+package gregtech.api.logic.interfaces;
+
+import gregtech.api.logic.PowerLogic;
+
+public interface PowerLogicHost {
+
+ PowerLogic getPowerLogic(byte side);
+
+ default boolean isEnergyReceiver() {
+ return false;
+ }
+
+ default boolean isEnergyEmitter() {
+ return false;
+ }
+}
diff --git a/src/main/java/gregtech/api/logic/interfaces/ProcessingLogicHost.java b/src/main/java/gregtech/api/logic/interfaces/ProcessingLogicHost.java
new file mode 100644
index 0000000000..55418208b0
--- /dev/null
+++ b/src/main/java/gregtech/api/logic/interfaces/ProcessingLogicHost.java
@@ -0,0 +1,8 @@
+package gregtech.api.logic.interfaces;
+
+import gregtech.api.logic.ProcessingLogic;
+
+public interface ProcessingLogicHost {
+
+ ProcessingLogic getProcessingLogic();
+}