@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);
  }
  @Override
  public int getHarvestLevel(ItemStack stack, String toolClass) {
    ToolMaterial toolMaterial =
        ToolMaterial.values()[stack.stackTagCompound.getInteger("material")];

    if (toolClass.equals("pickaxe") || toolClass.equals("shovel")) {
      return toolMaterial.getHarvestLevel();
    } else {
      return -1;
    }
  }
Example #3
0
  public static void patchRoCSteelTools() {

    Object[] items =
        new Object[] {
          ItemRegistry.STEELPICK.getItemInstance(),
          ItemRegistry.STEELAXE.getItemInstance(),
          ItemRegistry.STEELSHOVEL.getItemInstance()
        };

    for (int c = 0; c < items.length; c++) {
      Reflector itemreflector = new Reflector(items[c], ItemTool.class);
      ToolMaterial toolmat = ToolMaterial.valueOf("STEEL");
      itemreflector
          .set("field_77862_b", toolmat)
          .set("field_77865_bY", toolmat.getDamageVsEntity() + 2F)
          .set("field_77864_a", toolmat.getEfficiencyOnProperMaterial());
      ((ItemTool) items[c]).setMaxDamage(toolmat.getMaxUses());
    }
    // throw new RuntimeException();
  }
Example #4
0
 public static ToolMaterial patchToolMaterial(
     String toolmatname,
     int harvestLevel,
     int maxUses,
     float efficiency,
     float damageVsEntity,
     int enchantability) {
   ToolMaterial toolmat = ToolMaterial.valueOf(toolmatname);
   return patchToolMaterial(
       toolmat, harvestLevel, maxUses, efficiency, damageVsEntity, enchantability);
 }
Example #5
0
  public static ToolMaterial patchToolMaterial(
      ToolMaterial toolmat,
      int harvestLevel,
      int maxUses,
      float efficiency,
      float damageVsEntity,
      int enchantability) {
    FMLLog.info("[si.core] [patcher] Patching ToolMaterial " + toolmat.name());

    new Reflector(toolmat)
        .set("field_78001_f", harvestLevel)
        .set("field_78002_g", maxUses)
        .set("field_78010_h", efficiency)
        .set("field_78011_i", damageVsEntity)
        .set("field_78008_j", enchantability);

    return toolmat;
  }
Example #6
0
 private static void setPaxelHarvest(Item item, ToolMaterial material) {
   item.setHarvestLevel("pickaxe", material.getHarvestLevel());
   item.setHarvestLevel("axe", material.getHarvestLevel());
   item.setHarvestLevel("shovel", material.getHarvestLevel());
 }
Example #7
0
  public static void patchTools() {

    FMLControlledNamespacedRegistry<Item> gamereg = GameData.getItemRegistry();

    @SuppressWarnings("unchecked")
    Set<String> allItems = GameData.getItemRegistry().getKeys();

    for (String itemname : allItems) {

      Item item = gamereg.getObject(itemname);
      if (item instanceof ItemTool || item instanceof ItemHoe || item instanceof ItemSword) {

        if (item.getClass().getCanonicalName().contains("Reika.RotaryCraft")) {
          continue;
        }

        ToolMaterial toolmat = null;
        String toolmatname = null;
        if (item instanceof ItemTool) toolmatname = ((ItemTool) item).getToolMaterialName();
        else if (item instanceof ItemHoe) toolmatname = ((ItemHoe) item).getToolMaterialName();
        else if (item instanceof ItemSword) toolmatname = ((ItemSword) item).getToolMaterialName();

        if (toolmatname == null) {
        } else {
          try {
            toolmat = ToolMaterial.valueOf(toolmatname);
          } catch (IllegalArgumentException e) {
            toolmat = null;
          }
        }

        if (toolmat == null) {
        } else {
          // Update the tool material
          if (item instanceof ItemTool) {
            if (item.getClass().getCanonicalName().contains("fi.dy.masa.enderutilities")) {
              Reflector endertoolreflector = new Reflector(item, ItemEnderTool.class);
              endertoolreflector
                  .set("material", toolmat)
                  .set("field_77865_bY", toolmat.getDamageVsEntity() + 2F)
                  .set("field_77864_a", toolmat.getEfficiencyOnProperMaterial());

            } else {
              Reflector itemreflector = new Reflector(item, ItemTool.class);
              Float damagemodifier = 0F;
              if (item instanceof ItemAxe) damagemodifier = 3F;
              if (item instanceof ItemPickaxe) damagemodifier = 2F;
              if (item instanceof ItemSpade) damagemodifier = 1F;

              itemreflector
                  .set("field_77862_b", toolmat)
                  .set("field_77865_bY", toolmat.getDamageVsEntity() + damagemodifier)
                  .set("field_77864_a", toolmat.getEfficiencyOnProperMaterial());
            }
          }
          if (item instanceof ItemHoe) {
            new Reflector(item, ItemHoe.class).set("field_77843_a", toolmat);
          }
          if (item instanceof ItemSword) {
            new Reflector(item, ItemSword.class)
                .set("field_150933_b", toolmat)
                .set("field_150934_a", toolmat.getDamageVsEntity() + 4F);
          }

          // Update the max damage
          if (item.getMaxDamage() > 0) item.setMaxDamage(toolmat.getMaxUses());

          if (item instanceof ItemTool)
            FMLLog.info(
                "[si.core] [tool patcher] is a "
                    + ((ItemTool) item).getToolMaterialName()
                    + " tool");
          if (item instanceof ItemHoe)
            FMLLog.info(
                "[si.core] [tool patcher] is a " + ((ItemHoe) item).getToolMaterialName() + " hoe");
          if (item instanceof ItemSword)
            FMLLog.info(
                "[si.core] [tool patcher] is a "
                    + ((ToolMaterial) new Reflector(item, ItemSword.class).get("field_150933_b"))
                        .name()
                    + " weapon (basically a sword)");
        }
      }
    }
  }
 @Override
 public float getDigSpeed(ItemStack itemStack, Block block, int meta) {
   ToolMaterial toolMaterial =
       ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")];
   if (toolMaterial == ToolMaterial.WOOD) {
     // System.out.println("Wood " + Item.pickaxeWood.getStrVsBlock(par1ItemStack, par2Block));
     return Math.max(
         (Items.wooden_pickaxe.getDigSpeed(itemStack, block, meta)
                 / 2
                 * ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")]
                     .getEfficiencyOnProperMaterial())
             / 10,
         (Items.wooden_shovel.getDigSpeed(itemStack, block, meta)
                 / 2
                 * ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")]
                     .getEfficiencyOnProperMaterial())
             / 10);
   } else if (toolMaterial == ToolMaterial.STONE) {
     // System.out.println("Stone " + Item.pickaxeStone.getStrVsBlock(par1ItemStack, par2Block));
     return Math.max(
         (Items.stone_pickaxe.getDigSpeed(itemStack, block, meta)
                 / 2
                 * ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")]
                     .getEfficiencyOnProperMaterial())
             / 10,
         (Items.stone_shovel.getDigSpeed(itemStack, block, meta)
                 / 2
                 * ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")]
                     .getEfficiencyOnProperMaterial())
             / 10);
   } else if (toolMaterial == ToolMaterial.EMERALD) {
     // System.out.println("Diamond " + Item.pickaxeDiamond.getStrVsBlock(par1ItemStack,
     // par2Block));
     return Math.max(
         (Items.diamond_pickaxe.getDigSpeed(itemStack, block, meta)
                 / 2
                 * ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")]
                     .getEfficiencyOnProperMaterial())
             / 10,
         (Items.diamond_shovel.getDigSpeed(itemStack, block, meta)
                 / 2
                 * ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")]
                     .getEfficiencyOnProperMaterial())
             / 10);
   } else if (toolMaterial == ToolMaterial.IRON) {
     // System.out.println("Iron " + Item.pickaxeIron.getStrVsBlock(par1ItemStack, par2Block));
     return Math.max(
         (Items.iron_pickaxe.getDigSpeed(itemStack, block, meta)
                 / 2
                 * ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")]
                     .getEfficiencyOnProperMaterial())
             / 10,
         (Items.iron_shovel.getDigSpeed(itemStack, block, meta)
                 / 2
                 * ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")]
                     .getEfficiencyOnProperMaterial())
             / 10);
   } else if (toolMaterial == ToolMaterial.GOLD) {
     // System.out.println("Gold " + Item.pickaxeGold.getStrVsBlock(par1ItemStack, par2Block));
     return Math.max(
         (Items.golden_pickaxe.getDigSpeed(itemStack, block, meta)
                 / 2
                 * ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")]
                     .getEfficiencyOnProperMaterial())
             / 10,
         (Items.golden_shovel.getDigSpeed(itemStack, block, meta)
                 / 2
                 * ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")]
                     .getEfficiencyOnProperMaterial())
             / 10);
   }
   return (ToolMaterial.values()[itemStack.stackTagCompound.getInteger("material")]
           .getEfficiencyOnProperMaterial())
       / 10;
 }
  /**
   * Adds a tool material to TConstruct
   *
   * @param name Name of the material
   * @param stack The stack used to create the material
   * @param ID The unique ID of the material
   * @param mat The base tool material used to generate values
   * @param tooltipColor The colour in the item tooltip
   * @param hexColor The actual colour of the Item
   * @param handleMod The handle modifier of the material
   * @param reinforced The reinforced trait of the material
   * @param stonebound The stonebound modifier of the material, negative is jagged
   * @param maxDamage The base speed of the bow
   * @param bowMaxSpeed The max speed of the bow
   * @param arrowWeight The weight of the arrow
   * @param arrowBreakChance The chance that the arrow will survive on impact
   * @param inGame The in game name of the material
   * @param casting Whether or not this needs casting (true) or part building (false)
   */
  public static void createToolSet(
      String name,
      ItemStack stack,
      int ID,
      ToolMaterial mat,
      EnumChatFormatting tooltipColor,
      int hexColor,
      float handleMod,
      int reinforced,
      float stonebound,
      int maxDamage,
      float bowMaxSpeed,
      float arrowWeight,
      float arrowBreakChance,
      String inGame,
      boolean casting,
      boolean instant) {
    pb.registerMaterialSet(
        name,
        new ItemStack(TinkerTools.toolShard, 1, ID),
        new ItemStack(TinkerTools.toolRod, 1, ID),
        32);
    TConstructClientRegistry.addMaterialRenderMapping(ID, "tinker", name, true);
    if (Loader.isModLoaded("IguanaTweaksTConstruct"))
      //									ID, MaterialName, 	HarvestLevel,	BaseDurability, MiningSpeed, 	Attack,
      //	handleModifier, ReinforcedLevel, 	stonebound
      TConstructRegistry.addToolMaterial(
          ID,
          name,
          mat.getHarvestLevel() + 2,
          mat.getMaxUses(),
          instant ? Integer.MAX_VALUE : (int) mat.getEfficiencyOnProperMaterial() * 100,
          (int) mat.getDamageVsEntity(),
          handleMod,
          reinforced,
          stonebound,
          tooltipColor.toString(),
          hexColor);
    else
      TConstructRegistry.addToolMaterial(
          ID,
          name,
          mat.getHarvestLevel(),
          mat.getMaxUses(),
          instant ? Integer.MAX_VALUE : (int) mat.getEfficiencyOnProperMaterial() * 100,
          (int) mat.getDamageVsEntity(),
          handleMod,
          reinforced,
          stonebound,
          tooltipColor.toString(),
          hexColor);
    //								MatID, DrawSpeed, maxSpeed
    TConstructRegistry.addBowMaterial(ID, maxDamage, bowMaxSpeed);
    //								MatID, Weight, BreakChance
    TConstructRegistry.addArrowMaterial(ID, arrowWeight, arrowBreakChance);
    // TinkerTools.registerPatternMaterial(name, 2, name);
    TConstructRegistry.addDefaultToolPartMaterial(ID);
    pb.registerFullMaterial(
        stack,
        2,
        name,
        new ItemStack(TinkerTools.toolShard, 1, ID),
        new ItemStack(TinkerTools.toolRod, 1, ID),
        ID);
    LanguageRegistry.instance()
        .addStringLocalization("material." + name.toLowerCase(), "en_US", inGame);
    // LogHelper.info("Looking for %s to localise to %s", "material."+name, inGame);
    registerWithStations(stack, name, ID);
    if (!casting) addPartBuilding(ID);
    // else		 addCasting(null, ID);

  }