Ejemplo 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);
                  }
                }
              }
            }
          }
        }
      }
    }
  }
Ejemplo n.º 2
0
  @Override
  public boolean canHarvestBlock(Block block, ItemStack itemStack) {
    ToolMaterial toolMaterial =
        ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")];

    try {
      if (block.getBlockHardness(null, 0, 0, 0) == -1) {
        return false;
      }
    } catch (NullPointerException e) {
      return false;
    }

    if (block.getMaterial().isToolNotRequired()) {
      return true;
    }

    if (toolMaterial == ToolMaterial.WOOD) {
      return Items.wooden_pickaxe.func_150897_b /*canHarvestBlock*/(block)
          || Items.wooden_shovel.func_150897_b(block);
    } else if (toolMaterial == ToolMaterial.STONE) {
      return Items.stone_pickaxe.func_150897_b(block) || Items.stone_shovel.func_150897_b(block);
    } else if (toolMaterial == ToolMaterial.EMERALD) {
      return Items.diamond_pickaxe.func_150897_b(block)
          || Items.diamond_shovel.func_150897_b(block);
    } else if (toolMaterial == ToolMaterial.IRON) {
      return Items.iron_pickaxe.func_150897_b(block) || Items.iron_shovel.func_150897_b(block);
    } else if (toolMaterial == ToolMaterial.GOLD) {
      return Items.golden_pickaxe.func_150897_b(block) || Items.golden_shovel.func_150897_b(block);
    }

    return toolMaterial.getHarvestLevel() >= block.getHarvestLevel(0);
  }
Ejemplo n.º 3
0
  @Override
  public float getDigSpeed(ItemStack stack, Block block, int meta) {
    if (!stack.hasTagCompound()) return 1.0f;

    NBTTagCompound tags = stack.getTagCompound().getCompoundTag("InfiTool");
    if (tags.getBoolean("Broken")) return 0.1f;

    Material[] materials = getEffectiveMaterials();
    for (int i = 0; i < materials.length; i++) {
      if (materials[i] == block.getMaterial()) {
        float mineSpeed = tags.getInteger("MiningSpeed");
        int heads = 1;
        if (tags.hasKey("MiningSpeed2")) {
          mineSpeed += tags.getInteger("MiningSpeed2");
          heads++;
        }

        if (tags.hasKey("MiningSpeedHandle")) {
          mineSpeed += tags.getInteger("MiningSpeedHandle");
          heads++;
        }

        if (tags.hasKey("MiningSpeedExtra")) {
          mineSpeed += tags.getInteger("MiningSpeedExtra");
          heads++;
        }
        float trueSpeed = mineSpeed / (heads * 300f);
        int hlvl = block.getHarvestLevel(meta);
        int durability = tags.getInteger("Damage");

        float stonebound = tags.getFloat("Shoddy");
        float bonusLog = (float) Math.log(durability / 72f + 1) * 2 * stonebound;
        trueSpeed += bonusLog;

        if (hlvl <= tags.getInteger("HarvestLevel")) return trueSpeed;
        return 0.1f;
      }
    }
    return super.getDigSpeed(stack, block, meta);
  }
Ejemplo n.º 4
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));
    }
  }
Ejemplo n.º 5
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);
                          }
                      }
                  }*/
                }
              }
            }
          }
        }
      }
    }
  }
  /**
   * *****************************************************************************************************************
   * ********************************************** Tile Methods
   * ******************************************************
   * *****************************************************************************************************************
   */
  @Override
  @SuppressWarnings("unchecked")
  public void updateEntity() {
    super.updateEntity();
    if (!worldObj.isRemote
        && !isPowered()
        && getCore() != null
        && pickSlot.getStackInSlot(0) != null
        && worldObj.rand.nextInt(20) == 0) {
      SixWayRotation rotation = new SixWayRotation();
      ForgeDirection dir =
          rotation.convertMetaToDirection(worldObj.getBlockMetadata(xCoord, yCoord, zCoord));
      Location blockBreakLocation = new Location(this);
      blockBreakLocation.travel(dir);
      if (!worldObj.isAirBlock(blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z)) {
        Block toBreak =
            worldObj.getBlock(blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z);
        if (toBreak.getMaterial() == Material.water || toBreak.getMaterial() == Material.lava)
          return;
        int harvestLevel =
            pickSlot
                .getStackInSlot(0)
                .getItem()
                .getHarvestLevel(pickSlot.getStackInSlot(0), "pickaxe");
        if (toBreak.getHarvestLevel(
                worldObj.getBlockMetadata(
                    blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z))
            <= harvestLevel) {

          int fortune = 0;
          boolean silkTouch =
              toBreak.canSilkHarvest(
                  worldObj,
                  null,
                  blockBreakLocation.x,
                  blockBreakLocation.y,
                  blockBreakLocation.x,
                  worldObj.getBlockMetadata(
                      blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z));
          boolean hasSilkTouch = false;
          NBTTagList enchantList = pickSlot.getStackInSlot(0).getEnchantmentTagList();
          if (enchantList != null) {
            for (int i = 0; i < enchantList.tagCount(); i++) {
              NBTTagCompound tag = enchantList.getCompoundTagAt(i);
              if (tag.hasKey("id") && tag.getInteger("id") == 35) fortune = tag.getInteger("lvl");
              else if (tag.hasKey("id") && tag.getInteger("id") == 33) hasSilkTouch = true;
            }
          }
          ArrayList<ItemStack> itemStacks = new ArrayList<>();
          if (silkTouch && hasSilkTouch) {
            itemStacks.add(
                new ItemStack(
                    toBreak,
                    1,
                    worldObj.getBlockMetadata(
                        blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z)));
          } else {
            itemStacks =
                toBreak.getDrops(
                    worldObj,
                    blockBreakLocation.x,
                    blockBreakLocation.y,
                    blockBreakLocation.z,
                    worldObj.getBlockMetadata(
                        blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z),
                    fortune);
          }
          for (ItemStack itemStack : itemStacks) {
            if (itemStack != null && itemStack.stackSize > 0) {
              float rx = worldObj.rand.nextFloat() * 0.8F + 0.1F;
              float ry = worldObj.rand.nextFloat() * 0.8F + 0.1F;
              float rz = worldObj.rand.nextFloat() * 0.8F + 0.1F;

              EntityItem entityItem =
                  new EntityItem(
                      worldObj,
                      blockBreakLocation.x + rx,
                      blockBreakLocation.y + ry,
                      blockBreakLocation.z + rz,
                      new ItemStack(
                          itemStack.getItem(), itemStack.stackSize, itemStack.getItemDamage()));

              if (itemStack.hasTagCompound())
                entityItem
                    .getEntityItem()
                    .setTagCompound((NBTTagCompound) itemStack.getTagCompound().copy());

              float factor = 0.05F;
              entityItem.motionX = worldObj.rand.nextGaussian() * factor;
              entityItem.motionY = worldObj.rand.nextGaussian() * factor + 0.2F;
              entityItem.motionZ = worldObj.rand.nextGaussian() * factor;
              worldObj.spawnEntityInWorld(entityItem);

              itemStack.stackSize = 0;
            }
          }
          worldObj.playAuxSFX(
              2001,
              blockBreakLocation.x,
              blockBreakLocation.y,
              blockBreakLocation.z,
              Block.getIdFromBlock(toBreak)
                  + (worldObj.getBlockMetadata(
                          blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z)
                      << 12));
          worldObj.setBlockToAir(blockBreakLocation.x, blockBreakLocation.y, blockBreakLocation.z);
          pickSlot.getStackInSlot(0).setItemDamage(pickSlot.getStackInSlot(0).getItemDamage() + 1);
          if (pickSlot.getStackInSlot(0).getItemDamage()
              > pickSlot.getStackInSlot(0).getMaxDamage()) pickSlot.setStackInSlot(null, 0);
        }
      }
    }
  }