aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities
diff options
context:
space:
mode:
authorAlkalus <3060479+draknyte1@users.noreply.github.com>2021-12-20 20:52:41 +0000
committerAlkalus <3060479+draknyte1@users.noreply.github.com>2021-12-20 20:52:41 +0000
commitaadb1b8f7f0f909feb747c05548351fcfe271de5 (patch)
tree1e7afec59218aab95e42e2bbeca524cd2a8f87eb /src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities
parent2dde5446791fab35321a1d18fb7ab017ef7872e1 (diff)
downloadGT5-Unofficial-aadb1b8f7f0f909feb747c05548351fcfe271de5.tar.gz
GT5-Unofficial-aadb1b8f7f0f909feb747c05548351fcfe271de5.tar.bz2
GT5-Unofficial-aadb1b8f7f0f909feb747c05548351fcfe271de5.zip
Refactored GT_MetaTileEntity_Hatch_AirIntake_Extreme to extend GT_MetaTileEntity_Hatch_AirIntake.
Refactored GT_MetaTileEntity_Hatch_Reservoir. Refactored Chisel singles/multi to utilise a cache.
Diffstat (limited to 'src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities')
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java62
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java57
2 files changed, 86 insertions, 33 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java
index ea99f8d52a..3cdd43c24e 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/basic/GregtechMetaTileEntity_AutoChisel.java
@@ -9,13 +9,15 @@ import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_Recipe;
-import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import net.minecraft.item.ItemStack;
import team.chisel.carving.Carving;
public class GregtechMetaTileEntity_AutoChisel extends GT_MetaTileEntity_BasicMachine {
+ private ItemStack mInputCache;
+ private ItemStack mOutputCache;
+
public GregtechMetaTileEntity_AutoChisel(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 1, "Chisels things, Gregtech style", 1, 1, "Compressor.png", "",
new ITexture[]{
@@ -54,10 +56,30 @@ public class GregtechMetaTileEntity_AutoChisel extends GT_MetaTileEntity_BasicMa
public GT_Recipe.GT_Recipe_Map getRecipeList() {
return null;
}
+
+ private boolean hasValidCache(ItemStack mItem, boolean mClearOnFailure) {
+ if (mInputCache != null
+ && mOutputCache != null
+ && mInputCache.isItemEqual(mItem)
+ && ItemStack.areItemStackTagsEqual(mItem, mInputCache)) {
+ return true;
+ }
+ // clear cache if it was invalid
+ if (mClearOnFailure) {
+ mInputCache = null;
+ mOutputCache = null;
+ }
+ return false;
+ }
+
+ private void cacheItem(ItemStack mInputItem, ItemStack mOutputItem) {
+ mOutputCache = mOutputItem.copy();
+ mInputCache = mInputItem.copy();
+ }
@Override
protected boolean allowPutStackValidated(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
- return super.allowPutStackValidated(aBaseMetaTileEntity, aIndex, aSide, aStack) && hasChiselResults(aStack);
+ return hasValidCache(aStack, false) ? true : super.allowPutStackValidated(aBaseMetaTileEntity, aIndex, aSide, aStack) && hasChiselResults(aStack);
}
// lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target
@@ -81,48 +103,46 @@ public class GregtechMetaTileEntity_AutoChisel extends GT_MetaTileEntity_BasicMa
return Carving.chisel.getItemsForChiseling(aStack);
}
+ private static ItemStack getChiselOutput(ItemStack aInput, ItemStack aTarget) {
+ ItemStack tOutput = null;
+ if (aTarget != null && canBeMadeFrom(aInput, aTarget)) {
+ tOutput = aTarget;
+ }
+ else {
+ tOutput = getItemsForChiseling(aInput).get(0);
+ }
+ return tOutput;
+ }
+
@Override
public int checkRecipe() {
ItemStack tOutput = null;
ItemStack aInput = getInputAt(0);
ItemStack aTarget = getSpecialSlot();
+ boolean tIsCached = hasValidCache(aInput, true);
if (aInput != null && hasChiselResults(aInput) && aInput.stackSize > 0) {
- Logger.INFO("Has Valid Input.");
- if (aTarget != null && canBeMadeFrom(aInput, aTarget)) {
- tOutput = aTarget;
- Logger.INFO("Has Valid Target.");
- }
- else {
- tOutput = getItemsForChiseling(aInput).get(0);
- Logger.INFO("Using target(0)");
- }
+ tOutput = tIsCached ? mOutputCache.copy() : getChiselOutput(aInput, aTarget);
if (tOutput != null) {
- Logger.INFO("Has Valid Output. "+tOutput.getDisplayName());
// We can chisel this
if (canOutput(tOutput)) {
- Logger.INFO("Can Output");
getInputAt(0).stackSize -= 1;
- Logger.INFO("Consuming 1 input");
calculateOverclockedNess(16, 20);
- Logger.INFO("Did Overclock");
//In case recipe is too OP for that machine
if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1) {
- Logger.INFO("Brrrrr");
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
}
- Logger.INFO("Setting Output");
- this.mOutputItems[0] = tOutput;
- Logger.INFO("Recipe good.");
+ if (!tIsCached) {
+ cacheItem(aInput, tOutput);
+ }
+ this.mOutputItems[0] = tOutput.copy();
return FOUND_AND_SUCCESSFULLY_USED_RECIPE;
}
else {
- Logger.INFO("Cannot Output");
mOutputBlocked++;
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
}
}
}
- Logger.INFO("Recipe bad.");
return DID_NOT_FIND_RECIPE;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java
index 77cc19d5d4..290a36c052 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/processing/GregtechMetaTileEntity_IndustrialChisel.java
@@ -29,7 +29,6 @@ import gregtech.api.util.GTPP_Recipe;
import gregtech.api.util.GT_Multiblock_Tooltip_Builder;
import gregtech.api.util.GT_Recipe;
import gregtech.api.util.GT_Utility;
-import gtPlusPlus.api.objects.Logger;
import gtPlusPlus.core.block.ModBlocks;
import gtPlusPlus.core.lib.CORE;
import gtPlusPlus.core.util.minecraft.ItemUtils;
@@ -44,6 +43,9 @@ public class GregtechMetaTileEntity_IndustrialChisel extends GregtechMeta_MultiB
private int mCasing;
private IStructureDefinition<GregtechMetaTileEntity_IndustrialChisel> STRUCTURE_DEFINITION = null;
+ private ItemStack mInputCache;
+ private ItemStack mOutputCache;
+ private GTPP_Recipe mCachedRecipe;
public GregtechMetaTileEntity_IndustrialChisel(int aID, String aName, String aNameRegional) {
super(aID, aName, aNameRegional);
@@ -173,6 +175,27 @@ public class GregtechMetaTileEntity_IndustrialChisel extends GregtechMeta_MultiB
return true;
}
+ private boolean hasValidCache(ItemStack aStack, ItemStack aSpecialSlot, boolean aClearOnFailure) {
+ if (mInputCache != null && mOutputCache != null && mCachedRecipe != null) {
+ if (GT_Utility.areStacksEqual(aStack, mInputCache) && GT_Utility.areStacksEqual(aSpecialSlot, mOutputCache)) {
+ return true;
+ }
+ }
+ // clear cache if it was invalid
+ if (aClearOnFailure) {
+ mInputCache = null;
+ mOutputCache = null;
+ mCachedRecipe = null;
+ }
+ return false;
+ }
+
+ private void cacheItem(ItemStack aInputItem, ItemStack aOutputItem, GTPP_Recipe aRecipe) {
+ mInputCache = aInputItem.copy();
+ mOutputCache = aOutputItem.copy();
+ mCachedRecipe = aRecipe;
+ }
+
// lets make sure the user isn't trying to make something from a block that doesn't have this as a valid target
private static boolean canBeMadeFrom(ItemStack from, ItemStack to) {
List<ItemStack> results = getItemsForChiseling(from);
@@ -194,18 +217,26 @@ public class GregtechMetaTileEntity_IndustrialChisel extends GregtechMeta_MultiB
return Carving.chisel.getItemsForChiseling(aStack);
}
+ private static ItemStack getChiselOutput(ItemStack aInput, ItemStack aTarget) {
+ ItemStack tOutput = null;
+ if (aTarget != null && canBeMadeFrom(aInput, aTarget)) {
+ tOutput = aTarget;
+ }
+ else {
+ tOutput = getItemsForChiseling(aInput).get(0);
+ }
+ return tOutput;
+ }
+
private GTPP_Recipe generateChiselRecipe(ItemStack aInput, ItemStack aTarget) {
- if (aInput != null && hasChiselResults(aInput) && aInput.stackSize > 0) {
- ItemStack tOutput = null;
- if (aTarget != null && canBeMadeFrom(aInput, aTarget)) {
- tOutput = aTarget;
- }
- else {
- tOutput = getItemsForChiseling(aInput).get(0);
- }
- if (tOutput != null) {
+ boolean tIsCached = hasValidCache(aInput, aTarget, true);
+ if (tIsCached || aInput != null && hasChiselResults(aInput)) {
+ ItemStack tOutput = tIsCached ? mOutputCache.copy() : getChiselOutput(aInput, aTarget);
+ if (tOutput != null) {
+ if (mCachedRecipe != null && GT_Utility.areStacksEqual(aInput, mInputCache) && GT_Utility.areStacksEqual(tOutput, mOutputCache)) {
+ return mCachedRecipe;
+ }
// We can chisel this
- log("Generated Chisel recipe good.");
GTPP_Recipe aRecipe = new GTPP_Recipe(
false,
new ItemStack[] {ItemUtils.getSimpleStack(aInput, 1)},
@@ -217,10 +248,12 @@ public class GregtechMetaTileEntity_IndustrialChisel extends GregtechMeta_MultiB
20,
16,
0);
+
+ // Cache it
+ cacheItem(aInput, tOutput, aRecipe);
return aRecipe;
}
}
- Logger.INFO("Recipe bad.");
return null;
}