/** Removes a block and triggers the appropriate events */
  private boolean removeBlock(int par1, int par2, int par3) {
    Block block = theWorld.getBlock(par1, par2, par3);
    int l = theWorld.getBlockMetadata(par1, par2, par3);
    block.onBlockHarvested(theWorld, par1, par2, par3, l, thisPlayerMP);
    boolean flag = block != null && block.removedByPlayer(theWorld, thisPlayerMP, par1, par2, par3);

    if (flag) {
      block.onBlockDestroyedByPlayer(theWorld, par1, par2, par3, l);
    }

    return flag;
  }
예제 #2
0
  @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);
  }
예제 #3
0
  public static void removeBlockWithDrops(
      SpellContext context,
      EntityPlayer player,
      World world,
      ItemStack tool,
      BlockPos pos,
      boolean particles) {
    if (!world.isBlockLoaded(pos)
        || context.positionBroken != null && pos.equals(context.positionBroken.getBlockPos()))
      return;

    int harvestLevel = ConfigHandler.cadHarvestLevel;
    IBlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (!world.isRemote
        && block != null
        && !block.isAir(world, pos)
        && !(block instanceof BlockLiquid)
        && block.getPlayerRelativeBlockHardness(player, world, pos) > 0) {
      int neededHarvestLevel = block.getHarvestLevel(state);
      if (neededHarvestLevel > harvestLevel) return;

      BreakEvent event = new BreakEvent(world, pos, state, player);
      MinecraftForge.EVENT_BUS.post(event);
      if (!event.isCanceled()) {
        if (!player.capabilities.isCreativeMode) {
          block.onBlockHarvested(world, pos, state, player);

          if (block.removedByPlayer(world, pos, player, true)) {
            block.onBlockDestroyedByPlayer(world, pos, state);
            block.harvestBlock(world, player, pos, state, world.getTileEntity(pos));
          }
        } else world.setBlockToAir(pos);
      }

      if (particles) world.playAuxSFX(2001, pos, Block.getStateId(state));
    }
  }
예제 #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);
                          }
                      }
                  }*/
                }
              }
            }
          }
        }
      }
    }
  }