aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/tileentities/machines/basic
diff options
context:
space:
mode:
authorKiwi <42833050+Kiwi233@users.noreply.github.com>2020-12-13 21:24:20 +0800
committerGitHub <noreply@github.com>2020-12-13 21:24:20 +0800
commitd567ee9f63c6e11f2b21f26687cfc2ecaed200a1 (patch)
tree8e4c275624a966c4482b90ad85cda2375c6a63b9 /src/main/java/gregtech/common/tileentities/machines/basic
parentcec32d0a604156802eee3f9e8fefccb40a62d7ef (diff)
parent7ce77a615de68add2bb0fa71818b3e36241a02a7 (diff)
downloadGT5-Unofficial-d567ee9f63c6e11f2b21f26687cfc2ecaed200a1.tar.gz
GT5-Unofficial-d567ee9f63c6e11f2b21f26687cfc2ecaed200a1.tar.bz2
GT5-Unofficial-d567ee9f63c6e11f2b21f26687cfc2ecaed200a1.zip
Merge pull request #2 from GTNewHorizons/experimental
5.09.33.57
Diffstat (limited to 'src/main/java/gregtech/common/tileentities/machines/basic')
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_AdvSeismicProspector.java11
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Boxinator.java61
-rw-r--r--src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java88
3 files changed, 96 insertions, 64 deletions
diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_AdvSeismicProspector.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_AdvSeismicProspector.java
index 46ea555ad0..28f661c339 100644
--- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_AdvSeismicProspector.java
+++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_AdvSeismicProspector.java
@@ -216,12 +216,13 @@ public class GT_MetaTileEntity_AdvSeismicProspector extends GT_MetaTileEntity_Ba
}
} else {
int tMetaID = getBaseMetaTileEntity().getWorld().getBlockMetadata(x, y, z);
- ItemData tAssotiation = GT_OreDictUnificator.getAssociation(new ItemStack(tBlock, 1, tMetaID));
-
- if ((tAssotiation != null) && (tAssotiation.mPrefix.toString().startsWith("ore")))
- return tAssotiation.mMaterial.mMaterial.mDefaultLocalName;
+ ItemStack is = new ItemStack(tBlock, 1, tMetaID);
+ ItemData association = GT_OreDictUnificator.getAssociation(is);
+ if ((association != null) && (association.mPrefix.toString().startsWith("ore")))
+ return association.mMaterial.mMaterial.mDefaultLocalName;
+ else if (GT_Utility.isOre(is))
+ return tBlock.getLocalizedName();
}
-
return null;
}
diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Boxinator.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Boxinator.java
index 938c2d6900..6895310b46 100644
--- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Boxinator.java
+++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Boxinator.java
@@ -6,6 +6,7 @@ import gregtech.api.interfaces.ITexture;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.MetaTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine;
+import gregtech.api.objects.GT_ItemStack;
import gregtech.api.objects.GT_RenderedTexture;
import gregtech.api.util.GT_ModHandler;
import gregtech.api.util.GT_Recipe;
@@ -14,6 +15,10 @@ import net.minecraft.item.ItemStack;
public class GT_MetaTileEntity_Boxinator
extends GT_MetaTileEntity_BasicMachine {
+ ItemStack aInputCache;
+ ItemStack aOutputCache;
+ int aTypeCache = 0;
+
public GT_MetaTileEntity_Boxinator(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 1, "Puts things into Boxes", 2, 1, "Packager.png", "", new ITexture[]{new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_BOXINATOR_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_SIDE_BOXINATOR), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_BOXINATOR_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_FRONT_BOXINATOR), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_BOXINATOR_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_TOP_BOXINATOR), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_BOXINATOR_ACTIVE), new GT_RenderedTexture(Textures.BlockIcons.OVERLAY_BOTTOM_BOXINATOR)});
}
@@ -34,28 +39,56 @@ public class GT_MetaTileEntity_Boxinator
return GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes;
}
+ private boolean hasValidCache(ItemStack mItem,int mType,boolean mClearOnFailure) {
+ if (aInputCache != null
+ && aOutputCache != null
+ && aTypeCache == mType
+ && aInputCache.isItemEqual(mItem)
+ && ItemStack.areItemStackTagsEqual(mItem,aInputCache))
+ return true;
+ // clear cache if it was invalid
+ if (mClearOnFailure) {
+ aInputCache = null;
+ aOutputCache = null;
+ aTypeCache = 0;
+ }
+ return false;
+ }
+
+ private void cacheItem(ItemStack mInputItem,ItemStack mOutputItem,int mType) {
+ aTypeCache = mType;
+ aOutputCache = mOutputItem.copy();
+ aInputCache = mInputItem.copy();
+ }
+
public int checkRecipe() {
int tCheck = super.checkRecipe();
if (tCheck != DID_NOT_FIND_RECIPE) {
return tCheck;
}
- if ((GT_Utility.isStackValid(getInputAt(0))) && (GT_Utility.isStackValid(getInputAt(1))) && (GT_Utility.getContainerItem(getInputAt(0), true) == null)) {
- if ((ItemList.Schematic_1by1.isStackEqual(getInputAt(1))) && (getInputAt(0).stackSize >= 1)) {
- this.mOutputItems[0] = GT_ModHandler.getRecipeOutput(new ItemStack[]{getInputAt(0)});
+ ItemStack tSlot0 = getInputAt(0);
+ ItemStack tSlot1 = getInputAt(1);
+ if ((GT_Utility.isStackValid(tSlot0)) && (GT_Utility.isStackValid(tSlot1)) && (GT_Utility.getContainerItem(tSlot0, true) == null)) {
+ if ((ItemList.Schematic_1by1.isStackEqual(tSlot1)) && (tSlot0.stackSize >= 1)) {
+ boolean tIsCached = hasValidCache(tSlot0,1,true);
+ this.mOutputItems[0] = tIsCached ? aOutputCache.copy() : GT_ModHandler.getRecipeOutput(new ItemStack[]{tSlot0});
if (this.mOutputItems[0] != null) {
if (canOutput(new ItemStack[]{this.mOutputItems[0]})) {
- getInputAt(0).stackSize -= 1;
+ tSlot0.stackSize -= 1;
calculateOverclockedNess(32,16);
//In case recipe is too OP for that machine
if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1)
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
+ if (!tIsCached)
+ cacheItem(tSlot0,this.mOutputItems[0],1);
return FOUND_AND_SUCCESSFULLY_USED_RECIPE;
}
}
return DID_NOT_FIND_RECIPE;
}
- if ((ItemList.Schematic_2by2.isStackEqual(getInputAt(1))) && (getInputAt(0).stackSize >= 4)) {
- this.mOutputItems[0] = GT_ModHandler.getRecipeOutput(new ItemStack[]{getInputAt(0), getInputAt(0), null, getInputAt(0), getInputAt(0)});
+ if ((ItemList.Schematic_2by2.isStackEqual(tSlot1)) && (getInputAt(0).stackSize >= 4)) {
+ boolean tIsCached = hasValidCache(tSlot0,2,true);
+ this.mOutputItems[0] = tIsCached ? aOutputCache.copy() : GT_ModHandler.getRecipeOutput(new ItemStack[]{tSlot0, tSlot0, null, tSlot0, tSlot0});
if (this.mOutputItems[0] != null) {
if (canOutput(new ItemStack[]{this.mOutputItems[0]})) {
getInputAt(0).stackSize -= 4;
@@ -63,13 +96,16 @@ public class GT_MetaTileEntity_Boxinator
//In case recipe is too OP for that machine
if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1)
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
+ if (!tIsCached)
+ cacheItem(tSlot0,this.mOutputItems[0],2);
return FOUND_AND_SUCCESSFULLY_USED_RECIPE;
}
}
return DID_NOT_FIND_RECIPE;
}
- if ((ItemList.Schematic_3by3.isStackEqual(getInputAt(1))) && (getInputAt(0).stackSize >= 9)) {
- this.mOutputItems[0] = GT_ModHandler.getRecipeOutput(new ItemStack[]{getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0), getInputAt(0)});
+ if ((ItemList.Schematic_3by3.isStackEqual(tSlot1)) && (getInputAt(0).stackSize >= 9)) {
+ boolean tIsCached = hasValidCache(tSlot0,3,true);
+ this.mOutputItems[0] = tIsCached ? aOutputCache.copy() : GT_ModHandler.getRecipeOutput(new ItemStack[]{tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0, tSlot0});
if (this.mOutputItems[0] != null) {
if (canOutput(new ItemStack[]{this.mOutputItems[0]})) {
getInputAt(0).stackSize -= 9;
@@ -77,6 +113,8 @@ public class GT_MetaTileEntity_Boxinator
//In case recipe is too OP for that machine
if (mMaxProgresstime == Integer.MAX_VALUE - 1 && mEUt == Integer.MAX_VALUE - 1)
return FOUND_RECIPE_BUT_DID_NOT_MEET_REQUIREMENTS;
+ if (!tIsCached)
+ cacheItem(tSlot0,this.mOutputItems[0],3);
return FOUND_AND_SUCCESSFULLY_USED_RECIPE;
}
}
@@ -88,8 +126,11 @@ public class GT_MetaTileEntity_Boxinator
public boolean allowPutStack(IGregTechTileEntity aBaseMetaTileEntity, int aIndex, byte aSide, ItemStack aStack) {
if (super.allowPutStack(aBaseMetaTileEntity, aIndex, aSide, aStack)) {
- if ((ItemList.Schematic_1by1.isStackEqual(getInputAt(1))) || (ItemList.Schematic_2by2.isStackEqual(getInputAt(1))) || (ItemList.Schematic_3by3.isStackEqual(getInputAt(1)))) {
- if (GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes.findRecipe(getBaseMetaTileEntity(), true, gregtech.api.enums.GT_Values.V[mTier], null, new ItemStack[]{GT_Utility.copyAmount(64L, new Object[]{aStack}), getInputAt(1)}) != null) {
+ ItemStack tInput1 = getInputAt(1);
+ if ((ItemList.Schematic_1by1.isStackEqual(tInput1)) || (ItemList.Schematic_2by2.isStackEqual(tInput1)) || (ItemList.Schematic_3by3.isStackEqual(tInput1))) {
+ if (hasValidCache(aStack,aTypeCache,false))
+ return true;
+ if (GT_Recipe.GT_Recipe_Map.sBoxinatorRecipes.findRecipe(getBaseMetaTileEntity(), true, gregtech.api.enums.GT_Values.V[mTier], null, new ItemStack[]{GT_Utility.copyAmount(64L, new Object[]{aStack}), tInput1}) != null) {
return true;
}
if (ItemList.Schematic_1by1.isStackEqual(getInputAt(1)) && GT_ModHandler.getRecipeOutput(new ItemStack[]{aStack}) != null)
diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java
index 44db32e6b9..69543a7196 100644
--- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java
+++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java
@@ -6,13 +6,12 @@ import gregtech.api.interfaces.metatileentity.IMetaTileEntity;
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
import gregtech.api.metatileentity.implementations.GT_MetaTileEntity_BasicMachine;
import gregtech.api.objects.GT_RenderedTexture;
-import gregtech.api.objects.ItemData;
import gregtech.api.util.GT_Log;
import gregtech.api.util.GT_ModHandler;
-import gregtech.api.util.GT_OreDictUnificator;
import gregtech.api.util.GT_Utility;
import gregtech.common.blocks.GT_Block_Ores_Abstract;
import gregtech.common.blocks.GT_TileEntity_Ores;
+
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
@@ -21,6 +20,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
+import net.minecraft.world.ChunkPosition;
import net.minecraftforge.common.util.FakePlayer;
import java.util.ArrayList;
@@ -33,7 +33,7 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine {
private static final Block MINING_PIPE_BLOCK = GT_Utility.getBlockFromStack(MINING_PIPE);
private static final Block MINING_PIPE_TIP_BLOCK = GT_Utility.getBlockFromStack(GT_ModHandler.getIC2Item("miningPipeTip", 0));
- int drillX, drillY, drillZ;
+ int drillY = 0;
boolean isPickingPipes;
boolean waitMiningPipe;
final static int[] RADIUS = new int[]{8, 8, 16, 24, 32}; //Miner radius per tier
@@ -41,6 +41,7 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine {
final static int[] ENERGY = new int[]{8, 8, 32, 128, 512}; //Miner energy consumption per tier
private int radiusConfig; //Miner configured radius
+ private final ArrayList<ChunkPosition> oreBlockPositions = new ArrayList<>();
public GT_MetaTileEntity_Miner(int aID, String aName, String aNameRegional, int aTier) {
super(aID, aName, aNameRegional, aTier, 1,
@@ -90,7 +91,7 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine {
}
return true;
}
-
+
@Override
public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
super.onScrewdriverRightClick(aSide, aPlayer, aX, aY, aZ);
@@ -109,8 +110,14 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine {
radiusConfig = 0;
}
GT_Utility.sendChatToPlayer(aPlayer, StatCollector.translateToLocal("GT5U.machines.workareaset") + " " + (radiusConfig * 2 + 1) + "x" + (radiusConfig * 2 + 1));//TODO Add translation support
+ oreBlockPositions.clear();
+ fillOreList(getBaseMetaTileEntity());
}
}
+ @Override
+ public void onFirstTick(IGregTechTileEntity aBaseMetaTileEntity) {
+ fillOreList(aBaseMetaTileEntity);
+ }
@Override
public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) {
@@ -165,50 +172,34 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine {
}
return;
}
- if (drillY == 0) {
+ if (drillY == 0 || oreBlockPositions.isEmpty()) {
moveOneDown(aBaseMetaTileEntity);
- return;
- }
- if (drillZ > radiusConfig) {
- moveOneDown(aBaseMetaTileEntity);
- return;
- }
- while (drillZ <= radiusConfig) {
- while (drillX <= radiusConfig) {
- Block block = aBaseMetaTileEntity.getBlockOffset(drillX, drillY, drillZ);
- int blockMeta = aBaseMetaTileEntity.getMetaIDOffset(drillX, drillY, drillZ);
- if (block instanceof GT_Block_Ores_Abstract) {
- TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntityOffset(drillX, drillY, drillZ);
- if (tTileEntity instanceof GT_TileEntity_Ores && ((GT_TileEntity_Ores) tTileEntity).mNatural) {
- mineBlock(aBaseMetaTileEntity, drillX, drillY, drillZ);
- if (debugBlockMiner) {
- GT_Log.out.println("MINER: Mining GT ore block at " + drillX + " " + drillY + " " + drillZ);
- }
- return;
- } else {
- if (debugBlockMiner) {
- GT_Log.out.println("MINER: Not natural ore, will not mine");
- }
- }
- } else {
- ItemData association = GT_OreDictUnificator.getAssociation(new ItemStack(block, 1, blockMeta));
- if (association != null && association.mPrefix.toString().startsWith("ore")) {
- mineBlock(aBaseMetaTileEntity, drillX, drillY, drillZ);
- if (debugBlockMiner) {
- GT_Log.out.println("MINER: Mining oredict ore block at " + drillX + " " + drillY + " " + drillZ);
- }
- return;
- }
- }
- drillX++;
+ } else {
+ ChunkPosition oreBlockPos = oreBlockPositions.remove(0);
+ mineBlock(aBaseMetaTileEntity, oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ);
+ if (debugBlockMiner) {
+ GT_Log.out.println("MINER: Mining GT ore block at " + oreBlockPos.chunkPosX + " " + drillY + " " + oreBlockPos.chunkPosZ);
}
- drillX = -radiusConfig;
- drillZ++;
}
}
}
}
-
+ private void fillOreList(IGregTechTileEntity aBaseMetaTileEntity) {
+ if (drillY == 0)
+ return;
+ for (int z = -radiusConfig; z <= radiusConfig; ++z) {
+ for (int x = -radiusConfig; x <= radiusConfig; ++x) {
+ Block block = aBaseMetaTileEntity.getBlockOffset(x, drillY, z);
+ int blockMeta = aBaseMetaTileEntity.getMetaIDOffset(x, drillY, z);
+ if (block instanceof GT_Block_Ores_Abstract) {
+ TileEntity tTileEntity = getBaseMetaTileEntity().getTileEntityOffset(x, drillY, z);
+ if (tTileEntity instanceof GT_TileEntity_Ores && ((GT_TileEntity_Ores) tTileEntity).mNatural)
+ oreBlockPositions.add(new ChunkPosition(x, drillY, z));
+ } else if (GT_Utility.isOre(new ItemStack(block, 1, blockMeta)))
+ oreBlockPositions.add(new ChunkPosition(x, drillY, z));
+ }
+ }
+ }
@Override
public long maxEUStore() {
return mTier == 1 ? 4096 : V[mTier] * 64;
@@ -253,13 +244,16 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine {
}
aBaseMetaTileEntity.getWorld().setBlock(xCoord, yCoord + drillY - 1, zCoord, MINING_PIPE_TIP_BLOCK);
drillY--;
- drillZ = -RADIUS[mTier];
- drillX = -RADIUS[mTier];
+ fillOreList(aBaseMetaTileEntity);
return true;
}
public void mineBlock(IGregTechTileEntity aBaseMetaTileEntity, int x, int y, int z) {
- if (!GT_Utility.eraseBlockByFakePlayer(getFakePlayer(aBaseMetaTileEntity), aBaseMetaTileEntity.getXCoord() + x, aBaseMetaTileEntity.getYCoord() + y, aBaseMetaTileEntity.getZCoord() + z, true));
+ if (!GT_Utility.eraseBlockByFakePlayer(getFakePlayer(aBaseMetaTileEntity), aBaseMetaTileEntity.getXCoord() + x, aBaseMetaTileEntity.getYCoord() + y, aBaseMetaTileEntity.getZCoord() + z, true)) {
+ if (debugBlockMiner)
+ GT_Log.out.println("MINER: FakePlayer cannot mine block at " + (aBaseMetaTileEntity.getXCoord() + x) + ", " + (aBaseMetaTileEntity.getYCoord() + y) + ", " + (aBaseMetaTileEntity.getZCoord() + z));
+ return;
+ }
ArrayList<ItemStack> drops = getBlockDrops(aBaseMetaTileEntity.getBlockOffset(x, y, z), aBaseMetaTileEntity.getXCoord() + x, aBaseMetaTileEntity.getYCoord() + y, aBaseMetaTileEntity.getZCoord() + z);
if (drops.size() > 0)
mOutputItems[0] = drops.get(0);
@@ -284,9 +278,7 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine {
public void saveNBTData(NBTTagCompound aNBT) {
super.saveNBTData(aNBT);
aNBT.setBoolean("isPickingPipe", isPickingPipes);
- aNBT.setInteger("drillX", drillX);
aNBT.setInteger("drillY", drillY);
- aNBT.setInteger("drillZ", drillZ);
aNBT.setInteger("radiusConfig", radiusConfig);
}
@@ -294,9 +286,7 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine {
public void loadNBTData(NBTTagCompound aNBT) {
super.loadNBTData(aNBT);
isPickingPipes = aNBT.getBoolean("isPickingPipe");
- drillX = aNBT.getInteger("drillX");
drillY = aNBT.getInteger("drillY");
- drillZ = aNBT.getInteger("drillZ");
if (aNBT.hasKey("radiusConfig"))
radiusConfig = aNBT.getInteger("radiusConfig");
}