33import gregtech .api .GTValues ;
44import gregtech .api .capability .GregtechDataCodes ;
55import gregtech .api .capability .GregtechTileCapabilities ;
6+ import gregtech .api .capability .IEnergyContainer ;
67import gregtech .api .capability .IMultiblockController ;
78import gregtech .api .capability .IMultipleTankHandler ;
89import gregtech .api .capability .IWorkable ;
@@ -101,17 +102,27 @@ public AbstractRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap, bo
101102 /**
102103 * @return the energy container's energy input per second
103104 */
104- protected abstract long getEnergyInputPerSecond ();
105+ protected long getEnergyInputPerSecond () {
106+ return getEnergyContainer ().getInputPerSec ();
107+ }
105108
106109 /**
107110 * @return the energy container's current stored energy
108111 */
109- protected abstract long getEnergyStored ();
112+ protected long getEnergyStored () {
113+ return getEnergyContainer ().getEnergyStored ();
114+ }
110115
111116 /**
112117 * @return the energy container's maximum energy capacity
113118 */
114- protected abstract long getEnergyCapacity ();
119+ protected long getEnergyCapacity () {
120+ return getEnergyContainer ().getEnergyCapacity ();
121+ }
122+
123+ protected IEnergyContainer getEnergyContainer () {
124+ return IEnergyContainer .DEFAULT ;
125+ }
115126
116127 /**
117128 * Draw energy from the energy container
@@ -120,12 +131,22 @@ public AbstractRecipeLogic(MetaTileEntity tileEntity, RecipeMap<?> recipeMap, bo
120131 * @param simulate whether to simulate energy extraction or not
121132 * @return true if the energy can/was drained, otherwise false
122133 */
123- protected abstract boolean drawEnergy (long recipeEUt , boolean simulate );
134+ protected boolean drawEnergy (long recipeEUt , boolean simulate ) {
135+ // this should be the ONLY time eut is negative!
136+ if (consumesEnergy ()) recipeEUt = -recipeEUt ;
137+ long resultEnergy = getEnergyStored () + recipeEUt ;
138+ if (resultEnergy >= 0L && resultEnergy <= getEnergyCapacity ()) {
139+ if (!simulate ) getEnergyContainer ().changeEnergy (recipeEUt );
140+ return true ;
141+ } else return false ;
142+ }
124143
125144 /**
126145 * @return the maximum voltage the machine can use/handle for recipe searching
127146 */
128- public abstract long getMaxVoltage ();
147+ public long getMaxVoltage () {
148+ return Math .max (getEnergyContainer ().getInputVoltage (), getEnergyContainer ().getOutputVoltage ());
149+ }
129150
130151 /**
131152 *
@@ -941,7 +962,7 @@ public String[] getAvailableOverclockingTiers() {
941962 protected void setupRecipe (@ NotNull Recipe recipe ) {
942963 this .progressTime = 1 ;
943964 setMaxProgress (ocResult .duration ());
944- this .recipeEUt = consumesEnergy () ? ocResult . eut () : - ocResult .eut ();
965+ this .recipeEUt = ocResult .eut ();
945966
946967 int recipeTier = GTUtility .getTierByVoltage (recipe .getEUt ());
947968 int machineTier = getOverclockForTier (getMaximumOverclockVoltage ());
@@ -1226,7 +1247,7 @@ public void deserializeNBT(@NotNull NBTTagCompound compound) {
12261247 if (progressTime > 0 ) {
12271248 this .isActive = true ;
12281249 this .maxProgressTime = compound .getInteger ("MaxProgress" );
1229- this .recipeEUt = compound .getLong ("RecipeEUt" );
1250+ this .recipeEUt = Math . abs ( compound .getLong ("RecipeEUt" ) );
12301251 NBTTagList itemOutputsList = compound .getTagList ("ItemOutputs" , Constants .NBT .TAG_COMPOUND );
12311252 this .itemOutputs = new ArrayList <>(itemOutputsList .tagCount ());
12321253 for (int i = 0 ; i < itemOutputsList .tagCount (); i ++) {
0 commit comments