Exemplo n.º 1
0
  void destroyWood(
      World world, int x, int y, int z, ItemStack stack, NBTTagCompound tags, EntityPlayer player) {
    for (int xPos = x - 1; xPos <= x + 1; xPos++) {
      for (int yPos = y - 1; yPos <= y + 1; yPos++) {
        for (int zPos = z - 1; zPos <= z + 1; zPos++) {
          if (!(tags.getBoolean("Broken"))) {
            Block block = world.getBlock(xPos, yPos, zPos);
            int meta = world.getBlockMetadata(xPos, yPos, zPos);
            int hlvl = block.getHarvestLevel(meta);

            if (block != null && block.getMaterial() == Material.wood) {
              if (hlvl <= tags.getInteger("HarvestLevel")) {
                boolean cancelHarvest = false;
                for (ActiveToolMod mod : TConstructRegistry.activeModifiers) {
                  if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player))
                    cancelHarvest = true;
                }

                if (!cancelHarvest) {
                  WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
                  if (!player.capabilities.isCreativeMode) {
                    // TODO harvestBlock
                    block.harvestBlock(world, player, xPos, yPos, zPos, meta);
                    onBlockDestroyed(stack, world, block, xPos, yPos, zPos, player);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
Exemplo n.º 2
0
  void breakTree(
      World world,
      int x,
      int y,
      int z,
      ItemStack stack,
      NBTTagCompound tags,
      Block bID,
      int meta,
      EntityPlayer player) {
    Block block;
    for (int xPos = x - 1; xPos <= x + 1; xPos++) {
      for (int yPos = y; yPos <= y + 1; yPos++) {
        for (int zPos = z - 1; zPos <= z + 1; zPos++) {
          if (!(tags.getBoolean("Broken"))) {
            Block localblock = world.getBlock(xPos, yPos, zPos);
            if (bID == localblock) {
              block = localblock;
              meta = world.getBlockMetadata(xPos, yPos, zPos);
              int hlvl = block.getHarvestLevel(meta);

              if (hlvl <= tags.getInteger("HarvestLevel")) {
                boolean cancelHarvest = false;
                for (ActiveToolMod mod : TConstructRegistry.activeModifiers) {
                  if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player))
                    cancelHarvest = true;
                }

                if (cancelHarvest) {
                  breakTree(world, xPos, yPos, zPos, stack, tags, bID, meta, player);
                } else {
                  if (localblock == bID
                      && world.getBlockMetadata(xPos, yPos, zPos) % 4 == meta % 4) {
                    /* world.setBlock(xPos, yPos, zPos, 0, 0, 3);
                    if (!player.capabilities.isCreativeMode)
                    {
                        Block.blocksList[bID].harvestBlock(world, player, xPos, yPos, zPos, meta);
                        onBlockDestroyed(stack, world, bID, xPos, yPos, zPos, player);
                    }*/
                    if (!player.capabilities.isCreativeMode) {
                      if (block.removedByPlayer(world, player, xPos, yPos, zPos)) {
                        block.onBlockDestroyedByPlayer(world, xPos, yPos, zPos, meta);
                      }
                      block.harvestBlock(world, player, xPos, yPos, zPos, meta);
                      block.onBlockHarvested(world, xPos, yPos, zPos, meta, player);
                      onBlockDestroyed(stack, world, localblock, xPos, yPos, zPos, player);
                    } else {
                      WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
                    }
                    breakTree(world, xPos, yPos, zPos, stack, tags, bID, meta, player);
                  }
                  /*else
                  {
                      Block leaves = Block.blocksList[localID];
                      if (leaves != null && leaves.isLeaves(world, xPos, yPos, zPos))
                      {
                          WorldHelper.setBlockToAir(world, xPos, yPos, zPos);
                          if (!player.capabilities.isCreativeMode)
                          {
                              Block.blocksList[bID].harvestBlock(world, player, xPos, yPos, zPos, meta);
                              onBlockDestroyed(stack, world, bID, xPos, yPos, zPos, player);
                          }
                      }
                  }*/
                }
              }
            }
          }
        }
      }
    }
  }