aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common
diff options
context:
space:
mode:
authorD-Cysteine <54219287+D-Cysteine@users.noreply.github.com>2021-11-15 01:30:11 -0700
committerD-Cysteine <54219287+D-Cysteine@users.noreply.github.com>2021-11-15 02:23:59 -0700
commitb153c31432d22908097dac0e0c0181a1c097aaa4 (patch)
tree79507e7b9f03af9a648573f4e73b30e3b17699f7 /src/main/java/gregtech/common
parenta73802762161188fbd8539caba4164e4024fdeb3 (diff)
downloadGT5-Unofficial-b153c31432d22908097dac0e0c0181a1c097aaa4.tar.gz
GT5-Unofficial-b153c31432d22908097dac0e0c0181a1c097aaa4.tar.bz2
GT5-Unofficial-b153c31432d22908097dac0e0c0181a1c097aaa4.zip
Add locking support to LCR and PA
Diffstat (limited to 'src/main/java/gregtech/common')
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java131
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java104
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java12
3 files changed, 168 insertions, 79 deletions
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java
index 63b536fc72..87eddb7e13 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_LargeChemicalReactor.java
@@ -11,6 +11,7 @@ import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_EnhancedMul
import gregtech.api.render.TextureFactory;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Recipe;
+import gregtech.api.util.GT_Single_Recipe_Check;
import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
@@ -123,68 +124,98 @@ public class GT_MetaTileEntity_LargeChemicalReactor extends GT_MetaTileEntity_En
}
@Override
+ public boolean supportsSingleRecipeLocking() {
+ return true;
+ }
+
+ @Override
public boolean checkRecipe(ItemStack aStack) {
- ArrayList<ItemStack> tInputList = getStoredInputs();
- int tInputList_sS = tInputList.size();
- for (int i = 0; i < tInputList_sS - 1; i++) {
- for (int j = i + 1; j < tInputList_sS; j++) {
- if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) {
- if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) {
- tInputList.remove(j--);
- tInputList_sS = tInputList.size();
- } else {
- tInputList.remove(i--);
- tInputList_sS = tInputList.size();
- break;
+ long tVoltage = getMaxInputVoltage();
+ byte tier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
+ GT_Recipe tRecipe;
+
+ if (mLockedToSingleRecipe && mSingleRecipeCheck != null) {
+ if (!mSingleRecipeCheck.checkRecipeInputsSingleStack(true)) {
+ return false;
+ }
+
+ tRecipe = mSingleRecipeCheck.getRecipe();
+ } else {
+ ArrayList<ItemStack> tInputList = getStoredInputs();
+ int tInputList_sS = tInputList.size();
+ for (int i = 0; i < tInputList_sS - 1; i++) {
+ for (int j = i + 1; j < tInputList_sS; j++) {
+ if (GT_Utility.areStacksEqual(tInputList.get(i), tInputList.get(j))) {
+ if (tInputList.get(i).stackSize >= tInputList.get(j).stackSize) {
+ tInputList.remove(j--);
+ tInputList_sS = tInputList.size();
+ } else {
+ tInputList.remove(i--);
+ tInputList_sS = tInputList.size();
+ break;
+ }
}
}
}
- }
- tInputList.add(mInventory[1]);
- ItemStack[] inputs = tInputList.toArray(new ItemStack[0]);
-
- ArrayList<FluidStack> tFluidList = getStoredFluids();
- int tFluidList_sS = tFluidList.size();
- for (int i = 0; i < tFluidList_sS - 1; i++) {
- for (int j = i + 1; j < tFluidList_sS; j++) {
- if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) {
- if (tFluidList.get(i).amount >= tFluidList.get(j).amount) {
- tFluidList.remove(j--);
- tFluidList_sS = tFluidList.size();
- } else {
- tFluidList.remove(i--);
- tFluidList_sS = tFluidList.size();
- break;
+ tInputList.add(mInventory[1]);
+ ItemStack[] inputs = tInputList.toArray(new ItemStack[0]);
+
+ ArrayList<FluidStack> tFluidList = getStoredFluids();
+ int tFluidList_sS = tFluidList.size();
+ for (int i = 0; i < tFluidList_sS - 1; i++) {
+ for (int j = i + 1; j < tFluidList_sS; j++) {
+ if (GT_Utility.areFluidsEqual(tFluidList.get(i), tFluidList.get(j))) {
+ if (tFluidList.get(i).amount >= tFluidList.get(j).amount) {
+ tFluidList.remove(j--);
+ tFluidList_sS = tFluidList.size();
+ } else {
+ tFluidList.remove(i--);
+ tFluidList_sS = tFluidList.size();
+ break;
+ }
}
}
}
- }
- FluidStack[] fluids = tFluidList.toArray(new FluidStack[0]);
+ FluidStack[] fluids = tFluidList.toArray(new FluidStack[0]);
+
+ if (inputs.length == 0 && fluids.length == 0) {
+ return false;
+ }
- if (inputs.length > 0 || fluids.length > 0) {
- long tVoltage = getMaxInputVoltage();
- byte tier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
- GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sMultiblockChemicalRecipes.findRecipe(getBaseMetaTileEntity(), false,
+ GT_Single_Recipe_Check.Builder tSingleRecipeCheckBuilder = null;
+ if (mLockedToSingleRecipe) {
+ // We're locked to a single recipe, but haven't built the recipe checker yet.
+ // Build the checker on next successful recipe.
+ tSingleRecipeCheckBuilder = GT_Single_Recipe_Check.builder(this).setBefore();
+ }
+
+ tRecipe = GT_Recipe.GT_Recipe_Map.sMultiblockChemicalRecipes.findRecipe(getBaseMetaTileEntity(), false,
false, gregtech.api.enums.GT_Values.V[tier], fluids, inputs);
- if (tRecipe != null && tRecipe.isRecipeInputEqual(true, fluids, inputs)) {
- this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
- this.mEfficiencyIncrease = 10000;
-
- calculatePerfectOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage);
- //In case recipe is too OP for that machine
- if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1)
- return false;
- if (this.mEUt > 0) {
- this.mEUt = (-this.mEUt);
- }
- this.mOutputItems = tRecipe.mOutputs;
- this.mOutputFluids = tRecipe.mFluidOutputs;
- this.updateSlots();
- return true;
+ if (tRecipe == null || !tRecipe.isRecipeInputEqual(true, fluids, inputs)) {
+ return false;
+ }
+
+ if (mLockedToSingleRecipe) {
+ mSingleRecipeCheck = tSingleRecipeCheckBuilder.setAfter().setRecipe(tRecipe).build();
}
}
- return false;
+
+ this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
+ this.mEfficiencyIncrease = 10000;
+
+ calculatePerfectOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, 1, tVoltage);
+ //In case recipe is too OP for that machine
+ if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1)
+ return false;
+ if (this.mEUt > 0) {
+ this.mEUt = (-this.mEUt);
+ }
+
+ this.mOutputItems = tRecipe.mOutputs;
+ this.mOutputFluids = tRecipe.mFluidOutputs;
+ this.updateSlots();
+ return true;
}
@Override
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java
index ad0f5bd7f8..d5649ab0e4 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_ProcessingArray.java
@@ -19,6 +19,7 @@ import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_ProcessingArray_Manager;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Recipe.GT_Recipe_Map;
+import gregtech.api.util.GT_Single_Recipe_Check;
import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@@ -50,6 +51,12 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu
private boolean mSeparate = false;
private String mMachineName = "";
+ /** If locked to a single recipe, the locked recipe's amperage. */
+ private int mSingleRecipeAmperage;
+
+ /** If locked to a single recipe, the single-block machines that were used to run that single recipe. */
+ private ItemStack mSingleRecipeMachineStack;
+
public GT_MetaTileEntity_ProcessingArray(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
}
@@ -145,7 +152,16 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu
}
@Override
+ public boolean supportsSingleRecipeLocking() {
+ return true;
+ }
+
+ @Override
public boolean checkRecipe(ItemStack aStack) {
+ if (mLockedToSingleRecipe && mSingleRecipeCheck != null) {
+ return processLockedRecipe();
+ }
+
if (!isCorrectMachinePart(mInventory[1])) {
return false;
}
@@ -228,6 +244,27 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu
return false;
}
+ public boolean processLockedRecipe() {
+ if (!GT_Utility.areStacksEqual(mSingleRecipeMachineStack, mInventory[1])) {
+ // Machine stack was modified. This is not allowed, so stop processing.
+ return false;
+ }
+
+ int machines = Math.min(64, mInventory[1].stackSize << mMult); //Upped max Cap to 64
+ int i = 0;
+ for (; i < machines; i++) {
+ // TODO we should create a separate single recipe check class just for PAs.
+ // This class can memorize the amperage and machine stack for us, as well as compute
+ // the max number of runs in a single iteration over the inputs, rather than requiring
+ // one iteration per machine in the stack. But let's do that after we've tested this.
+ if (!mSingleRecipeCheck.checkRecipeInputs(true)) {
+ break;
+ }
+ }
+
+ return processRecipeOutputs(mSingleRecipeCheck.getRecipe(), mSingleRecipeAmperage, i);
+ }
+
public boolean processRecipe(ItemStack[] tInputs, FluidStack[] tFluids, GT_Recipe.GT_Recipe_Map map) {
if (tInputs.length <= 0 && tFluids.length <= 0) return false;
GT_Recipe tRecipe = map.findRecipe(getBaseMetaTileEntity(), mLastRecipe, false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs);
@@ -236,54 +273,74 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu
!isValidForLowGravity(tRecipe, getBaseMetaTileEntity().getWorld().provider.dimensionId))
return false;
+ GT_Single_Recipe_Check.Builder tSingleRecipeCheckBuilder = null;
+ if (mLockedToSingleRecipe) {
+ // We're locked to a single recipe, but haven't built the recipe checker yet.
+ // Build the checker on next successful recipe.
+ tSingleRecipeCheckBuilder = GT_Single_Recipe_Check.builder(this).setBefore();
+ }
+
+ boolean recipeLocked = false;
mLastRecipe = tRecipe;
- this.mEUt = 0;
- this.mOutputItems = null;
- this.mOutputFluids = null;
int machines = Math.min(64, mInventory[1].stackSize << mMult); //Upped max Cap to 64
int i = 0;
for (; i < machines; i++) {
if (!tRecipe.isRecipeInputEqual(true, tFluids, tInputs)) {
- if (i == 0) {
- return false;
- }
break;
+ } else if (mLockedToSingleRecipe && !recipeLocked) {
+ // We want to lock to a single run of the recipe.
+ mSingleRecipeCheck = tSingleRecipeCheckBuilder.setAfter().setRecipe(tRecipe).build();
+ mSingleRecipeAmperage = map.mAmperage;
+ mSingleRecipeMachineStack = mInventory[1].copy();
+ recipeLocked = true;
}
}
- this.mMaxProgresstime = tRecipe.mDuration;
+
+ return processRecipeOutputs(tRecipe, map.mAmperage, i);
+ }
+
+ public boolean processRecipeOutputs(GT_Recipe aRecipe, int aAmperage, int parallel) {
+ this.mEUt = 0;
+ this.mOutputItems = null;
+ this.mOutputFluids = null;
+ if (parallel == 0) {
+ return false;
+ }
+
+ this.mMaxProgresstime = aRecipe.mDuration;
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;
- calculateOverclockedNessMulti(tRecipe.mEUt, tRecipe.mDuration, map.mAmperage, GT_Values.V[tTier]);
+ calculateOverclockedNessMulti(aRecipe.mEUt, aRecipe.mDuration, aAmperage, GT_Values.V[tTier]);
//In case recipe is too OP for that machine
if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1)
return false;
- this.mEUt = GT_Utility.safeInt(((long) this.mEUt * i) >> mMult, 1);
+ this.mEUt = GT_Utility.safeInt(((long) this.mEUt * parallel) >> mMult, 1);
if (mEUt == Integer.MAX_VALUE - 1)
return false;
if (this.mEUt > 0) {
this.mEUt = (-this.mEUt);
}
- ItemStack[] tOut = new ItemStack[tRecipe.mOutputs.length];
- for (int h = 0; h < tRecipe.mOutputs.length; h++) {
- if (tRecipe.getOutput(h) != null) {
- tOut[h] = tRecipe.getOutput(h).copy();
+ ItemStack[] tOut = new ItemStack[aRecipe.mOutputs.length];
+ for (int h = 0; h < aRecipe.mOutputs.length; h++) {
+ if (aRecipe.getOutput(h) != null) {
+ tOut[h] = aRecipe.getOutput(h).copy();
tOut[h].stackSize = 0;
}
}
FluidStack tFOut = null;
- if (tRecipe.getFluidOutput(0) != null) tFOut = tRecipe.getFluidOutput(0).copy();
+ if (aRecipe.getFluidOutput(0) != null) tFOut = aRecipe.getFluidOutput(0).copy();
for (int f = 0; f < tOut.length; f++) {
- if (tRecipe.mOutputs[f] != null && tOut[f] != null) {
- for (int g = 0; g < i; g++) {
- if (getBaseMetaTileEntity().getRandomNumber(10000) < tRecipe.getOutputChance(f))
- tOut[f].stackSize += tRecipe.mOutputs[f].stackSize;
+ if (aRecipe.mOutputs[f] != null && tOut[f] != null) {
+ for (int g = 0; g < parallel; g++) {
+ if (getBaseMetaTileEntity().getRandomNumber(10000) < aRecipe.getOutputChance(f))
+ tOut[f].stackSize += aRecipe.mOutputs[f].stackSize;
}
}
}
if (tFOut != null) {
int tSize = tFOut.amount;
- tFOut.amount = tSize * i;
+ tFOut.amount = tSize * parallel;
}
this.mMaxProgresstime = Math.max(1, this.mMaxProgresstime);
this.mOutputItems = Arrays.stream(tOut)
@@ -353,8 +410,13 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu
@Override
public final void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
- mSeparate = !mSeparate;
- GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.machines.separatebus") + " " + mSeparate);
+ if (aPlayer.isSneaking()) {
+ // Lock to single recipe
+ super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ);
+ } else {
+ mSeparate = !mSeparate;
+ GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.machines.separatebus") + " " + mSeparate);
+ }
}
@Override
diff --git a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java
index 428931e654..9542c54ce0 100644
--- a/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java
+++ b/src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java
@@ -147,21 +147,17 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_EnhancedMu
tRecipe = mSingleRecipeCheck.getRecipe();
} else {
- GT_Single_Recipe_Check.Builder tSingleRecipeCheckBuilder = null;
- if (mLockedToSingleRecipe) {
- // We're locked to a single recipe, but haven't built the recipe checker yet.
- // Build the checker on next successful recipe.
- tSingleRecipeCheckBuilder = GT_Single_Recipe_Check.builder(this);
- }
-
ItemStack[] tInputs = getCompactedInputs();
FluidStack[] tFluids = getCompactedFluids();
if (tInputs.length <= 0)
return false;
+ GT_Single_Recipe_Check.Builder tSingleRecipeCheckBuilder = null;
if (mLockedToSingleRecipe) {
- tSingleRecipeCheckBuilder.setBefore();
+ // We're locked to a single recipe, but haven't built the recipe checker yet.
+ // Build the checker on next successful recipe.
+ tSingleRecipeCheckBuilder = GT_Single_Recipe_Check.builder(this).setBefore();
}
tRecipe = GT_Recipe.GT_Recipe_Map.sPyrolyseRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs);