diff --git a/MineTweaker3-API/src/main/java/minetweaker/api/item/IngredientCondition.java b/MineTweaker3-API/src/main/java/minetweaker/api/item/IngredientCondition.java index c69945f..2577048 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/api/item/IngredientCondition.java +++ b/MineTweaker3-API/src/main/java/minetweaker/api/item/IngredientCondition.java @@ -8,113 +8,113 @@ import stanhebben.zenscript.annotations.ZenMethod; * Conditions can be used to set requirements for matching items. They can be * used to require specific NBT tags or damage values, requiring changed items * or as complement to damage-consuming or stack-consuming recipes. - * + * * @author Stan Hebben */ @ZenExpansion("minetweaker.item.IIngredient") public class IngredientCondition { - /** - * Requires the item to be damaged. A damage value of 1 is enough. - * - * @param ingredient target value - * @return damaged condition - */ - @ZenMethod - public static IIngredient onlyDamaged(IIngredient ingredient) { - return ingredient.only(new IItemCondition() { - @Override - public boolean matches(IItemStack stack) { - return stack.getDamage() > 0; - } - }); - } + /** + * Requires the item to be damaged. A damage value of 1 is enough. + * + * @param ingredient target value + * @return damaged condition + */ + @ZenMethod + public static IIngredient onlyDamaged(IIngredient ingredient) { + return ingredient.only(new IItemCondition() { + @Override + public boolean matches(IItemStack stack) { + return stack.getDamage() > 0; + } + }); + } - /** - * Requires the item to be damaged with at least a specified amount. - * - * @param ingredient target value - * @param minDamage minimum damage - * @return damage condition - */ - @ZenMethod - public static IIngredient onlyDamageAtLeast(IIngredient ingredient, final int minDamage) { - return ingredient.only(new IItemCondition() { - @Override - public boolean matches(IItemStack stack) { - return stack.getDamage() >= minDamage; - } - }); - } + /** + * Requires the item to be damaged with at least a specified amount. + * + * @param ingredient target value + * @param minDamage minimum damage + * @return damage condition + */ + @ZenMethod + public static IIngredient onlyDamageAtLeast(IIngredient ingredient, final int minDamage) { + return ingredient.only(new IItemCondition() { + @Override + public boolean matches(IItemStack stack) { + return stack.getDamage() >= minDamage; + } + }); + } - /** - * Requires the item to be damaged with at most a specified amount. An - * undamaged item is accepted. - * - * @param ingredient target value - * @param maxDamage maximum damage - * @return damage condition - */ - @ZenMethod - public static IIngredient onlyDamageAtMost(IIngredient ingredient, final int maxDamage) { - return ingredient.only(new IItemCondition() { - @Override - public boolean matches(IItemStack stack) { - return stack.getDamage() <= maxDamage; - } - }); - } + /** + * Requires the item to be damaged with at most a specified amount. An + * undamaged item is accepted. + * + * @param ingredient target value + * @param maxDamage maximum damage + * @return damage condition + */ + @ZenMethod + public static IIngredient onlyDamageAtMost(IIngredient ingredient, final int maxDamage) { + return ingredient.only(new IItemCondition() { + @Override + public boolean matches(IItemStack stack) { + return stack.getDamage() <= maxDamage; + } + }); + } - /** - * Requires the item damage value to be between two values. - * - * @param ingredient target value - * @param minDamage minimum damage - * @param maxDamage maximum damage - * @return damage condition - */ - @ZenMethod - public static IIngredient onlyDamageBetween(IIngredient ingredient, final int minDamage, final int maxDamage) { - return ingredient.only(new IItemCondition() { - @Override - public boolean matches(IItemStack stack) { - return stack.getDamage() >= minDamage && stack.getDamage() <= maxDamage; - } - }); - } + /** + * Requires the item damage value to be between two values. + * + * @param ingredient target value + * @param minDamage minimum damage + * @param maxDamage maximum damage + * @return damage condition + */ + @ZenMethod + public static IIngredient onlyDamageBetween(IIngredient ingredient, final int minDamage, final int maxDamage) { + return ingredient.only(new IItemCondition() { + @Override + public boolean matches(IItemStack stack) { + return stack.getDamage() >= minDamage && stack.getDamage() <= maxDamage; + } + }); + } - /** - * Requires the item to contain at least the given tags. It is OK for the - * item to contain more data, as remaining data is ignored. - * - * @param ingredient target value - * @param data required data - * @return data condition - */ - @ZenMethod - public static IIngredient onlyWithTag(IIngredient ingredient, final IData data) { - return ingredient.only(new IItemCondition() { - @Override - public boolean matches(IItemStack stack) { - return stack.getTag() != null && stack.getTag().contains(data); - } - }); - } + /** + * Requires the item to contain at least the given tags. It is OK for the + * item to contain more data, as remaining data is ignored. + * + * @param ingredient target value + * @param data required data + * @return data condition + */ + @ZenMethod + public static IIngredient onlyWithTag(IIngredient ingredient, final IData data) { + return ingredient.only(new IItemCondition() { + @Override + public boolean matches(IItemStack stack) { + return stack.getTag() != null && stack.getTag().contains(data); + } + }); + } - /** - * Requires the input stack to contain at least the given number of items. - * Used in combination with stack consuming recipes. - * - * @param ingredient target value - * @param amount required stack size - * @return stack size condition - */ - @ZenMethod - public static IIngredient onlyStack(IIngredient ingredient, final int amount) { - return ingredient.only(new IItemCondition() { - @Override - public boolean matches(IItemStack stack) { - return stack.getAmount() >= amount; - } - }); - } + /** + * Requires the input stack to contain at least the given number of items. + * Used in combination with stack consuming recipes. + * + * @param ingredient target value + * @param amount required stack size + * @return stack size condition + */ + @ZenMethod + public static IIngredient onlyStack(IIngredient ingredient, final int amount) { + return ingredient.only(new IItemCondition() { + @Override + public boolean matches(IItemStack stack) { + return stack.getAmount() >= amount; + } + }); + } } diff --git a/MineTweaker3-API/src/main/java/minetweaker/runtime/providers/ScriptProviderDirectory.java b/MineTweaker3-API/src/main/java/minetweaker/runtime/providers/ScriptProviderDirectory.java index 889c907..376c9b1 100644 --- a/MineTweaker3-API/src/main/java/minetweaker/runtime/providers/ScriptProviderDirectory.java +++ b/MineTweaker3-API/src/main/java/minetweaker/runtime/providers/ScriptProviderDirectory.java @@ -12,10 +12,7 @@ import minetweaker.runtime.IScriptProvider; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; +import java.util.*; /** * @author Stan diff --git a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerMod.java b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerMod.java index b3875c5..dbf14c1 100644 --- a/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerMod.java +++ b/MineTweaker3-MC1102-Main/src/main/java/minetweaker/mc1102/MineTweakerMod.java @@ -34,14 +34,19 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.server.MinecraftServer; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; +import net.minecraftforge.fml.common.discovery.ASMDataTable; import net.minecraftforge.fml.common.event.*; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper; import net.minecraftforge.fml.relauncher.Side; +import stanhebben.zenscript.annotations.ZenExpansion; import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; /** * Main mod class. Performs some general logic, initialization of the API and @@ -108,6 +113,15 @@ public class MineTweakerMod { public void onLoad(FMLPreInitializationEvent ev) { MinecraftForge.EVENT_BUS.register(new ForgeEventHandler()); FMLCommonHandler.instance().bus().register(new FMLEventHandler()); + for (ASMDataTable.ASMData data : ev.getAsmData().getAll(ZenExpansion.class.getCanonicalName())) { + try { + Class asmClass = Class.forName(data.getClassName()); + MineTweakerAPI.registerClass(asmClass); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + } + } @EventHandler @@ -119,6 +133,20 @@ public class MineTweakerMod { } FuelTweaker.INSTANCE.register(); + if (Loader.isModLoaded("JEI")) { + try { + Method register = Class.forName("minetweaker.mods.jei.JEI").getMethod("onRegister"); + register.invoke(null); + } catch (NoSuchMethodException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + } } @EventHandler @@ -154,7 +182,7 @@ public class MineTweakerMod { } IScriptProvider scriptsLocal = new ScriptProviderDirectory(scriptsDir); - IScriptProvider cascaded = new ScriptProviderCascade(scriptsIMC, scriptsGlobal,scriptsLocal); + IScriptProvider cascaded = new ScriptProviderCascade(scriptsIMC, scriptsGlobal, scriptsLocal); MineTweakerImplementationAPI.setScriptProvider(cascaded); MineTweakerImplementationAPI.onServerStart(new MCServer(ev.getServer())); diff --git a/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEI.java b/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEI.java index 1244810..34d2582 100644 --- a/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEI.java +++ b/MineTweaker3-MC1102-Mod-JEI/src/main/java/minetweaker/mods/jei/JEI.java @@ -6,6 +6,7 @@ import minetweaker.MineTweakerImplementationAPI; import minetweaker.annotations.OnRegister; import minetweaker.api.item.IItemStack; import minetweaker.util.IEventHandler; +import net.minecraftforge.fml.common.Loader; import stanhebben.zenscript.annotations.NotNull; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenMethod; @@ -17,7 +18,7 @@ import static minetweaker.mods.jei.JEIAddonPlugin.jeiHelpers; /** * MineTweaker JEI support. - * + *

* Enables hiding JEI items as well as adding new item stacks. These item stacks * can then show a custom message or contain NBT data. Can be used to show a * custom message or lore with certain items, or to provide spawnable items with @@ -28,103 +29,111 @@ import static minetweaker.mods.jei.JEIAddonPlugin.jeiHelpers; @ZenClass("mods.jei.JEI") public class JEI { - /** - * Hides a specific item in JEI. Will take into account metadata values, if - * any. - * - * @param item - * item to be hidden - */ - @ZenMethod - public static void hide(@NotNull IItemStack item) { - MineTweakerAPI.apply(new JEIHideItemAction(item)); - } + /** + * Hides a specific item in JEI. Will take into account metadata values, if + * any. + * + * @param item item to be hidden + */ + @ZenMethod + public static void hide(@NotNull IItemStack item) { + MineTweakerAPI.apply(new JEIHideItemAction(item)); + } - /** - * Register callbacks otherwise the load order with JEI is all messed up. - */ - @OnRegister - public static void onRegister() { - // discard all not yet applied actions before a reload - MineTweakerImplementationAPI.onReloadEvent(new IEventHandler() { - @Override - public void handle(MineTweakerImplementationAPI.ReloadEvent event) { - apply.clear(); - } - }); + /** + * Register callbacks otherwise the load order with JEI is all messed up. + */ + @OnRegister + public static void onRegister() { + // discard all not yet applied actions before a reload + MineTweakerImplementationAPI.onReloadEvent(new IEventHandler() { + @Override + public void handle(MineTweakerImplementationAPI.ReloadEvent event) { + apply.clear(); + } + }); - // after the reload JEI needs to be reloaded as well - MineTweakerImplementationAPI.onPostReload(new IEventHandler() { - @Override - public void handle(MineTweakerImplementationAPI.ReloadEvent event) { - if (jeiHelpers != null) { - jeiHelpers.reload(); - } - } - }); - } + // after the reload JEI needs to be reloaded as well + MineTweakerImplementationAPI.onPostReload(new IEventHandler() { + @Override + public void handle(MineTweakerImplementationAPI.ReloadEvent event) { + if (Loader.isModLoaded("JEI")) { + try { + if (Class.forName("minetweaker.mods.jei.JEIAddonPlugin") != null) { + System.out.println("class exists"); + } + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + if (minetweaker.mods.jei.JEIAddonPlugin.jeiHelpers != null) + minetweaker.mods.jei.JEIAddonPlugin.jeiHelpers.reload(); + } + } + }); + } - // list of all hide actions that need to be applied after JEI is available + // list of all hide actions that need to be applied after JEI is available private static LinkedList apply = new LinkedList(); - /** - * JEI is available and the Hiding of the actions can now be applied. - */ - public static void onJEIStarted() { - for (JEIHideItemAction action : apply) { - action.doApply(); - } + /** + * JEI is available and the Hiding of the actions can now be applied. + */ + public static void onJEIStarted() { + for (JEIHideItemAction action : apply) { + action.doApply(); + } apply.clear(); } - private static class JEIHideItemAction implements IUndoableAction { - private final IItemStack stack; - public JEIHideItemAction(IItemStack stack) { - this.stack = stack; - } + private static class JEIHideItemAction implements IUndoableAction { + private final IItemStack stack; - @Override - public void apply() { - // just register until the JEI addon is registered, otherwise the jeiHelpers are null - apply.add(this); - } + public JEIHideItemAction(IItemStack stack) { + this.stack = stack; + } - /** - * Really adds the item to the blacklist when JEI is available - */ - void doApply() { - if (jeiHelpers != null) { - jeiHelpers.getItemBlacklist().addItemToBlacklist(getItemStack(stack)); - } else { - // Should not happen, but in case only log an error - MineTweakerImplementationAPI.logger.logError("JEI not initialized yet!"); - } - } + @Override + public void apply() { + // just register until the JEI addon is registered, otherwise the jeiHelpers are null + apply.add(this); + } - @Override - public boolean canUndo() { - return true; - } + /** + * Really adds the item to the blacklist when JEI is available + */ + void doApply() { + if (jeiHelpers != null) { + jeiHelpers.getItemBlacklist().addItemToBlacklist(getItemStack(stack)); + } else { + // Should not happen, but in case only log an error + MineTweakerImplementationAPI.logger.logError("JEI not initialized yet!"); + } + } - @Override - public void undo() { - // Doesn't need to be called since on reload of JEI the blacklist will be cleared anyway + @Override + public boolean canUndo() { + return true; + } + + @Override + public void undo() { + // Doesn't need to be called since on reload of JEI the blacklist will be cleared anyway // jeiHelpers.getItemBlacklist().removeItemFromBlacklist(getItemStack(stack)); - } + } - @Override - public String describe() { - return "Hiding " + stack + " in JEI"; - } + @Override + public String describe() { + return "Hiding " + stack + " in JEI"; + } - @Override - public String describeUndo() { - return "Displaying " + stack + " in JEI"; - } + @Override + public String describeUndo() { + return "Displaying " + stack + " in JEI"; + } - @Override - public Object getOverrideKey() { - return null; - } - } + @Override + public Object getOverrideKey() { + return null; + } + } }