@SubscribeEvent
    public void chopChop(TickEvent.WorldTickEvent event) {
      if (event.side.isClient()) {
        finish();
        return;
      }

      // setup
      int left = blocksPerTick;

      // continue running
      BlockPos pos;
      while (left > 0) {
        // completely done or can't do our job anymore?!
        if (blocks.isEmpty() || ToolHelper.isBroken(tool)) {
          finish();
          return;
        }

        pos = blocks.remove();
        if (!visited.add(pos)) {
          continue;
        }

        // can we harvest the block and is effective?
        if (!isLog(world, pos) || !ToolHelper.isToolEffective2(tool, world.getBlockState(pos))) {
          continue;
        }

        // save its neighbours
        for (EnumFacing facing :
            new EnumFacing[] {
              EnumFacing.NORTH, EnumFacing.EAST, EnumFacing.SOUTH, EnumFacing.WEST
            }) {
          BlockPos pos2 = pos.offset(facing);
          if (!visited.contains(pos2)) {
            blocks.add(pos2);
          }
        }

        // also add the layer above.. stupid acacia trees
        for (int x = 0; x < 3; x++) {
          for (int z = 0; z < 3; z++) {
            BlockPos pos2 = pos.add(-1 + x, 1, -1 + z);
            if (!visited.contains(pos2)) {
              blocks.add(pos2);
            }
          }
        }

        // break it, wooo!
        ToolHelper.breakExtraBlock(tool, world, player, pos, pos);
        left--;
      }
    }
  @SubscribeEvent
  public void onRenderGUI(RenderGameOverlayEvent.Pre event) {
    // we're only interested in the inventory
    if (event.type != RenderGameOverlayEvent.ElementType.HOTBAR) {
      return;
    }

    EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    ItemStack stack = player.getCurrentEquippedItem();
    if (stack == null) {
      return;
    }

    // do we hold a tool that supports secondary item usage?
    if (stack.getItem() instanceof ToolCore && ((ToolCore) stack.getItem()).canUseSecondaryItem()) {
      int slot = ToolHelper.getSecondaryItemSlot(player);

      if (slot != player.inventory.currentItem) {
        // render the special border around the secondary item that would be used
        int x = event.resolution.getScaledWidth() / 2 - 90 + slot * 20 + 2;
        int y = event.resolution.getScaledHeight() - 16 - 3;

        // render a cool underlay thing
        GlStateManager.color(1, 1, 1, 0.5f);
        Minecraft.getMinecraft().getTextureManager().bindTexture(widgetsTexPath);
        Gui.drawScaledCustomSizeModalRect(x, y, 1, 23, 22, 22, 16, 16, 256, 256);
      }
    }
  }
Exemple #3
0
 @Override
 public void afterHit(
     ItemStack tool,
     EntityLivingBase player,
     EntityLivingBase target,
     float damage,
     boolean wasCritical,
     boolean wasHit) {
   int time = (int) player.getEntityWorld().getWorldTime();
   if (random.nextFloat() <= 0.1 && isNight(time)) {
     ToolHelper.healTool(tool, random.nextInt(15) + 1, null);
   }
 }
Exemple #4
0
 @Override
 public void afterBlockBreak(
     ItemStack tool,
     World world,
     IBlockState state,
     BlockPos pos,
     EntityLivingBase player,
     boolean wasEffective) {
   int time = (int) world.getWorldTime();
   if (random.nextFloat() <= 0.1 && isNight(time)) {
     ToolHelper.healTool(tool, random.nextInt(15) + 1, null);
   }
 }
  // grass paths
  @Override
  public EnumActionResult onItemUse(
      ItemStack stack,
      EntityPlayer player,
      World world,
      BlockPos pos,
      EnumHand hand,
      EnumFacing facing,
      float hitX,
      float hitY,
      float hitZ) {
    if (ToolHelper.isBroken(stack)) {
      return EnumActionResult.FAIL;
    }

    EnumActionResult result =
        Items.DIAMOND_SHOVEL.onItemUse(stack, player, world, pos, hand, facing, hitX, hitY, hitZ);

    // only do the AOE path if the selected block is grass or grass path
    Block block = world.getBlockState(pos).getBlock();
    if (block == Blocks.GRASS || block == Blocks.GRASS_PATH) {
      for (BlockPos aoePos : getAOEBlocks(stack, world, player, pos)) {
        // stop if the tool breaks during the process
        if (ToolHelper.isBroken(stack)) {
          break;
        }

        EnumActionResult aoeResult =
            Items.DIAMOND_SHOVEL.onItemUse(
                stack, player, world, aoePos, hand, facing, hitX, hitY, hitZ);
        // if we pass on an earlier block, check if another block succeeds here instead
        if (result != EnumActionResult.SUCCESS) {
          result = aoeResult;
        }
      }
    }

    return result;
  }
 @Override
 public ImmutableList<BlockPos> getAOEBlocks(
     ItemStack stack, World world, EntityPlayer player, BlockPos origin) {
   return ToolHelper.calcAOEBlocks(stack, world, player, origin, 3, 3, 3);
 }