diff options
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Miner.java | 249 | ||||
-rw-r--r-- | src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java | 1 |
2 files changed, 162 insertions, 88 deletions
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 6d4b160a86..bafb80057c 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 @@ -33,7 +33,8 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine { private static final Block MINING_PIPE_TIP_BLOCK = GT_Utility.getBlockFromStack(GT_ModHandler.getIC2Item("miningPipeTip", 0)); int drillY = 0; - boolean isPickingPipes; + boolean mRetractDone; + boolean waitMiningPipe; static final int[] RADIUS = {8, 8, 16, 24, 32}; //Miner radius per tier static final int[] SPEED = {160, 160, 80, 40, 20}; //Miner cycle time per tier @@ -47,6 +48,7 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine { new String[]{ "Digging ore instead of you", "Use Screwdriver to regulate work area", + "Use Soft Mallet to disable and retract the pipe", ENERGY[aTier] + " EU/t, " + SPEED[aTier] / 20 + " sec per block, no stuttering", "Maximum work area " + (RADIUS[aTier] * 2 + 1) + "x" + (RADIUS[aTier] * 2 + 1), "Fortune bonus of " + aTier}, @@ -91,7 +93,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); @@ -122,80 +124,147 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine { @Override public void onPostTick(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { super.onPostTick(aBaseMetaTileEntity, aTick); - if (aBaseMetaTileEntity.isServerSide()) { - if (aBaseMetaTileEntity.isAllowedToWork() && aBaseMetaTileEntity.isUniversalEnergyStored(ENERGY[mTier] * (SPEED[mTier] - mProgresstime)) && hasFreeSpace()) { - miningPipe: - if (waitMiningPipe) { - mMaxProgresstime = 0; - for (int i = 0; i < mInputSlotCount; i++) { - ItemStack s = getInputAt(i); - if (s != null && s.getItem() == MINING_PIPE.getItem() && s.stackSize > 0) { - waitMiningPipe = false; - break miningPipe; - } - } - if (debugBlockMiner) { - GT_Log.out.println("MINER: Pipe found in input"); - } - return; + + if (!aBaseMetaTileEntity.isServerSide()) { + return; + } + // If the machine was disabled - try to retract pipe + if (!aBaseMetaTileEntity.isAllowedToWork()){ + mMaxProgresstime = 0; + onPostTickRetract(aBaseMetaTileEntity, aTick); + return; + } + // If the machine was re-enabled - we should reset the retracting process + mRetractDone = false; + + boolean hasFreeSpace = hasFreeSpace(); + boolean hasEnergy = aBaseMetaTileEntity.isUniversalEnergyStored(ENERGY[mTier] * (SPEED[mTier] - mProgresstime)); + + if (!hasEnergy || !hasFreeSpace){ + mMaxProgresstime = 0; + if (debugBlockMiner) { + if (!aBaseMetaTileEntity.isAllowedToWork()) { + GT_Log.out.println("MINER: Disabled"); } - aBaseMetaTileEntity.decreaseStoredEnergyUnits(ENERGY[mTier], true); - mMaxProgresstime = SPEED[mTier]; - } else { + if (!hasEnergy) { + GT_Log.out.println("MINER: Not enough energy yet, want " + (ENERGY[mTier] * SPEED[mTier]) + " have " + aBaseMetaTileEntity.getUniversalEnergyStored()); + } + if (!hasFreeSpace) { + GT_Log.out.println("MINER: No free space"); + } + } + return; + } + + ItemStack minigPipeStack = getMiningPipe(0); + if (waitMiningPipe){ + if (minigPipeStack == null || minigPipeStack.stackSize == 0){ mMaxProgresstime = 0; - if (debugBlockMiner) { - if (!aBaseMetaTileEntity.isAllowedToWork()) { - GT_Log.out.println("MINER: Disabled"); - } - if (!aBaseMetaTileEntity.isUniversalEnergyStored(ENERGY[mTier] * (SPEED[mTier] - mProgresstime))) { - GT_Log.out.println("MINER: Not enough energy yet, want " + (ENERGY[mTier] * SPEED[mTier]) + " have " + aBaseMetaTileEntity.getUniversalEnergyStored()); - } - if (!hasFreeSpace()) { - GT_Log.out.println("MINER: No free space"); - } + if (debugBlockMiner){ + GT_Log.out.println("MINER: Pipe found in input"); } return; } - if (mProgresstime == SPEED[mTier] - 1) { - if (isPickingPipes) { - if (drillY == 0) { - aBaseMetaTileEntity.disableWorking(); - isPickingPipes = false; - if (debugBlockMiner) { - GT_Log.out.println("MINER: Completed picking pipes"); - } - } else if (aBaseMetaTileEntity.getBlockOffset(0, drillY, 0) == MINING_PIPE_TIP_BLOCK || aBaseMetaTileEntity.getBlockOffset(0, drillY, 0) == MINING_PIPE_BLOCK) { - mOutputItems[0] = MINING_PIPE.copy(); - mOutputItems[0].stackSize = 1; - aBaseMetaTileEntity.getWorld().setBlockToAir(aBaseMetaTileEntity.getXCoord(), aBaseMetaTileEntity.getYCoord() + drillY, aBaseMetaTileEntity.getZCoord()); - drillY++; - } - return; + } + + aBaseMetaTileEntity.decreaseStoredEnergyUnits(ENERGY[mTier], true); + mMaxProgresstime = SPEED[mTier]; + + if (mProgresstime == SPEED[mTier] - 1) { + if (drillY == 0 || oreBlockPositions.isEmpty()) { + moveOneDown(aBaseMetaTileEntity); + } else { + ChunkPosition oreBlockPos; + int x = 0, y = 0, z = 0; + Block oreBlock; + int oreBlockMetadata = 0; + do { + oreBlockPos = oreBlockPositions.remove(0); + oreBlock = aBaseMetaTileEntity.getBlockOffset(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); + x = aBaseMetaTileEntity.getXCoord() + oreBlockPos.chunkPosX; + y = aBaseMetaTileEntity.getYCoord() + oreBlockPos.chunkPosY; + z = aBaseMetaTileEntity.getZCoord() + oreBlockPos.chunkPosZ; + oreBlockMetadata = getBaseMetaTileEntity().getWorld().getBlockMetadata(x, y, z); + } // someone else might have removed the block + while (!GT_Utility.isOre(oreBlock, oreBlockMetadata) && !oreBlockPositions.isEmpty()); + + if (GT_Utility.isOre(oreBlock, oreBlockMetadata)) { + mineBlock(aBaseMetaTileEntity, oreBlock, x, y, z); } - if (drillY == 0 || oreBlockPositions.isEmpty()) { - moveOneDown(aBaseMetaTileEntity); - } else { - ChunkPosition oreBlockPos; - int x = 0, y = 0, z = 0; - Block oreBlock; - int oreBlockMetadata = 0; - do { - oreBlockPos = oreBlockPositions.remove(0); - oreBlock = aBaseMetaTileEntity.getBlockOffset(oreBlockPos.chunkPosX, oreBlockPos.chunkPosY, oreBlockPos.chunkPosZ); - x = aBaseMetaTileEntity.getXCoord() + oreBlockPos.chunkPosX; - y = aBaseMetaTileEntity.getYCoord() + oreBlockPos.chunkPosY; - z = aBaseMetaTileEntity.getZCoord() + oreBlockPos.chunkPosZ; - oreBlockMetadata = getBaseMetaTileEntity().getWorld().getBlockMetadata(x, y, z); - } // someone else might have removed the block - while (!GT_Utility.isOre(oreBlock, oreBlockMetadata) && !oreBlockPositions.isEmpty()); - - if (GT_Utility.isOre(oreBlock, oreBlockMetadata)) { - mineBlock(aBaseMetaTileEntity, oreBlock, x, y, z); - } + } + } + } + + /** + * If the machine are disabled - tried to retract pipe + */ + private void onPostTickRetract(IGregTechTileEntity aBaseMetaTileEntity, long aTick) { + if (mRetractDone) { + return; + } + // If retracting process just touch the miner + if (drillY == 0) { + mRetractDone = true; + return; + } + // Once per N ticks (depends on tier) + if ((aTick % (SPEED[mTier] / 5)) != 0) { + return; + } + // Check the pipe fits the first output slot + int outSlotIndex = getOutputSlot(); + ItemStack outSlotItem = this.mInventory[outSlotIndex]; + if (outSlotItem != null && !GT_Utility.areStacksEqual(outSlotItem, MINING_PIPE)) { + return; + } + // Inspect target block - it should be a pipe tip, else something went wrong. + Block inspectedBlock = aBaseMetaTileEntity.getBlockOffset(0, drillY, 0); + boolean isPipeTip = inspectedBlock == MINING_PIPE_TIP_BLOCK; + if (!isPipeTip) { + return; + } + // Retract the pipe/tip + int xCoord = aBaseMetaTileEntity.getXCoord(); + int yCoord = aBaseMetaTileEntity.getYCoord(); + int zCoord = aBaseMetaTileEntity.getZCoord(); + int actualDrillY = yCoord + drillY; + // Move the pipe tip position + if (actualDrillY < yCoord - 1) { + getBaseMetaTileEntity().getWorld().setBlock(xCoord, actualDrillY + 1, zCoord, MINING_PIPE_TIP_BLOCK); + } + // Remove the old pipe tip + aBaseMetaTileEntity.getWorld().setBlockToAir(xCoord, actualDrillY, zCoord); + // Return the pipe into the machine + if (outSlotItem == null) { + final ItemStack copy = MINING_PIPE.copy(); + copy.stackSize = 1; + this.setInventorySlotContents(outSlotIndex, copy); + } else { + this.mInventory[outSlotIndex].stackSize++; + } + drillY++; + } + + /** + * Returns first available pipe from input slots + */ + private ItemStack getMiningPipe(int modify) { + for (int i = 0; i < mInputSlotCount; i++) { + ItemStack stack = getInputAt(i); + if (stack != null && stack.getItem() == MINING_PIPE.getItem() && stack.stackSize > 0) { + stack.stackSize += modify; + if (stack.stackSize == 0) { + mInventory[getInputSlot() + i] = null; } + return stack; } } + return null; } + + /** + * Findsw the ores in current drill Y level + */ private void fillOreList(IGregTechTileEntity aBaseMetaTileEntity) { if (drillY == 0) return; @@ -220,38 +289,43 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine { public boolean moveOneDown(IGregTechTileEntity aBaseMetaTileEntity) { int xCoord = aBaseMetaTileEntity.getXCoord(); int zCoord = aBaseMetaTileEntity.getZCoord(); - short yCoord = aBaseMetaTileEntity.getYCoord(); - if (yCoord + drillY - 1 < 0 - || GT_Utility.getBlockHardnessAt(aBaseMetaTileEntity.getWorld(), xCoord, yCoord + drillY - 1, zCoord) < 0 - || !GT_Utility.setBlockByFakePlayer(getFakePlayer(aBaseMetaTileEntity), xCoord, yCoord + drillY - 1, zCoord, MINING_PIPE_TIP_BLOCK, 0, true)) { - isPickingPipes = true; + int yCoord = aBaseMetaTileEntity.getYCoord(); + boolean isHitsTheVoid = yCoord + drillY - 1 < 0; + boolean isHitsBedrock = GT_Utility.getBlockHardnessAt(aBaseMetaTileEntity.getWorld(), xCoord, yCoord + drillY - 1, zCoord) < 0; + boolean isFakePlayerAllowed = !GT_Utility.setBlockByFakePlayer(getFakePlayer(aBaseMetaTileEntity), xCoord, yCoord + drillY - 1, zCoord, MINING_PIPE_TIP_BLOCK, 0, true); + + if (isHitsTheVoid || isHitsBedrock || !isFakePlayerAllowed) { + aBaseMetaTileEntity.disableWorking(); if (debugBlockMiner) { - GT_Log.out.println("MINER: Hit bottom? Hit block with -1 hardness? Unable to set mining pipe tip?"); + if (isHitsTheVoid) { + GT_Log.out.println("MINER: Hit bottom"); + } + if (isHitsBedrock) { + GT_Log.out.println("MINER: Hit block with -1 hardness"); + } + if (!isFakePlayerAllowed) { + GT_Log.out.println("MINER: Unable to set mining pipe tip"); + } } return false; } + // Replace the tip onto pipe if (aBaseMetaTileEntity.getBlockOffset(0, drillY, 0) == MINING_PIPE_TIP_BLOCK) { aBaseMetaTileEntity.getWorld().setBlock(xCoord, yCoord + drillY, zCoord, MINING_PIPE_BLOCK); } - miningPipes: - { - for (int i = 0; i < mInputSlotCount; i++) { - ItemStack s = getInputAt(i); - if (s != null && s.getItem() == MINING_PIPE.getItem() && s.stackSize > 0) { - s.stackSize--; - if (s.stackSize == 0) { - mInventory[getInputSlot() + i] = null; - } - break miningPipes; - } - } + // Get and decrease pipe from the machine + ItemStack pipeInSlot = getMiningPipe(-1); + if (pipeInSlot == null) { + // If there was nothing - wainting for the pipes (just for prevent unnecessary checks) waitMiningPipe = true; return false; } + // If there is something - mine it (todo don't matter what? maybe some checks like in mining method?) Block block = aBaseMetaTileEntity.getBlockOffset(0, drillY - 1, 0); if (block != Blocks.air) { mineBlock(aBaseMetaTileEntity, block, xCoord, yCoord + drillY - 1, zCoord); } + // Raise the pipe tip aBaseMetaTileEntity.getWorld().setBlock(xCoord, yCoord + drillY - 1, zCoord, MINING_PIPE_TIP_BLOCK); drillY--; fillOreList(aBaseMetaTileEntity); @@ -297,7 +371,6 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine { @Override public void saveNBTData(NBTTagCompound aNBT) { super.saveNBTData(aNBT); - aNBT.setBoolean("isPickingPipe", isPickingPipes); aNBT.setInteger("drillY", drillY); aNBT.setInteger("radiusConfig", radiusConfig); } @@ -305,7 +378,7 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine { @Override public void loadNBTData(NBTTagCompound aNBT) { super.loadNBTData(aNBT); - isPickingPipes = aNBT.getBoolean("isPickingPipe"); + // todo actually we need to find pipes from the 0Y in the up direction until the miner, and don't need to save it drillY = aNBT.getInteger("drillY"); if (aNBT.hasKey("radiusConfig")) radiusConfig = aNBT.getInteger("radiusConfig"); @@ -322,12 +395,12 @@ public class GT_MetaTileEntity_Miner extends GT_MetaTileEntity_BasicMachine { } return mFakePlayer; } - + @Override public String[] getInfoData() { return new String[]{ EnumChatFormatting.BLUE+StatCollector.translateToLocal("GT5U.machines.miner")+EnumChatFormatting.RESET, - StatCollector.translateToLocal("GT5U.machines.workarea")+": " + EnumChatFormatting.GREEN + (radiusConfig * 2 + 1)+ + StatCollector.translateToLocal("GT5U.machines.workarea")+": " + EnumChatFormatting.GREEN + (radiusConfig * 2 + 1)+ EnumChatFormatting.RESET+" " + StatCollector.translateToLocal("GT5U.machines.blocks") }; } diff --git a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java index 431241eb84..2027516dcc 100644 --- a/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java +++ b/src/main/java/gregtech/common/tileentities/machines/basic/GT_MetaTileEntity_Pump.java @@ -65,6 +65,7 @@ public class GT_MetaTileEntity_Pump extends GT_MetaTileEntity_Hatch { getEuUsagePerTier(aTier) + " EU/operation, " + GT_Utility.safeInt(160 / 20 / (long)Math.pow(2, aTier) ) + " sec per bucket, no stuttering", "Maximum pumping area: " + (getMaxDistanceForTier( aTier) * 2 + 1) + "x" + (getMaxDistanceForTier( aTier) * 2 + 1), "Use Screwdriver to regulate pumping area", + "Use Soft Mallet to disable and retract the pipe", "Disable itself upon hitting rocks", "Disable the bottom pump to retract the pipe!"}); radiusConfig = getMaxDistanceForTier(mTier); |