Пример #1
0
 public boolean contentsMatch(int index, ItemStack is) {
   if (storage[index] != null
       && storage[index].getItem() == is.getItem()
       && storage[index].getItemDamage() == is.getItemDamage()
       && storage[index].stackSize < storage[index].getMaxStackSize()) {
     return true;
   } else {
     return false;
   }
 }
  @Override
  public void harvestBlock(World world, EntityPlayer entityplayer, int i, int j, int k, int l) {
    // we need to make sure the player has the correct tool out
    boolean isAxeorSaw = false;
    boolean isHammer = false;
    ItemStack equip = entityplayer.getCurrentEquippedItem();
    if (!world.isRemote) {
      if (equip != null) {
        for (int cnt = 0; cnt < Recipes.Axes.length && !isAxeorSaw; cnt++) {
          if (equip.getItem() == Recipes.Axes[cnt]) {
            isAxeorSaw = true;
            if (cnt < 4) isStone = true;
          }
        }
        //				for(int cnt = 0; cnt < Recipes.Saws.length && !isAxeorSaw; cnt++)
        //				{
        //					if(equip.getItem() == Recipes.Saws[cnt])
        //					{
        //						isAxeorSaw = true;
        //					}
        //				}
        for (int cnt = 0; cnt < Recipes.Hammers.length && !isAxeorSaw; cnt++) {
          if (equip.getItem() == Recipes.Hammers[cnt]) {
            isHammer = true;
          }
        }
      }
      if (isAxeorSaw) {
        damage = -1;
        ProcessTree(world, i, j, k, l, equip);

        if (damage + equip.getItemDamage() > equip.getMaxDamage()) {
          int ind = entityplayer.inventory.currentItem;
          entityplayer.inventory.setInventorySlotContents(ind, null);
          world.setBlockAndMetadataWithNotify(i, j, k, blockID, l, 3);
        } else {
          equip.damageItem(damage, entityplayer);
        }
      } else if (isHammer) {
        EntityItem item =
            new EntityItem(
                world,
                i + 0.5,
                j + 0.5,
                k + 0.5,
                new ItemStack(Item.stick, 1 + world.rand.nextInt(3)));
        world.spawnEntityInWorld(item);
      } else {
        world.setBlockAndMetadataWithNotify(i, j, k, blockID, l, 3);
      }
    }
  }
  private void scanLogs(
      World world,
      int i,
      int j,
      int k,
      int l,
      boolean[][][] checkArray,
      int x,
      int y,
      int z,
      ItemStack stack) {
    if (y >= 0) {
      checkArray[x][y][z] = true;
      int offsetX = 0;
      int offsetY = 0;
      int offsetZ = 0;

      for (offsetY = 0; offsetY <= 1; offsetY++) {
        for (offsetX = -2; offsetX <= 2; offsetX++) {
          for (offsetZ = -2; offsetZ <= 2; offsetZ++) {
            if (x + offsetX < 11
                && x + offsetX >= 0
                && z + offsetZ < 11
                && z + offsetZ >= 0
                && y + offsetY < 50
                && y + offsetY >= 0) {
              if (checkOut(world, i + offsetX, j + offsetY, k + offsetZ, l)
                  && !checkArray[x + offsetX][y + offsetY][z + offsetZ]) {
                scanLogs(
                    world,
                    i + offsetX,
                    j + offsetY,
                    k + offsetZ,
                    l,
                    checkArray,
                    x + offsetX,
                    y + offsetY,
                    z + offsetZ,
                    stack);
              }
            }
          }
        }
      }

      damage++;
      if (stack != null) {
        if (damage + stack.getItemDamage() <= stack.getMaxDamage()) {
          world.setBlock(i, j, k, 0);
          world.markBlockForUpdate(i, j, k);
          if ((isStone && world.rand.nextInt(10) != 0) || !isStone)
            dropBlockAsItem_do(
                world, i, j, k, new ItemStack(Item.itemsList[TFCItems.Logs.itemID], 1, l));
        }
      } else {
        world.setBlock(i, j, k, 0);
        world.markBlockForUpdate(i, j, k);
        dropBlockAsItem_do(
            world, i, j, k, new ItemStack(Item.itemsList[TFCItems.Logs.itemID], 1, l));
      }
    }
  }