예제 #1
0
 public Block getNextBlock() {
   Point2I currentPoint = spiral(currentColumn, pos.getX(), pos.getZ());
   miningWith = canMineBlock(currentPoint.getX(), currentYLevel, currentPoint.getY());
   while ((miningWith <= 0) && (currentYLevel >= 0)) {
     if (miningWith > 0) {
       return worldObj
           .getBlockState(new BlockPos(currentPoint.getX(), currentYLevel, currentPoint.getY()))
           .getBlock();
     } else {
       currentYLevel--;
       if (currentYLevel >= 0)
         miningWith = canMineBlock(currentPoint.getX(), currentYLevel, currentPoint.getY());
     }
   }
   if (miningWith > 0) {
     return worldObj
         .getBlockState(new BlockPos(currentPoint.getX(), currentYLevel, currentPoint.getY()))
         .getBlock();
   }
   if (currentYLevel < 0) {
     currentYLevel = pos.getY() - 1;
     currentColumn--;
     if (currentColumn < 0) {
       // ProgressiveAutomation.logger.info("Last Column done Update");
       scanBlocks();
       currentColumn = getRange();
     } else {
       return getNextBlock();
     }
   }
   return null;
 }
예제 #2
0
 public void scanBlocks() {
   totalMineBlocks = currentMineBlocks = 0;
   for (int i = 1; i <= getRange(); i++) {
     Point2I currentPoint = spiral(i, pos.getX(), pos.getZ());
     boolean bedrock = false;
     int newY = this.pos.getY() - 1;
     while (!bedrock) {
       int result = canMineBlock(currentPoint.getX(), newY, currentPoint.getY());
       if (result >= 1) {
         totalMineBlocks++;
       } else if (result == -1) {
         totalMineBlocks++;
         currentMineBlocks++;
       }
       newY--;
       if (newY < 0) bedrock = true;
     }
   }
   addPartialUpdate("MineBlocks", totalMineBlocks);
   addPartialUpdate("MinedBlocks", currentMineBlocks);
   notifyUpdate();
   // ProgressiveAutomation.logger.info("Update Finished: "+currentMineBlocks+"/"+totalMineBlocks);
 }
예제 #3
0
  public void mine() {
    if ((slots[1] == null) || (slots[2] == null) || (slots[3] == null)) return;
    if (currentBlock != null) {
      // continue to mine this block
      if (miningTime <= 0) {
        miningTime = 0;
        // clock is done, lets mine it
        Point2I currentPoint = spiral(currentColumn, pos.getX(), pos.getZ());
        BlockPos currentPosition =
            new BlockPos(currentPoint.getX(), currentYLevel, currentPoint.getY());
        // ProgressiveAutomation.logger.info("Point: "+miningWith+"
        // "+currentPoint.getX()+","+currentYLevel+","+currentPoint.getY());

        // don't harvest anything if the block is air or liquid
        if (miningWith != 4) {
          // get the inventory of anything under it
          if (worldObj.getTileEntity(currentPosition) instanceof IInventory) {
            IInventory inv = (IInventory) worldObj.getTileEntity(currentPosition);
            for (int i = 0; i < inv.getSizeInventory(); i++) {
              if (inv.getStackInSlot(i) != null) {
                addToInventory(inv.getStackInSlot(i));
                inv.setInventorySlotContents(i, null);
              }
            }
          }

          // silk touch the block if we have it
          int silkTouch = 0;
          if (miningWith != 1) {
            silkTouch =
                EnchantmentHelper.getEnchantmentLevel(Enchantments.SILK_TOUCH, slots[miningWith]);
          }

          if (silkTouch > 0) {
            int i = 0;
            Item item = Item.getItemFromBlock(currentBlock);
            if (item != null && item.getHasSubtypes())
              i = currentBlock.getMetaFromState(worldObj.getBlockState(currentPosition));

            ItemStack addItem = new ItemStack(currentBlock, 1, i);
            addToInventory(addItem);

          } else {
            // mine the block
            int fortuneLevel = 0;
            if (miningWith != 1) {
              fortuneLevel =
                  EnchantmentHelper.getEnchantmentLevel(Enchantments.FORTUNE, slots[miningWith]);
            }

            // then break the block
            List<ItemStack> items =
                currentBlock.getDrops(
                    worldObj,
                    currentPosition,
                    worldObj.getBlockState(currentPosition),
                    fortuneLevel);
            // get the drops
            for (ItemStack item : items) {
              addToInventory(item);
            }
          }

          if (miningWith != 1) {
            if (ToolHelper.damageTool(
                slots[miningWith],
                worldObj,
                currentPoint.getX(),
                currentYLevel,
                currentPoint.getY())) {
              destroyTool(miningWith);
            }
          }
        }

        // remove the block and entity if there is one
        worldObj.removeTileEntity(currentPosition);
        worldObj.setBlockState(currentPosition, Blocks.COBBLESTONE.getDefaultState());
        slots[1].stackSize--;
        if (slots[1].stackSize == 0) {
          slots[1] = null;
        }
        currentMineBlocks++;
        addPartialUpdate("MinedBlocks", currentMineBlocks);
        currentBlock = null;

      } else {
        miningTime--;
      }
    } else {
      if (!isDone()) {
        currentBlock = getNextBlock();
        if (currentBlock != null) {
          Point2I currentPoint = spiral(currentColumn, pos.getX(), pos.getZ());
          BlockPos currentPosition =
              new BlockPos(currentPoint.getX(), currentYLevel, currentPoint.getY());
          IBlockState currentBlockState = worldObj.getBlockState(currentPosition);

          if (miningWith == 4) {
            miningTime = 1;
          } else {
            miningTime =
                (int)
                    Math.ceil(
                        currentBlock.getBlockHardness(currentBlockState, worldObj, currentPosition)
                            * 1.5
                            * 20);

            if (miningWith != 1) {
              float miningSpeed = ToolHelper.getDigSpeed(slots[miningWith], currentBlockState);

              // check for efficiency on the tool
              if (miningSpeed > 1) {
                int eff =
                    EnchantmentHelper.getEnchantmentLevel(
                        Enchantments.EFFICIENCY, slots[miningWith]);
                if (eff > 0) {
                  for (int i = 0; i < eff; i++) {
                    miningSpeed = miningSpeed * 1.3f;
                  }
                }
              }

              miningTime = (int) Math.ceil(miningTime / miningSpeed);
            }
          }

          // ProgressiveAutomation.logger.info("Mining: "+currentBlock.getUnlocalizedName()+" in
          // "+miningTime+" ticks");

        }
      }
    }

    if (isDone()) {
      // ProgressiveAutomation.logger.info("Done Update");
      scanBlocks();
      currentColumn = getRange();
    }
  }