Example #1
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)");
        }
      }
    }
  }
Example #2
0
 public static void initBlocks() {
   blockMultiblock = new BlockMultiblock();
   GameRegistry.registerBlock(blockMultiblock, "multiblock");
   GameRegistry.registerTileEntity(TileMultiblock.class, "RPMulti");
   blockAppliance = new BlockAppliance();
   GameRegistry.registerBlock(blockAppliance, ItemExtended.class, "appliance");
   GameRegistry.registerTileEntity(TileAlloyFurnace.class, "RPAFurnace");
   blockAppliance.addTileEntityMapping(0, TileAlloyFurnace.class);
   blockAppliance.setBlockName(0, "rpafurnace");
   GameRegistry.addRecipe(
       new ItemStack(blockAppliance, 1, 0),
       new Object[] {"BBB", "B B", "BBB", Character.valueOf('B'), Blocks.brick_block});
   GameRegistry.registerTileEntity(TileAdvBench.class, "RPAdvBench");
   blockAppliance.addTileEntityMapping(3, TileAdvBench.class);
   blockAppliance.setBlockName(3, "rpabench");
   CraftLib.addOreRecipe(
       new ItemStack(blockAppliance, 1, 3),
       new Object[] {
         "SSS",
         "WTW",
         "WCW",
         Character.valueOf('S'),
         Blocks.stone,
         Character.valueOf('W'),
         "plankWood",
         Character.valueOf('T'),
         Blocks.crafting_table,
         Character.valueOf('C'),
         Blocks.chest
       });
   itemHandsawIron = new ItemHandsaw(0);
   itemHandsawIron.setUnlocalizedName("handsawIron");
   itemHandsawIron.setTextureName("rpworld:itemHandsawIron");
   itemHandsawIron.setMaxDamage(320);
   itemHandsawDiamond = new ItemHandsaw(2);
   itemHandsawDiamond.setUnlocalizedName("handsawDiamond");
   itemHandsawDiamond.setTextureName("rpworld:itemHandsawDiamond");
   itemHandsawDiamond.setMaxDamage(1280);
   GameRegistry.addRecipe(
       new ItemStack(itemHandsawIron, 1),
       new Object[] {
         "WWW",
         " II",
         " II",
         Character.valueOf('I'),
         Items.iron_ingot,
         Character.valueOf('W'),
         Items.stick
       });
   GameRegistry.addRecipe(
       new ItemStack(itemHandsawDiamond, 1),
       new Object[] {
         "WWW",
         " II",
         " DD",
         Character.valueOf('I'),
         Items.iron_ingot,
         Character.valueOf('D'),
         Items.diamond,
         Character.valueOf('W'),
         Items.stick
       });
   GameRegistry.addShapelessRecipe(
       CoreLib.copyStack(itemWaferSilicon, 16),
       new Object[] {itemBouleSilicon, new ItemStack(itemHandsawDiamond, 1, -1)});
   itemScrewdriver = new ItemScrewdriver();
   GameRegistry.addRecipe(
       new ItemStack(itemScrewdriver, 1),
       new Object[] {
         "I ", " W", Character.valueOf('I'), Items.iron_ingot, Character.valueOf('W'), Items.stick
       });
   GameRegistry.registerItem(itemScrewdriver, "screwdriver");
   GameRegistry.addRecipe(
       new ItemStack(itemDrawplateDiamond, 1),
       new Object[] {
         " I ",
         "IDI",
         " I ",
         Character.valueOf('I'),
         new ItemStack(blockMicro, 1, 5649),
         Character.valueOf('D'),
         new ItemStack(blockMicro, 1, 4115)
       });
   GameRegistry.addShapelessRecipe(
       itemFineIron, new Object[] {Items.iron_ingot, new ItemStack(itemDrawplateDiamond, 1, -1)});
   CraftLib.addShapelessOreRecipe(
       itemFineCopper, new Object[] {"ingotCopper", new ItemStack(itemDrawplateDiamond, 1, -1)});
   GameRegistry.addRecipe(
       CoreLib.copyStack(itemNuggetIron, 9),
       new Object[] {"I", Character.valueOf('I'), Items.iron_ingot});
   CraftLib.addOreRecipe(
       CoreLib.copyStack(itemNuggetCopper, 9),
       new Object[] {"I", Character.valueOf('I'), "ingotCopper"});
   CraftLib.addOreRecipe(
       CoreLib.copyStack(itemNuggetTin, 9),
       new Object[] {"I", Character.valueOf('I'), "ingotTin"});
   CraftLib.addOreRecipe(
       CoreLib.copyStack(itemNuggetSilver, 9),
       new Object[] {"I", Character.valueOf('I'), "ingotSilver"});
   GameRegistry.addRecipe(
       new ItemStack(Items.iron_ingot, 1, 0),
       new Object[] {"III", "III", "III", Character.valueOf('I'), itemNuggetIron});
   GameRegistry.addRecipe(
       itemIngotSilver,
       new Object[] {"III", "III", "III", Character.valueOf('I'), itemNuggetSilver});
   GameRegistry.addRecipe(
       itemIngotTin, new Object[] {"III", "III", "III", Character.valueOf('I'), itemNuggetTin});
   GameRegistry.addRecipe(
       itemIngotCopper,
       new Object[] {"III", "III", "III", Character.valueOf('I'), itemNuggetCopper});
   GameRegistry.addRecipe(
       itemCanvas,
       new Object[] {
         "SSS",
         "SWS",
         "SSS",
         Character.valueOf('S'),
         Items.string,
         Character.valueOf('W'),
         Items.stick
       });
   GameRegistry.addRecipe(
       new ItemStack(Items.diamond, 2),
       new Object[] {"D", Character.valueOf('D'), new ItemStack(blockMicro, 1, 4115)});
   GameRegistry.addRecipe(
       new ItemStack(Items.diamond, 1),
       new Object[] {"D", Character.valueOf('D'), new ItemStack(blockMicro, 1, 19)});
   GameRegistry.addRecipe(
       new ItemStack(Items.iron_ingot, 2),
       new Object[] {"I", Character.valueOf('I'), new ItemStack(blockMicro, 1, 4113)});
   GameRegistry.addRecipe(
       new ItemStack(Items.iron_ingot, 1),
       new Object[] {"I", Character.valueOf('I'), new ItemStack(blockMicro, 1, 17)});
 }