コード例 #1
0
    @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--;
      }
    }
コード例 #2
0
  @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);
      }
    }
  }
コード例 #3
0
ファイル: TraitArcane.java プロジェクト: ConnorRowe/TAIGA
 @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);
   }
 }
コード例 #4
0
ファイル: TraitArcane.java プロジェクト: ConnorRowe/TAIGA
 @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);
   }
 }
コード例 #5
0
  // 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;
  }
コード例 #6
0
 @Override
 public ImmutableList<BlockPos> getAOEBlocks(
     ItemStack stack, World world, EntityPlayer player, BlockPos origin) {
   return ToolHelper.calcAOEBlocks(stack, world, player, origin, 3, 3, 3);
 }