diff options
Diffstat (limited to 'src')
50 files changed, 2430 insertions, 959 deletions
diff --git a/src/main/java/gregtech/api/enums/GT_Values.java b/src/main/java/gregtech/api/enums/GT_Values.java index 14cca69f05..d06e70b0b5 100644 --- a/src/main/java/gregtech/api/enums/GT_Values.java +++ b/src/main/java/gregtech/api/enums/GT_Values.java @@ -232,7 +232,7 @@ public class GT_Values { // Machines ACTIVE = "gt.active", // Boolean FLUID_OUT = "gt.fluidout", // Output Fluid - ITEM_OUT = "gt,itemout", // Output Item + ITEM_OUT = "gt.itemout", // Output Item PARALLEL = "gt.parallel", // Number TANK_CAPACITY = "gt.tankcap", // Number TANK_IN = "gt.tank.in.", // FluidStack @@ -242,6 +242,14 @@ public class GT_Values { INV_OUTPUT_SIZE = "gt.invsize.out", // Number INV_INPUT_LIST = "gt.invlist.in", // NBT List INV_OUTPUT_LIST = "gt.invlist.out", // NBT List + VOLTAGE = "gt.voltage", // Number + AMPERAGE = "gt.amperage", // Number + STORED_ENERGY = "gt.stored.energy", // Number + MAXIMUM_ENERGY = "gt.maximum.energy", // Number + EUT_CONSUMPTION = "gt.eut.consumption", // Number + BURN_TIME_LEFT = "gt.burn.time.left", // Number + TOTAL_BURN_TIME = "gt.total.burn.time", // Number + ALLOWED_WORK = "gt.allowed.work", // Boolean // MultiBlock STRUCTURE_OK = "gt.structure.ok", ROTATION = "gt.eRotation", FLIP = "gt.eFlip", TARGET = "gt.target", // Boolean @@ -255,6 +263,15 @@ public class GT_Values { UPGRADE_INVENTORY_NAME = "gt.invname.upg", // String UPGRADE_INVENTORIES_INPUT = "gt.invlist.upg.in", // NBT List UPGRADE_INVENTORIES_OUTPUT = "gt.invlist.upg.out", // NBT List + SEPARATE_INPUTS = "gt.separate.inputs", // Boolean + + // Logic + POWER_LOGIC = "gt.power.logic", // NBT Tag + POWER_LOGIC_STORED_ENERGY = "gt.power.logic.stored.energy", // Number + POWER_LOGIC_ENERGY_CAPACITY = "gt.power.logic.energy.capacity", // Number + POWER_LOGIC_VOLTAGE = "gt.power.logic.voltage", // Number + POWER_LOGIC_AMPERAGE = "gt.power.logic.voltage", // Number + POWER_LOGIC_TYPE = "gt.power.logic.type", // Number empty_ = ""; } diff --git a/src/main/java/gregtech/api/enums/TickTime.java b/src/main/java/gregtech/api/enums/TickTime.java new file mode 100644 index 0000000000..28c68e172f --- /dev/null +++ b/src/main/java/gregtech/api/enums/TickTime.java @@ -0,0 +1,10 @@ +package gregtech.api.enums; + +public class TickTime { + + public static final int TICK = 1; + public static final int SECOND = TICK * 20; + public static final int MINUTE = SECOND * 60; + public static final int HOUR = MINUTE * 60; + public static final int DAY = HOUR * 24; +} diff --git a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java index 4fcfc861bb..92d2482014 100644 --- a/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java +++ b/src/main/java/gregtech/api/interfaces/tileentity/IEnergyConnected.java @@ -5,6 +5,8 @@ import net.minecraftforge.common.util.ForgeDirection; import cofh.api.energy.IEnergyReceiver; import gregtech.api.GregTech_API; +import gregtech.api.logic.PowerLogic; +import gregtech.api.logic.interfaces.PowerLogicHost; import gregtech.api.util.GT_Utility; import ic2.api.energy.tile.IEnergySink; @@ -58,37 +60,49 @@ public interface IEnergyConnected extends IColoredTileEntity { */ public static long emitEnergyToNetwork(long aVoltage, long aAmperage, IEnergyConnected aEmitter) { long rUsedAmperes = 0; - if (aEmitter instanceof IHasWorldObjectAndCoords) { - IHasWorldObjectAndCoords emitterTile = (IHasWorldObjectAndCoords) aEmitter; - for (byte i = 0, j = 0; i < 6 && aAmperage > rUsedAmperes; i++) { - if (aEmitter.outputsEnergyTo(i)) { - j = GT_Utility.getOppositeSide(i); - final TileEntity tTileEntity = emitterTile.getTileEntityAtSide(i); - if (tTileEntity instanceof IEnergyConnected) { - if (aEmitter.getColorization() >= 0) { - final byte tColor = ((IEnergyConnected) tTileEntity).getColorization(); - if (tColor >= 0 && tColor != aEmitter.getColorization()) continue; - } - rUsedAmperes += ((IEnergyConnected) tTileEntity) - .injectEnergyUnits(j, aVoltage, aAmperage - rUsedAmperes); + if (!(aEmitter instanceof IHasWorldObjectAndCoords)) { + return 0; + } + + IHasWorldObjectAndCoords emitterTile = (IHasWorldObjectAndCoords) aEmitter; + for (byte i = 0, j = 0; i < 6 && aAmperage > rUsedAmperes; i++) { + if (!aEmitter.outputsEnergyTo(i)) { + continue; + } - } else if (tTileEntity instanceof IEnergySink) { - if (((IEnergySink) tTileEntity) - .acceptsEnergyFrom((TileEntity) aEmitter, ForgeDirection.getOrientation(j))) { - while (aAmperage > rUsedAmperes && ((IEnergySink) tTileEntity).getDemandedEnergy() > 0 - && ((IEnergySink) tTileEntity) - .injectEnergy(ForgeDirection.getOrientation(j), aVoltage, aVoltage) - < aVoltage) - rUsedAmperes++; - } - } else if (GregTech_API.mOutputRF && tTileEntity instanceof IEnergyReceiver) { - final ForgeDirection tDirection = ForgeDirection.getOrientation(i).getOpposite(); - final int rfOut = GT_Utility.safeInt(aVoltage * GregTech_API.mEUtoRF / 100); - if (((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, true) == rfOut) { - ((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, false); - rUsedAmperes++; - } - } + j = GT_Utility.getOppositeSide(i); + final TileEntity tTileEntity = emitterTile.getTileEntityAtSide(i); + if (tTileEntity instanceof PowerLogicHost) { + PowerLogicHost host = (PowerLogicHost) tTileEntity; + + PowerLogic logic = host.getPowerLogic(j); + if (logic == null || logic.isEnergyReceiver()) { + continue; + } + + rUsedAmperes += logic.injectEnergy(aVoltage, aAmperage - rUsedAmperes); + } else if (tTileEntity instanceof IEnergyConnected) { + if (aEmitter.getColorization() >= 0) { + final byte tColor = ((IEnergyConnected) tTileEntity).getColorization(); + if (tColor >= 0 && tColor != aEmitter.getColorization()) continue; + } + rUsedAmperes += ((IEnergyConnected) tTileEntity) + .injectEnergyUnits(j, aVoltage, aAmperage - rUsedAmperes); + + } else if (tTileEntity instanceof IEnergySink) { + if (((IEnergySink) tTileEntity) + .acceptsEnergyFrom((TileEntity) aEmitter, ForgeDirection.getOrientation(j))) { + while (aAmperage > rUsedAmperes && ((IEnergySink) tTileEntity).getDemandedEnergy() > 0 + && ((IEnergySink) tTileEntity) + .injectEnergy(ForgeDirection.getOrientation(j), aVoltage, aVoltage) < aVoltage) + rUsedAmperes++; + } + } else if (GregTech_API.mOutputRF && tTileEntity instanceof IEnergyReceiver) { + final ForgeDirection tDirection = ForgeDirection.getOrientation(i).getOpposite(); + final int rfOut = GT_Utility.safeInt(aVoltage * GregTech_API.mEUtoRF / 100); + if (((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, true) == rfOut) { + ((IEnergyReceiver) tTileEntity).receiveEnergy(tDirection, rfOut, false); + rUsedAmperes++; } } } 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(); +} diff --git a/src/main/java/gregtech/api/multitileentity/MultiTileEntityClassContainer.java b/src/main/java/gregtech/api/multitileentity/MultiTileEntityClassContainer.java index 84cbdfb529..195fed3100 100644 --- a/src/main/java/gregtech/api/multitileentity/MultiTileEntityClassContainer.java +++ b/src/main/java/gregtech/api/multitileentity/MultiTileEntityClassContainer.java @@ -8,9 +8,11 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.Tuple; import gregtech.api.enums.Materials; -import gregtech.api.multitileentity.base.BaseMultiTileEntity; -import gregtech.api.multitileentity.multiblock.casing.AdvancedCasing; +import gregtech.api.multitileentity.base.MultiTileEntity; +import gregtech.api.multitileentity.multiblock.casing.FunctionalCasing; +import gregtech.api.multitileentity.multiblock.casing.UpgradeCasing; import gregtech.api.util.GT_Util; +import gregtech.common.tileentities.casings.upgrade.InventoryUpgrade; public class MultiTileEntityClassContainer { @@ -19,9 +21,9 @@ public class MultiTileEntityClassContainer { private String mCategoryName; public final short mID; - public Class<? extends BaseMultiTileEntity> mClass; + public Class<? extends MultiTileEntity> mClass; public MultiTileEntityBlock mBlock; - public BaseMultiTileEntity mCanonicalTileEntity; + public MultiTileEntity mCanonicalTileEntity; public NBTTagCompound mParameters; // These have defaults @@ -30,7 +32,7 @@ public class MultiTileEntityClassContainer { public boolean mHidden = false; public MultiTileEntityClassContainer(MultiTileEntityRegistry aRegistry, int aID, - Class<? extends BaseMultiTileEntity> aClass) { + Class<? extends MultiTileEntity> aClass) { /* Start the Builder */ mRegistry = new WeakReference<>(aRegistry); mID = (short) aID; @@ -127,14 +129,13 @@ public class MultiTileEntityClassContainer { } public MultiTileEntityClassContainer tier(int aTier) { - verifyDescendentOf(AdvancedCasing.class); - + verifyDescendentOfMultiple(true, UpgradeCasing.class, FunctionalCasing.class); mParameters.setInteger(NBT.TIER, aTier); return this; } public MultiTileEntityClassContainer upgradeInventorySize(int aSize) { - verifyDescendentOf(AdvancedCasing.class); + verifyDescendentOf(InventoryUpgrade.class); mParameters.setInteger(NBT.UPGRADE_INVENTORY_SIZE, aSize); return this; |
