@Override
  public boolean onBlockDestroyed(
      ItemStack stack, World world, int blockID, int x, int y, int z, EntityPlayer player) {
    boolean b = false;
    Block block = Block.blocksList[blockID];
    int plant = (int) ModuleManager.computeModularProperty(stack, PLANT_RADIUS);
    int leaf = (int) ModuleManager.computeModularProperty(stack, LEAF_RADIUS);
    int totalEnergyDrain = 0;

    // Leaves
    if (block != null && block.isLeaves(world, x, y, z)) {
      for (int i = -leaf; i < leaf; i++) {
        for (int j = -leaf; j < leaf; j++) {
          for (int k = -leaf; k < leaf; k++) {
            int id = world.getBlockId(x + i, y + j, z + k);
            int meta = world.getBlockId(x + i, y + j, z + k);
            Block tempBlock = Block.blocksList[id];
            if (tempBlock != null && tempBlock.isLeaves(world, x + i, y + j, z + k)) {
              if (block.canHarvestBlock(player, meta)) {
                block.harvestBlock(world, player, x + i, y + j, z + k, meta);
                totalEnergyDrain +=
                    ModuleManager.computeModularProperty(stack, LEAF_BLOWER_ENERGY_CONSUMPTION);
              }
              world.setBlock(x + i, y + j, z + k, 0);
              b = true;
            }
          }
        }
      }
    }

    for (int i = -plant; i < plant; i++) {
      for (int j = -plant; j < plant; j++) {
        for (int k = -plant; k < plant; k++) {
          int id = world.getBlockId(x + i, y + j, z + k);
          int meta = world.getBlockId(x + i, y + j, z + k);
          Block tempBlock = Block.blocksList[id];
          if (tempBlock != null && tempBlock instanceof BlockFlower) {
            if (block.canHarvestBlock(player, meta)) {
              block.harvestBlock(world, player, x + i, y + j, z + k, meta);
              totalEnergyDrain +=
                  ModuleManager.computeModularProperty(stack, LEAF_BLOWER_ENERGY_CONSUMPTION);
            }
            world.setBlock(x + i, y + j, z + k, 0);
            b = true;
          }
        }
      }
    }
    ElectricItemUtils.drainPlayerEnergy(player, totalEnergyDrain);
    return b;
  }
Example #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);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
Example #3
0
 /**
  * Called when the player destroys a block with an item that can harvest it. (i, j, k) are the
  * coordinates of the block and l is the block's subtype/damage.
  */
 public void harvestBlock(
     World p_149636_1_,
     EntityPlayer p_149636_2_,
     int p_149636_3_,
     int p_149636_4_,
     int p_149636_5_,
     int p_149636_6_) {
   {
     super.harvestBlock(
         p_149636_1_, p_149636_2_, p_149636_3_, p_149636_4_, p_149636_5_, p_149636_6_);
   }
 }
Example #4
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);
  }
  /** Attempts to harvest a block at the given coordinate */
  @Override
  public boolean tryHarvestBlock(int x, int y, int z) {
    BlockEvent.BreakEvent event =
        ForgeHooks.onBlockBreakEvent(theWorld, getGameType(), thisPlayerMP, x, y, z);
    if (event.isCanceled()) {
      return false;
    } else {
      ItemStack stack = thisPlayerMP.getCurrentEquippedItem();
      if (stack != null && stack.getItem().onBlockStartBreak(stack, x, y, z, thisPlayerMP)) {
        return false;
      }
      Block block = theWorld.getBlock(x, y, z);
      int l = theWorld.getBlockMetadata(x, y, z);
      theWorld.playAuxSFXAtEntity(
          thisPlayerMP,
          2001,
          x,
          y,
          z,
          Block.getIdFromBlock(block) + (theWorld.getBlockMetadata(x, y, z) << 12));
      boolean flag = false;

      ItemStack itemstack = thisPlayerMP.getCurrentEquippedItem();

      if (itemstack != null) {
        itemstack.func_150999_a(theWorld, block, x, y, z, thisPlayerMP);

        if (itemstack.stackSize == 0) {
          thisPlayerMP.destroyCurrentEquippedItem();
        }
      }

      if (removeBlock(x, y, z)) {
        block.harvestBlock(theWorld, thisPlayerMP, x, y, z, l);
        flag = true;
      }

      // Drop experience
      if (!isCreative() && flag && event != null) {
        block.dropXpOnBlockBreak(theWorld, x, y, z, event.getExpToDrop());
      }
      drone.addAir(null, -PneumaticValues.DRONE_USAGE_DIG);
      return true;
    }
  }
Example #6
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));
    }
  }
Example #7
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);
                          }
                      }
                  }*/
                }
              }
            }
          }
        }
      }
    }
  }
Example #8
0
 @Override
 public void harvestBlock(
     World par1World, EntityPlayer par2EntityPlayer, int par3, int par4, int par5, int par6) {
   super.harvestBlock(par1World, par2EntityPlayer, par3, par4, par5, par6);
   par1World.setBlockToAir(par3, par4, par5);
 }