@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);
      }
    }
  }
Esempio n. 2
0
  private boolean moveToBlock(World world, int x, int y, int z, int x2, int y2, int z2) {
    int blockID2 = world.getBlockId(x2, y2, z2);
    int originMeta = world.getBlockMetadata(x, y, z);
    int destMeta = world.getBlockMetadata(x2, y2, z2);
    if (blockID2 == this.blockID) {
      if (destMeta > originMeta || y > y2) {
        if (originMeta < 7 && destMeta > 0) {
          world.setBlockMetadata(x, y, z, originMeta + 1);
          world.markBlockForUpdate(x, y, z);
          world.setBlockMetadata(x2, y2, z2, destMeta - 1);
          world.markBlockForUpdate(x2, y2, z2);
          return true;
        } else if (destMeta > 0) {
          world.setBlockWithNotify(x, y, z, 0);
          world.markBlockForUpdate(x, y, z);
          world.setBlockMetadata(x2, y2, z2, destMeta - 1);
          world.markBlockForUpdate(x2, y2, z2);
          return true;
        } else {
          return false;
        }
      } else {
        return false;
      }
    } else if (liquidCanDisplaceBlock(world, x2, y2, z2)) {
      if (blockID2 > 0) {
        if (this.blockMaterial == Material.lava) {
          this.triggerLavaMixEffects(world, x2, y2, z2);
        } else if (blockID2 == Block.waterMoving.blockID || blockID2 == Block.waterStill.blockID) {
          if (originMeta < 7) {
            world.setBlockMetadataWithNotify(x, y, z, originMeta + 1);
            world.markBlockForUpdate(x, y, z);
            return true;
          } else {
            world.setBlockWithNotify(x, y, z, 0);
            world.markBlockForUpdate(x, y, z);
            return true;
          }
        } else {
          Block.blocksList[blockID2].dropBlockAsItem(
              world, x2, y2, z2, world.getBlockMetadata(x2, y2, z2), 0);
        }
      }

      if (y2 < y) {
        world.setBlockWithNotify(x, y, z, 0);
        world.markBlockForUpdate(x, y, z);
        world.setBlockAndMetadataWithNotify(x2, y2, z2, blockID, originMeta);
        world.markBlockForUpdate(x2, y2, z2);
        return true;
      }
      if (originMeta < 7) {
        world.setBlockMetadataWithNotify(x, y, z, originMeta + 1);
        world.markBlockForUpdate(x, y, z);
        world.setBlockAndMetadataWithNotify(x2, y2, z2, blockID, 7);
        world.markBlockForUpdate(x2, y2, z2);
        return true;
      } else if (world.getBlockId(x - 1, y, z) != this.blockID
          && world.getBlockId(x + 1, y, z) != this.blockID
          && world.getBlockId(x, y + 1, z) != this.blockID
          && world.getBlockId(x, y, z - 1) != this.blockID
          && world.getBlockId(x, y, z + 1) != this.blockID) {
        world.setBlockWithNotify(x, y, z, 0);
        return true;
      } else {
        world.setBlockWithNotify(x, y, z, 0);
        world.markBlockForUpdate(x, y, z);
        world.setBlockAndMetadataWithNotify(x2, y2, z2, blockID, 7);
        world.markBlockForUpdate(x2, y2, z2);
        return true;
      }
    } else {
      return false;
    }
  }