@Override
  public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
    NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
    World world = player.worldObj;
    int bID = player.worldObj.getBlockId(x, y, z);
    int meta = world.getBlockMetadata(x, y, z);
    Block block = Block.blocksList[bID];
    if (block == null || bID < 1) return false;
    int hlvl = MinecraftForge.getBlockHarvestLevel(block, meta, getHarvestType());
    int shlvl = MinecraftForge.getBlockHarvestLevel(block, meta, getSecondHarvestType());

    if (hlvl <= tags.getInteger("HarvestLevel") && shlvl <= tags.getInteger("HarvestLevel2")) {
      boolean cancelHarvest = false;
      for (ActiveToolMod mod : TConstructRegistry.activeModifiers) {
        if (mod.beforeBlockBreak(this, stack, x, y, z, player)) cancelHarvest = true;
      }

      return cancelHarvest;
    } else {
      if (!player.capabilities.isCreativeMode) onBlockDestroyed(stack, world, bID, x, y, z, player);
      world.setBlockToAir(x, y, z);
      if (!world.isRemote) world.playAuxSFX(2001, x, y, z, bID + (meta << 12));
      return true;
    }
  }
Beispiel #2
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);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  @Override
  public boolean onBlockStartBreak(ItemStack stack, int x, int y, int z, EntityPlayer player) {
    if (!stack.hasTagCompound()) return false;

    World world = player.worldObj;
    final int blockID = world.getBlockId(x, y, z);
    final int meta = world.getBlockMetadata(x, y, z);
    if (!stack.hasTagCompound()) return false;
    NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
    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"))) {
            boolean cancelHarvest = false;
            for (ActiveToolMod mod : TConstructRegistry.activeModifiers) {
              if (mod.beforeBlockBreak(this, stack, xPos, yPos, zPos, player)) cancelHarvest = true;
            }

            if (!cancelHarvest) {
              int localblockID = world.getBlockId(xPos, yPos, zPos);
              Block block = Block.blocksList[localblockID];
              if (block
                  != null) // && (block.blockMaterial == Material.leaves || block.isLeaves(world,
              // xPos, yPos, zPos)))
              {
                for (int iter = 0; iter < materials.length; iter++) {
                  if (materials[iter] == block.blockMaterial) {
                    int localMeta = world.getBlockMetadata(xPos, yPos, zPos);
                    world.setBlockToAir(xPos, yPos, zPos);
                    if (!player.capabilities.isCreativeMode) {
                      block.onBlockDestroyedByPlayer(world, x, y, z, meta);
                      block.harvestBlock(world, player, xPos, yPos, zPos, localMeta);
                      block.onBlockHarvested(world, x, y, z, localMeta, player);
                      onBlockDestroyed(stack, world, localblockID, xPos, yPos, zPos, player);
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
    if (!world.isRemote) world.playAuxSFX(2001, x, y, z, blockID + (meta << 12));
    return super.onBlockStartBreak(stack, x, y, z, player);
  }
Beispiel #4
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);
                          }
                      }
                  }*/
                }
              }
            }
          }
        }
      }
    }
  }