From 4109c9575dd6d8a89f03e1242493dca228255570 Mon Sep 17 00:00:00 2001 From: Alkalus <3060479+draknyte1@users.noreply.github.com> Date: Mon, 29 Apr 2019 12:55:19 +1000 Subject: + Added Framework for Thermal power based upon the code used for RF. > This is more effective than trying to use the GT EU code for the exact same thing. --- .../api/thermal/energy/IThermalConnection.java | 7 ++ .../api/thermal/energy/IThermalContainerItem.java | 15 +++ .../api/thermal/energy/IThermalHandler.java | 15 +++ .../api/thermal/energy/IThermalProvider.java | 13 +++ .../api/thermal/energy/IThermalReceiver.java | 13 +++ .../api/thermal/energy/IThermalStorage.java | 13 +++ .../api/thermal/energy/ThermalStorage.java | 116 +++++++++++++++++++++ .../api/thermal/energy/ThermalStorageAdv.java | 34 ++++++ .../api/thermal/sample/ItemThermalContainer.java | 84 +++++++++++++++ .../api/thermal/sample/TileThermalHandler.java | 42 ++++++++ .../api/thermal/tileentity/IThermalInfo.java | 13 +++ 11 files changed, 365 insertions(+) create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalConnection.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalContainerItem.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalHandler.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalProvider.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalReceiver.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/IThermalStorage.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java create mode 100644 src/Java/gtPlusPlus/api/thermal/energy/ThermalStorageAdv.java create mode 100644 src/Java/gtPlusPlus/api/thermal/sample/ItemThermalContainer.java create mode 100644 src/Java/gtPlusPlus/api/thermal/sample/TileThermalHandler.java create mode 100644 src/Java/gtPlusPlus/api/thermal/tileentity/IThermalInfo.java diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalConnection.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalConnection.java new file mode 100644 index 0000000000..d8573000fc --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalConnection.java @@ -0,0 +1,7 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IThermalConnection { + boolean canConnectThermalEnergy(ForgeDirection arg0); +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalContainerItem.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalContainerItem.java new file mode 100644 index 0000000000..072695bd76 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalContainerItem.java @@ -0,0 +1,15 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraft.item.ItemStack; + +public interface IThermalContainerItem { + + int receiveThermalEnergy(ItemStack arg0, int arg1, boolean arg2); + + int extractThermalEnergy(ItemStack arg0, int arg1, boolean arg2); + + int getThermalEnergyStored(ItemStack arg0); + + int getMaxThermalEnergyStored(ItemStack arg0); + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalHandler.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalHandler.java new file mode 100644 index 0000000000..3ab7127757 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalHandler.java @@ -0,0 +1,15 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IThermalHandler extends IThermalProvider, IThermalReceiver { + + int receiveThermalEnergy(ForgeDirection arg0, int arg1, boolean arg2); + + int extractThermalEnergy(ForgeDirection arg0, int arg1, boolean arg2); + + int getThermalEnergyStored(ForgeDirection arg0); + + int getMaxThermalEnergyStored(ForgeDirection arg0); + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalProvider.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalProvider.java new file mode 100644 index 0000000000..0e4a060b23 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalProvider.java @@ -0,0 +1,13 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IThermalProvider extends IThermalConnection { + + int extractThermalEnergy(ForgeDirection arg0, int arg1, boolean arg2); + + int getThermalEnergyStored(ForgeDirection arg0); + + int getMaxThermalEnergyStored(ForgeDirection arg0); + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalReceiver.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalReceiver.java new file mode 100644 index 0000000000..e08ce48a06 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalReceiver.java @@ -0,0 +1,13 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IThermalReceiver extends IThermalConnection { + + int receiveThermalEnergy(ForgeDirection arg0, int arg1, boolean arg2); + + int getThermalEnergyStored(ForgeDirection arg0); + + int getMaxThermalEnergyStored(ForgeDirection arg0); + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/IThermalStorage.java b/src/Java/gtPlusPlus/api/thermal/energy/IThermalStorage.java new file mode 100644 index 0000000000..db3e6c8966 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/IThermalStorage.java @@ -0,0 +1,13 @@ +package gtPlusPlus.api.thermal.energy; + +public interface IThermalStorage { + + int receiveThermalEnergy(int arg0, boolean arg1); + + int extractThermalEnergy(int arg0, boolean arg1); + + int getThermalEnergyStored(); + + int getMaxThermalEnergyStored(); + +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java b/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java new file mode 100644 index 0000000000..22a47b2807 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorage.java @@ -0,0 +1,116 @@ +package gtPlusPlus.api.thermal.energy; + +import net.minecraft.nbt.NBTTagCompound; + +public class ThermalStorage implements IThermalStorage { + + protected int thermal_energy; + protected int capacity; + protected int maxReceive; + protected int maxExtract; + + public ThermalStorage(int arg0) { + this(arg0, arg0, arg0); + } + + public ThermalStorage(int arg0, int arg1) { + this(arg0, arg1, arg1); + } + + public ThermalStorage(int arg0, int arg1, int arg2) { + this.capacity = arg0; + this.maxReceive = arg1; + this.maxExtract = arg2; + } + + public ThermalStorage readFromNBT(NBTTagCompound arg0) { + this.thermal_energy = arg0.getInteger("Energy"); + if (this.thermal_energy > this.capacity) { + this.thermal_energy = this.capacity; + } + return this; + } + + public NBTTagCompound writeToNBT(NBTTagCompound arg0) { + if (this.thermal_energy < 0) { + this.thermal_energy = 0; + } + arg0.setInteger("Energy", this.thermal_energy); + return arg0; + } + + public void setCapacity(int arg0) { + this.capacity = arg0; + if (this.thermal_energy > arg0) { + this.thermal_energy = arg0; + } + + } + + public void setMaxTransfer(int arg0) { + this.setMaxReceive(arg0); + this.setMaxExtract(arg0); + } + + public void setMaxReceive(int arg0) { + this.maxReceive = arg0; + } + + public void setMaxExtract(int arg0) { + this.maxExtract = arg0; + } + + public int getMaxReceive() { + return this.maxReceive; + } + + public int getMaxExtract() { + return this.maxExtract; + } + + public void setEnergyStored(int arg0) { + this.thermal_energy = arg0; + if (this.thermal_energy > this.capacity) { + this.thermal_energy = this.capacity; + } else if (this.thermal_energy < 0) { + this.thermal_energy = 0; + } + + } + + public void modifyEnergyStored(int arg0) { + this.thermal_energy += arg0; + if (this.thermal_energy > this.capacity) { + this.thermal_energy = this.capacity; + } else if (this.thermal_energy < 0) { + this.thermal_energy = 0; + } + + } + + public int receiveThermalEnergy(int arg0, boolean arg1) { + int arg2 = Math.min(this.capacity - this.thermal_energy, Math.min(this.maxReceive, arg0)); + if (!arg1) { + this.thermal_energy += arg2; + } + + return arg2; + } + + public int extractThermalEnergy(int arg0, boolean arg1) { + int arg2 = Math.min(this.thermal_energy, Math.min(this.maxExtract, arg0)); + if (!arg1) { + this.thermal_energy -= arg2; + } + + return arg2; + } + + public int getThermalEnergyStored() { + return this.thermal_energy; + } + + public int getMaxThermalEnergyStored() { + return this.capacity; + } +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorageAdv.java b/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorageAdv.java new file mode 100644 index 0000000000..47af7e79a6 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/energy/ThermalStorageAdv.java @@ -0,0 +1,34 @@ +package gtPlusPlus.api.thermal.energy; + +public class ThermalStorageAdv extends ThermalStorage { + + public ThermalStorageAdv(int arg0) { + this(arg0, arg0, arg0); + } + + public ThermalStorageAdv(int arg0, int arg1) { + this(arg0, arg1, arg1); + } + + public ThermalStorageAdv(int arg0, int arg1, int arg2) { + super(arg0, arg1, arg2); + } + + public int receiveEnergyNoLimit(int arg0, boolean arg1) { + int arg2 = Math.min(super.capacity - super.thermal_energy, arg0); + if (!arg1) { + super.thermal_energy += arg2; + } + + return arg2; + } + + public int extractEnergyNoLimit(int arg0, boolean arg1) { + int arg2 = Math.min(super.thermal_energy, arg0); + if (!arg1) { + super.thermal_energy -= arg2; + } + + return arg2; + } +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/sample/ItemThermalContainer.java b/src/Java/gtPlusPlus/api/thermal/sample/ItemThermalContainer.java new file mode 100644 index 0000000000..e33a47d220 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/sample/ItemThermalContainer.java @@ -0,0 +1,84 @@ +package gtPlusPlus.api.thermal.sample; + +import gtPlusPlus.api.thermal.energy.IThermalContainerItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class ItemThermalContainer extends Item implements IThermalContainerItem { + protected int capacity; + protected int maxReceive; + protected int maxExtract; + + public ItemThermalContainer() { + } + + public ItemThermalContainer(int arg0) { + this(arg0, arg0, arg0); + } + + public ItemThermalContainer(int arg0, int arg1) { + this(arg0, arg1, arg1); + } + + public ItemThermalContainer(int arg0, int arg1, int arg2) { + this.capacity = arg0; + this.maxReceive = arg1; + this.maxExtract = arg2; + } + + public ItemThermalContainer setCapacity(int arg0) { + this.capacity = arg0; + return this; + } + + public void setMaxTransfer(int arg0) { + this.setMaxReceive(arg0); + this.setMaxExtract(arg0); + } + + public void setMaxReceive(int arg0) { + this.maxReceive = arg0; + } + + public void setMaxExtract(int arg0) { + this.maxExtract = arg0; + } + + public int receiveThermalEnergy(ItemStack arg0, int arg1, boolean arg2) { + if (arg0.getTagCompound() == null) { + arg0.stackTagCompound = new NBTTagCompound(); + } + int arg3 = arg0.stackTagCompound.getInteger("Energy"); + int arg4 = Math.min(this.capacity - arg3, Math.min(this.maxReceive, arg1)); + if (!arg2) { + arg3 += arg4; + arg0.stackTagCompound.setInteger("Energy", arg3); + } + return arg4; + } + + public int extractThermalEnergy(ItemStack arg0, int arg1, boolean arg2) { + if (arg0.stackTagCompound != null && arg0.stackTagCompound.hasKey("Energy")) { + int arg3 = arg0.stackTagCompound.getInteger("Energy"); + int arg4 = Math.min(arg3, Math.min(this.maxExtract, arg1)); + if (!arg2) { + arg3 -= arg4; + arg0.stackTagCompound.setInteger("Energy", arg3); + } + return arg4; + } else { + return 0; + } + } + + public int getEnergyStored(ItemStack arg0) { + return arg0.stackTagCompound != null && arg0.stackTagCompound.hasKey("Energy") + ? arg0.stackTagCompound.getInteger("Energy") + : 0; + } + + public int getMaxThermalEnergyStored(ItemStack arg0) { + return this.capacity; + } +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/sample/TileThermalHandler.java b/src/Java/gtPlusPlus/api/thermal/sample/TileThermalHandler.java new file mode 100644 index 0000000000..e2e3c50ab7 --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/sample/TileThermalHandler.java @@ -0,0 +1,42 @@ +package gtPlusPlus.api.thermal.sample; + +import gtPlusPlus.api.thermal.energy.IThermalHandler; +import gtPlusPlus.api.thermal.energy.ThermalStorage; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.common.util.ForgeDirection; + +public class TileThermalHandler extends TileEntity implements IThermalHandler { + + protected ThermalStorage storage = new ThermalStorage(32000); + + public void readFromNBT(NBTTagCompound arg0) { + super.readFromNBT(arg0); + this.storage.readFromNBT(arg0); + } + + public void writeToNBT(NBTTagCompound arg0) { + super.writeToNBT(arg0); + this.storage.writeToNBT(arg0); + } + + public boolean canConnectThermalEnergy(ForgeDirection arg0) { + return true; + } + + public int receiveThermalEnergy(ForgeDirection arg0, int arg1, boolean arg2) { + return this.storage.receiveThermalEnergy(arg1, arg2); + } + + public int extractThermalEnergy(ForgeDirection arg0, int arg1, boolean arg2) { + return this.storage.extractThermalEnergy(arg1, arg2); + } + + public int getThermalEnergyStored(ForgeDirection arg0) { + return this.storage.getThermalEnergyStored(); + } + + public int getMaxThermalEnergyStored(ForgeDirection arg0) { + return this.storage.getMaxThermalEnergyStored(); + } +} \ No newline at end of file diff --git a/src/Java/gtPlusPlus/api/thermal/tileentity/IThermalInfo.java b/src/Java/gtPlusPlus/api/thermal/tileentity/IThermalInfo.java new file mode 100644 index 0000000000..a40535887c --- /dev/null +++ b/src/Java/gtPlusPlus/api/thermal/tileentity/IThermalInfo.java @@ -0,0 +1,13 @@ +package gtPlusPlus.api.thermal.tileentity; + +public interface IThermalInfo { + + int getInfoEnergyPerTick(); + + int getInfoMaxEnergyPerTick(); + + int getInfoEnergyStored(); + + int getInfoMaxEnergyStored(); + +} \ No newline at end of file -- cgit