예제 #1
0
 private void parseSimpleFieldAnnotation(
     SetMultimap<String, ASMData> annotations,
     String annotationClassName,
     Function<ModContainer, Object> retreiver)
     throws IllegalAccessException {
   String[] annName = annotationClassName.split("\\.");
   String annotationName = annName[annName.length - 1];
   for (ASMData targets : annotations.get(annotationClassName)) {
     String targetMod = (String) targets.getAnnotationInfo().get("value");
     Field f = null;
     Object injectedMod = null;
     ModContainer mc = this;
     boolean isStatic = false;
     Class<?> clz = modInstance.getClass();
     if (!Strings.isNullOrEmpty(targetMod)) {
       if (Loader.isModLoaded(targetMod)) {
         mc = Loader.instance().getIndexedModList().get(targetMod);
       } else {
         mc = null;
       }
     }
     if (mc != null) {
       try {
         clz = Class.forName(targets.getClassName(), true, Loader.instance().getModClassLoader());
         f = clz.getDeclaredField(targets.getObjectName());
         f.setAccessible(true);
         isStatic = Modifier.isStatic(f.getModifiers());
         injectedMod = retreiver.apply(mc);
       } catch (Exception e) {
         Throwables.propagateIfPossible(e);
         FMLLog.log(
             getModId(),
             Level.WARNING,
             e,
             "Attempting to load @%s in class %s for %s and failing",
             annotationName,
             targets.getClassName(),
             mc.getModId());
       }
     }
     if (f != null) {
       Object target = null;
       if (!isStatic) {
         target = modInstance;
         if (!modInstance.getClass().equals(clz)) {
           FMLLog.log(
               getModId(),
               Level.WARNING,
               "Unable to inject @%s in non-static field %s.%s for %s as it is NOT the primary mod instance",
               annotationName,
               targets.getClassName(),
               targets.getObjectName(),
               mc.getModId());
           continue;
         }
       }
       f.set(target, injectedMod);
     }
   }
 }
예제 #2
0
  @Handler
  public void preInit(FMLPreInitializationEvent event) {
    proxy.preInit();

    MinecraftForge.EVENT_BUS.register(new TinkerArmorEvents());
    FMLCommonHandler.instance().bus().register(new ArmorAbilities());

    TinkerArmor.dryingRack = new DryingRack().setBlockName("Armor.DryingRack");
    GameRegistry.registerBlock(TinkerArmor.dryingRack, "Armor.DryingRack");
    GameRegistry.registerTileEntity(DryingRackLogic.class, "Armor.DryingRack");
    TinkerArmor.diamondApple = new DiamondApple().setUnlocalizedName("tconstruct.apple.diamond");
    GameRegistry.registerItem(TinkerArmor.diamondApple, "diamondApple");
    boolean foodOverhaul = false;
    if (Loader.isModLoaded("HungerOverhaul") || Loader.isModLoaded("fc_food")) {
      foodOverhaul = true;
    }

    TinkerArmor.jerky = new Jerky(foodOverhaul).setUnlocalizedName("tconstruct.jerky");
    GameRegistry.registerItem(TinkerArmor.jerky, "jerky");

    // Wearables
    // heavyHelmet = new TArmorBase(PHConstruct.heavyHelmet,
    // 0).setUnlocalizedName("tconstruct.HeavyHelmet");
    TinkerArmor.heartCanister = new HeartCanister().setUnlocalizedName("tconstruct.canister");
    // heavyBoots = new TArmorBase(PHConstruct.heavyBoots,
    // 3).setUnlocalizedName("tconstruct.HeavyBoots");
    // glove = new
    // Glove(PHConstruct.glove).setUnlocalizedName("tconstruct.Glove");
    TinkerArmor.knapsack = new Knapsack().setUnlocalizedName("tconstruct.storage");
    // GameRegistry.registerItem(TRepo.heavyHelmet, "heavyHelmet");
    GameRegistry.registerItem(TinkerArmor.heartCanister, "heartCanister");
    // GameRegistry.registerItem(TRepo.heavyBoots, "heavyBoots");
    // GameRegistry.registerItem(TRepo.glove, "glove");
    GameRegistry.registerItem(TinkerArmor.knapsack, "knapsack");

    LiquidCasting basinCasting = TConstruct.getBasinCasting();
    TinkerArmor.materialWood = EnumHelper.addArmorMaterial("WOOD", 2, new int[] {1, 2, 2, 1}, 3);
    TinkerArmor.helmetWood =
        new ArmorBasic(TinkerArmor.materialWood, 0, "wood")
            .setUnlocalizedName("tconstruct.helmetWood");
    TinkerArmor.chestplateWood =
        new ArmorBasic(TinkerArmor.materialWood, 1, "wood")
            .setUnlocalizedName("tconstruct.chestplateWood");
    TinkerArmor.leggingsWood =
        new ArmorBasic(TinkerArmor.materialWood, 2, "wood")
            .setUnlocalizedName("tconstruct.leggingsWood");
    TinkerArmor.bootsWood =
        new ArmorBasic(TinkerArmor.materialWood, 3, "wood")
            .setUnlocalizedName("tconstruct.bootsWood");
    GameRegistry.registerItem(TinkerArmor.helmetWood, "helmetWood");
    GameRegistry.registerItem(TinkerArmor.chestplateWood, "chestplateWood");
    GameRegistry.registerItem(TinkerArmor.leggingsWood, "leggingsWood");
    GameRegistry.registerItem(TinkerArmor.bootsWood, "bootsWood");
    TConstructRegistry.addItemStackToDirectory(
        "diamondApple", new ItemStack(TinkerArmor.diamondApple, 1, 0));

    TConstructRegistry.addItemStackToDirectory(
        "canisterEmpty", new ItemStack(TinkerArmor.heartCanister, 1, 0));
    TConstructRegistry.addItemStackToDirectory(
        "miniRedHeart", new ItemStack(TinkerArmor.heartCanister, 1, 1));
    TConstructRegistry.addItemStackToDirectory(
        "canisterRedHeart", new ItemStack(TinkerArmor.heartCanister, 1, 2));

    travelGoggles =
        (TravelGear) new TravelGear(ArmorPart.Head).setUnlocalizedName("tconstruct.travelgoggles");
    travelVest =
        (TravelGear) new TravelGear(ArmorPart.Chest).setUnlocalizedName("tconstruct.travelvest");
    travelWings = (TravelGear) new TravelWings().setUnlocalizedName("tconstruct.travelwings");
    travelBoots =
        (TravelGear) new TravelGear(ArmorPart.Feet).setUnlocalizedName("tconstruct.travelboots");
    travelGlove = (AccessoryCore) new TravelGlove().setUnlocalizedName("tconstruct.travelgloves");
    travelBelt = (AccessoryCore) new TravelBelt().setUnlocalizedName("tconstruct.travelbelt");
    GameRegistry.registerItem(travelGoggles, "travelGoggles");
    GameRegistry.registerItem(travelVest, "travelVest");
    GameRegistry.registerItem(travelWings, "travelWings");
    GameRegistry.registerItem(travelBoots, "travelBoots");
    GameRegistry.registerItem(travelGlove, "travelGlove");
    GameRegistry.registerItem(travelBelt, "travelBelt");
  }