/** 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;
  }
 private void emulateBlockHarvest(
     ItemStack stack,
     World world,
     int x,
     int y,
     int z,
     Block block,
     int meta,
     EntityPlayer player) {
   world.playAuxSFXAtEntity(player, 2001, x, y, z, Block.getIdFromBlock(block) | meta << 12);
   stack.func_150999_a(world, block, x, y, z, player);
   if (stack.stackSize == 0) player.destroyCurrentEquippedItem();
   if (block.removedByPlayer(world, player, x, y, z, false)) {
     block.dropBlockAsItem(world, x, y, z, meta, EnchantmentHelper.getFortuneModifier(player));
   }
 }
Beispiel #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));
    }
  }
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);
                          }
                      }
                  }*/
                }
              }
            }
          }
        }
      }
    }
  }
  @Override
  public int onBlockPlaced(
      World world,
      int int1,
      int int2,
      int int3,
      int int4,
      float float1,
      float float2,
      float float3,
      int int5) {
    if (this == ModBlocks.blockTrytementium) {
      world.createExplosion(null, int1, int2, int3, 10.0F, false);
      for (int i = -9; i <= 9; i++) {
        for (int j = -8; j <= 8; j++) {
          for (int k = -8; k <= 8; k++) {
            Block block = world.getBlock(int1 + i, int2 + j, int3 + k);
            Random rand = new Random();
            int isInfested = rand.nextInt(5);
            int isRemoved = rand.nextInt(2);
            if (block == Blocks.grass
                || block == Blocks.dirt
                || block == ModBlocks.fluxInfestedSoil) {
              if (ConfigurationHandler.trytementiumBoom) {
                block.removedByPlayer(world, null, int1 + i, int2 + j, int3 + k, true);
              }
              if (isInfested <= 1) {
                world.setBlock(int1 + i, int2 + j, int3 + k, ModBlocks.fluxInfestedSoil);
              }
            } else if (block.getBlockHardness(world, int1 + i, int2 + j, int3 + k) != -1
                && ConfigurationHandler.trytementiumBoom) {
              if (isRemoved <= 1 && ConfigurationHandler.trytementiumBoom) {
                block.removedByPlayer(world, null, int1 + i, int2 + j, int3 + k, true);
              }
            }
          }
        }
      }
      for (int i = -8; i <= 8; i++) {
        for (int j = -9; j <= 9; j++) {
          for (int k = -8; k <= 8; k++) {
            Block block = world.getBlock(int1 + i, int2 + j, int3 + k);
            Random rand = new Random();
            int isInfested = rand.nextInt(5);
            int isRemoved = rand.nextInt(2);
            if (block == Blocks.grass
                || block == Blocks.dirt
                || block == ModBlocks.fluxInfestedSoil) {
              if (ConfigurationHandler.trytementiumBoom) {
                block.removedByPlayer(world, null, int1 + i, int2 + j, int3 + k, true);
              }
              if (isInfested <= 1) {
                world.setBlock(int1 + i, int2 + j, int3 + k, ModBlocks.fluxInfestedSoil);
              }
            } else if (block.getBlockHardness(world, int1 + i, int2 + j, int3 + k) != -1
                && ConfigurationHandler.trytementiumBoom) {
              if (isRemoved <= 1 && ConfigurationHandler.trytementiumBoom) {
                block.removedByPlayer(world, null, int1 + i, int2 + j, int3 + k, true);
              }
            }
          }
        }
      }
      for (int i = -8; i <= 8; i++) {
        for (int j = -8; j <= 8; j++) {
          for (int k = -9; k <= 9; k++) {
            Block block = world.getBlock(int1 + i, int2 + j, int3 + k);
            Random rand = new Random();
            int isInfested = rand.nextInt(5);
            int isRemoved = rand.nextInt(2);
            if (block == Blocks.grass
                || block == Blocks.dirt
                || block == ModBlocks.fluxInfestedSoil) {
              block.removedByPlayer(world, null, int1 + i, int2 + j, int3 + k, true);
              if (ConfigurationHandler.trytementiumBoom) {
                block.removedByPlayer(world, null, int1 + i, int2 + j, int3 + k, true);
              }
              if (isInfested <= 1) {
                world.setBlock(int1 + i, int2 + j, int3 + k, ModBlocks.fluxInfestedSoil);
              }

            } else if (block.getBlockHardness(world, int1 + i, int2 + j, int3 + k) != -1
                && ConfigurationHandler.trytementiumBoom) {
              if (isRemoved <= 1 && ConfigurationHandler.trytementiumBoom) {
                block.removedByPlayer(world, null, int1 + i, int2 + j, int3 + k, true);
              }
            }
          }
        }
      }
      world.scheduleBlockUpdate(int1, int2, int3, this, 1);
    }
    return int5;
  }