aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/tileentities/machines
diff options
context:
space:
mode:
authorMartin Robertz <dream-master@gmx.net>2021-11-20 09:42:31 +0100
committerGitHub <noreply@github.com>2021-11-20 09:42:31 +0100
commit182dffe8e1d2ed0f96c80b40764c121da5c39f53 (patch)
tree13f03f2d23ce7e33bd0c70d19cd7a24b26a21240 /src/main/java/gregtech/common/tileentities/machines
parent36ab4741d560e11bc906d4173445a0a06a5b08da (diff)
parent1dd66efceca26d9931010adb24932bba408ca630 (diff)
downloadGT5-Unofficial-182dffe8e1d2ed0f96c80b40764c121da5c39f53.tar.gz
GT5-Unofficial-182dffe8e1d2ed0f96c80b40764c121da5c39f53.tar.bz2
GT5-Unofficial-182dffe8e1d2ed0f96c80b40764c121da5c39f53.zip
Merge pull request #732 from D-Cysteine/lock-single-recipe
[Proof of concept] Allow locking multi-block machines to a single recipe, to reduce server cost
Diffstat (limited to 'src/main/java/gregtech/common/tileentities/machines')
-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.java89
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/multi/GT_MetaTileEntity_PyrolyseOven.java45
3 files changed, 185 insertions, 80 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..a48f63c60a 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_Processing_Array;
import gregtech.api.util.GT_Utility;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
@@ -145,7 +146,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 +238,15 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu
return false;
}
+ public boolean processLockedRecipe() {
+ GT_Single_Recipe_Check_Processing_Array tSingleRecipeCheck = (GT_Single_Recipe_Check_Processing_Array) mSingleRecipeCheck;
+
+ int machines = Math.min(64, mInventory[1].stackSize << mMult); //Upped max Cap to 64
+ int parallel = tSingleRecipeCheck.checkRecipeInputs(true, machines);
+
+ return processRecipeOutputs(tSingleRecipeCheck.getRecipe(), tSingleRecipeCheck.getRecipeAmperage(), parallel);
+ }
+
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 +255,77 @@ public class GT_MetaTileEntity_ProcessingArray extends GT_MetaTileEntity_CubicMu
!isValidForLowGravity(tRecipe, getBaseMetaTileEntity().getWorld().provider.dimensionId))
return false;
+ GT_Single_Recipe_Check_Processing_Array.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_Processing_Array.processingArrayBuilder(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)
+ .setRecipeAmperage(map.mAmperage)
+ .build();
+ 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 +395,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 ae96b82a23..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
@@ -16,6 +16,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;
@@ -129,19 +130,45 @@ public class GT_MetaTileEntity_PyrolyseOven extends GT_MetaTileEntity_EnhancedMu
}
@Override
- public boolean checkRecipe(ItemStack aStack) {
- ItemStack[] tInputs = getCompactedInputs();
- FluidStack[] tFluids = getCompactedFluids();
-
- if (tInputs.length <= 0)
- return false;
+ public boolean supportsSingleRecipeLocking() {
+ return true;
+ }
+ @Override
+ public boolean checkRecipe(ItemStack aStack) {
long tVoltage = getMaxInputVoltage();
byte tTier = (byte) Math.max(1, GT_Utility.getTier(tVoltage));
- GT_Recipe tRecipe = GT_Recipe.GT_Recipe_Map.sPyrolyseRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs);
+ GT_Recipe tRecipe;
- if (tRecipe == null || !tRecipe.isRecipeInputEqual(true, tFluids, tInputs))
- return false;
+ if (mLockedToSingleRecipe && mSingleRecipeCheck != null) {
+ if (!mSingleRecipeCheck.checkRecipeInputsSingleStack(true)) {
+ return false;
+ }
+
+ tRecipe = mSingleRecipeCheck.getRecipe();
+ } else {
+ ItemStack[] tInputs = getCompactedInputs();
+ FluidStack[] tFluids = getCompactedFluids();
+
+ if (tInputs.length <= 0)
+ 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();
+ }
+
+ tRecipe = GT_Recipe.GT_Recipe_Map.sPyrolyseRecipes.findRecipe(getBaseMetaTileEntity(), false, gregtech.api.enums.GT_Values.V[tTier], tFluids, tInputs);
+
+ if (tRecipe == null || !tRecipe.isRecipeInputEqual(true, tFluids, tInputs))
+ return false;
+
+ if (mLockedToSingleRecipe) {
+ mSingleRecipeCheck = tSingleRecipeCheckBuilder.setAfter().setRecipe(tRecipe).build();
+ }
+ }
this.mEfficiency = (10000 - (getIdealStatus() - getRepairStatus()) * 1000);
this.mEfficiencyIncrease = 10000;