aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/gregtech
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
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')
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java2
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java80
-rw-r--r--src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java20
-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
5 files changed, 93 insertions, 128 deletions
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java
index 4716d8038a..02b7a03f3b 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake.java
@@ -29,7 +29,7 @@ public class GT_MetaTileEntity_Hatch_AirIntake extends GT_MetaTileEntity_Hatch_F
String[] aTooltip = new String[3];
aTooltip[0] = "DO NOT OBSTRUCT THE INPUT!";
aTooltip[1] = "Draws in Air from the surrounding environment";
- aTooltip[2] = "Creates 1000L of Air every 4 ticks";
+ aTooltip[2] = "Creates "+getAmountOfFluidToGenerate()+"L of Air every "+getMaxTickTime()+" ticks";
return aTooltip;
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java
index d70afcb433..45611d9e05 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_AirIntake_Extreme.java
@@ -3,13 +3,8 @@ package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
-import gtPlusPlus.core.lib.CORE;
-import gtPlusPlus.core.util.minecraft.FluidUtils;
-import net.minecraft.world.World;
-import net.minecraftforge.common.util.ForgeDirection;
-import net.minecraftforge.fluids.Fluid;
-public class GT_MetaTileEntity_Hatch_AirIntake_Extreme extends GT_MetaTileEntity_Hatch_FluidGenerator {
+public class GT_MetaTileEntity_Hatch_AirIntake_Extreme extends GT_MetaTileEntity_Hatch_AirIntake {
public GT_MetaTileEntity_Hatch_AirIntake_Extreme(final int aID, final String aName, final String aNameRegional, final int aTier) {
super(aID, aName, aNameRegional, aTier);
@@ -25,86 +20,13 @@ public class GT_MetaTileEntity_Hatch_AirIntake_Extreme extends GT_MetaTileEntity
}
@Override
- public String[] getCustomTooltip() {
- String[] aTooltip = new String[3];
- aTooltip[0] = "DO NOT OBSTRUCT THE INPUT!";
- aTooltip[1] = "Draws in Air from the surrounding environment";
- aTooltip[2] = "Creates 8000L of Air every 4 ticks";
- return aTooltip;
- }
-
- @Override
- public Fluid getFluidToGenerate() {
- return FluidUtils.getAir(1).getFluid();
- }
-
- @Override
public int getAmountOfFluidToGenerate() {
return 8000;
}
@Override
- public int getMaxTickTime() {
- return 4;
- }
-
- @Override
public int getCapacity() {
return 256000;
}
- @Override
- public boolean doesHatchMeetConditionsToGenerate() {
- return this.getBaseMetaTileEntity().getAirAtSide(this.getBaseMetaTileEntity().getFrontFacing());
- }
-
- @Override
- public void generateParticles(World aWorld, String name) {
- if (this.getBaseMetaTileEntity().isServerSide()) {
- return;
- }
- final float ran1 = GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat();
- float ran2 = 0.0f;
- float ran3 = 0.0f;
- ran2 = GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat();
- ran3 = GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat();
-
- final IGregTechTileEntity aMuffler = this.getBaseMetaTileEntity();
- final ForgeDirection aDir = ForgeDirection.getOrientation((int) aMuffler.getFrontFacing());
- final float xPos = aDir.offsetX * 0.76f + aMuffler.getXCoord() + 0.25f;
- float yPos = aDir.offsetY * 0.76f + aMuffler.getYCoord() + 0.65f;
- final float zPos = aDir.offsetZ * 0.76f + aMuffler.getZCoord() + 0.25f;
- float ySpd = aDir.offsetY * 0.1f + 0.2f + 0.1f * GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat();
- float xSpd;
- float zSpd;
- if (aDir.offsetY == -1) {
- //Logger.INFO("Y = -1");
- final float temp = GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat() * 2.0f * CORE.PI;
- xSpd = (float) Math.sin(temp) * 0.1f;
- zSpd = (float) Math.cos(temp) * 0.1f;
- ySpd = -ySpd;
- yPos = yPos - 0.8f;
- }
- else {
- xSpd = aDir.offsetX * (0.1f + 0.2f * GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat());
- zSpd = aDir.offsetZ * (0.1f + 0.2f * GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat());
-
- xSpd = -xSpd;
- zSpd = -zSpd;
- }
-
- aWorld.spawnParticle(name, (double) (xPos + ran1 * 0.5f),
- (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat() * 0.5f),
- (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat() * 0.5f), (double) xSpd,
- (double) -ySpd, (double) zSpd);
- aWorld.spawnParticle(name, (double) (xPos + ran2 * 0.5f),
- (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat() * 0.5f),
- (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat() * 0.5f), (double) xSpd,
- (double) -ySpd, (double) zSpd);
- aWorld.spawnParticle(name, (double) (xPos + ran3 * 0.5f),
- (double) (yPos + GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat() * 0.5f),
- (double) (zPos + GT_MetaTileEntity_Hatch_AirIntake_Extreme.floatGen.nextFloat() * 0.5f), (double) xSpd,
- (double) -ySpd, (double) zSpd);
- }
-
}
diff --git a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java
index a2aa4d266c..716251ecf0 100644
--- a/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java
+++ b/src/main/java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GT_MetaTileEntity_Hatch_Reservoir.java
@@ -1,13 +1,11 @@
package gtPlusPlus.xmod.gregtech.api.metatileentity.implementations;
-import java.lang.reflect.Field;
-
+import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.objects.GT_RenderedTexture;
import gtPlusPlus.core.lib.LoadedMods;
-import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
@@ -20,10 +18,6 @@ import net.minecraftforge.fluids.IFluidHandler;
public class GT_MetaTileEntity_Hatch_Reservoir extends GT_MetaTileEntity_Hatch_FluidGenerator {
- private static Class sClass_EIO;
- private static Class sClass_RIO;
- private static Field sField_EIO;
- private static Field sField_RIO;
private static Block sBlock_EIO;
private static Block sBlock_RIO;
@@ -70,15 +64,11 @@ public class GT_MetaTileEntity_Hatch_Reservoir extends GT_MetaTileEntity_Hatch_F
}
private static void setCrossModData() {
- if (LoadedMods.EnderIO && sClass_EIO == null) {
- sClass_EIO = ReflectionUtils.getClass("crazypants.enderio.EnderIO");
- sField_EIO = ReflectionUtils.getField(sClass_EIO, "blockReservoir");
- sBlock_EIO = ReflectionUtils.getFieldValue(sField_EIO, null);
+ if (LoadedMods.EnderIO && sBlock_EIO == null) {
+ sBlock_EIO = GameRegistry.findBlock("EnderIO", "blockReservoir");
}
- if (LoadedMods.RemoteIO && sClass_RIO == null) {
- sClass_RIO = ReflectionUtils.getClass("remoteio.common.lib.ModBlocks");
- sField_RIO = ReflectionUtils.getField(sClass_RIO, "machine");
- sBlock_RIO = ReflectionUtils.getFieldValue(sField_RIO, null);
+ if (LoadedMods.RemoteIO && sBlock_RIO == null) {
+ sBlock_RIO = GameRegistry.findBlock("RIO", "machine");
}
}
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;
}