From 407657f5f013b5039c17f3b61baf3eb8f126cc06 Mon Sep 17 00:00:00 2001 From: bioastroiner <68257484+bioastroiner@users.noreply.github.com> Date: Sun, 31 Dec 2023 01:40:28 +0330 Subject: [PATCH] + use interfaces for cleaner code --- .../api/mods/gregtech/GregTweakerAPI.java | 33 ++++++ .../api/mods/gregtech/oredict/IMaterial.java | 14 +++ .../mods/gregtech/oredict/IMaterialData.java | 61 ++++++++++ .../mods/gregtech/oredict/IMaterialStack.java | 16 +++ .../api/mods/gregtech/oredict/IPrefix.java | 40 +++++++ .../api/mods/gregtech/recipe/IRecipe.java | 38 ++++++ .../mods/gregtech/recipe/IRecipeFactory.java | 81 +++++++++++++ .../api/mods/gregtech/recipe/IRecipeMap.java | 70 +++++++++++ .../mods/bio/gttweaker/core/GTTweaker.java | 41 +++---- .../mods/bio/gttweaker/core/RecipeHelper.java | 1 + .../bio/gttweaker/core/command/GTCommand.java | 3 +- .../mods/gregtech/oredict/CTMaterial.java | 11 +- .../mods/gregtech/oredict/CTMaterialData.java | 62 +++------- .../gregtech/oredict/CTMaterialStack.java | 12 +- .../mods/gregtech/oredict/CTPrefix.java | 26 ++-- .../bracket/CTPrefixBracketHandler.java | 3 +- .../mods/gregtech/recipe/CTRecipe.java | 38 +++--- .../mods/gregtech/recipe/CTRecipeFactory.java | 112 +++++++++--------- .../mods/gregtech/recipe/CTRecipeMap.java | 94 +++++---------- .../mods/gregtech/recipe/CTRecipeMaps.java | 7 +- .../recipe/actions/AddRecipeAction.java | 1 + .../recipe/actions/RemoveRecipeAction.java | 1 + .../bracket/CTRecipeMapBracketHandler.java | 3 +- .../minetweaker/CTIItemStackExpansion.java | 22 ++-- .../minetweaker/CTILiquidStackExpansion.java | 7 +- .../mods/minetweaker/CTIOreDictExpansion.java | 10 +- 26 files changed, 557 insertions(+), 250 deletions(-) create mode 100644 src/main/java/mods/bio/gttweaker/api/mods/gregtech/GregTweakerAPI.java create mode 100644 src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterial.java create mode 100644 src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterialData.java create mode 100644 src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterialStack.java create mode 100644 src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IPrefix.java create mode 100644 src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipe.java create mode 100644 src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipeFactory.java create mode 100644 src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipeMap.java diff --git a/src/main/java/mods/bio/gttweaker/api/mods/gregtech/GregTweakerAPI.java b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/GregTweakerAPI.java new file mode 100644 index 0000000..afc0d09 --- /dev/null +++ b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/GregTweakerAPI.java @@ -0,0 +1,33 @@ +package mods.bio.gttweaker.api.mods.gregtech; + +import gregapi.oredict.OreDictMaterial; +import minetweaker.api.item.IIngredient; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterial; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.oredict.OreDictionary; + +public class GregTweakerAPI { + public static OreDictMaterial getMaterial(IMaterial iMaterial){ + return iMaterial.getMaterial(); + } + +// public static OreDictPrefix getPrefix(IPrefix iPrefix){ +// return iPrefix. +// } + + public static ItemStack getItemStackOrNull(IIngredient ingredient) { + Object internal = ingredient.getInternal(); + if (internal instanceof ItemStack) return (ItemStack) internal; + else if (internal instanceof String) return OreDictionary.getOres((String) internal) + .size() > 0 ? OreDictionary.getOres((String) internal) + .get(0) : null; + return null; + } + + public static FluidStack getFluidStackOrNull(IIngredient ingredient) { + Object internal = ingredient.getInternal(); + if (internal instanceof FluidStack) return (FluidStack) internal; + return null; + } +} diff --git a/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterial.java b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterial.java new file mode 100644 index 0000000..2f88622 --- /dev/null +++ b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterial.java @@ -0,0 +1,14 @@ +package mods.bio.gttweaker.api.mods.gregtech.oredict; + +import gregapi.oredict.OreDictMaterial; +import stanhebben.zenscript.annotations.OperatorType; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenOperator; + +@ZenClass("mods.gregtech.oredict.IMaterial") +public interface IMaterial { + OreDictMaterial getMaterial(); + + @ZenOperator(OperatorType.MUL) + IMaterialStack multiply(long amount); +} diff --git a/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterialData.java b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterialData.java new file mode 100644 index 0000000..ce6d0cb --- /dev/null +++ b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterialData.java @@ -0,0 +1,61 @@ +package mods.bio.gttweaker.api.mods.gregtech.oredict; + +import gregapi.oredict.OreDictItemData; +import gregapi.oredict.OreDictManager; +import gregapi.oredict.OreDictMaterial; +import gregapi.oredict.OreDictMaterialStack; +import minetweaker.MineTweakerAPI; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import minetweaker.api.minecraft.MineTweakerMC; +import minetweaker.api.oredict.IOreDictEntry; +import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterialData; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenGetter; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.List; + +import static gregapi.data.CS.F; + +@ZenClass("mods.gregtech.oredict.IMaterialData") +public interface IMaterialData { + @ZenMethod + public static IMaterialData association(IItemStack item) { + OreDictItemData data = OreDictManager.INSTANCE.getAssociation(MineTweakerMC.getItemStack(item), F); + if (data != null) return new CTMaterialData(data); + MineTweakerAPI.logError(item + " dose not have a GT Association!"); + return null; + } + + @ZenMethod + public static IMaterialData association(ILiquidStack iLiquidStack) { + OreDictMaterialStack stack = OreDictMaterial.FLUID_MAP.get(MineTweakerMC.getLiquidStack(iLiquidStack).getFluid().getName()); + if (stack != null) { + OreDictItemData data = new OreDictItemData(stack); + return new CTMaterialData(data); + } + MineTweakerAPI.logError(iLiquidStack + " dose not have a GT Association!"); + return null; + } + + @ZenMethod + public static IMaterialData association(IOreDictEntry ore) { + OreDictItemData data = OreDictManager.INSTANCE.getAutomaticItemData(ore.getName()); + if (data != null) return new CTMaterialData(data); + MineTweakerAPI.logError(ore + " dose not have a GT Association!"); + return null; + } + + @ZenGetter + IMaterialStack material(); + + @ZenGetter + IPrefix prefix(); + + @ZenGetter + List byProducts(); + + @ZenGetter + List materials(); +} diff --git a/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterialStack.java b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterialStack.java new file mode 100644 index 0000000..a1a3a88 --- /dev/null +++ b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IMaterialStack.java @@ -0,0 +1,16 @@ +package mods.bio.gttweaker.api.mods.gregtech.oredict; + +import stanhebben.zenscript.annotations.OperatorType; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenGetter; +import stanhebben.zenscript.annotations.ZenOperator; + +@ZenClass("mods.gregtech.oredict.IMaterialStack") +public interface IMaterialStack { + @ZenGetter + IMaterial material(); + + @ZenOperator(OperatorType.MUL) + @ZenGetter + long amount(); +} diff --git a/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IPrefix.java b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IPrefix.java new file mode 100644 index 0000000..b955280 --- /dev/null +++ b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/oredict/IPrefix.java @@ -0,0 +1,40 @@ +package mods.bio.gttweaker.api.mods.gregtech.oredict; + +import minetweaker.api.item.IItemStack; +import minetweaker.api.oredict.IOreDictEntry; +import mods.bio.gttweaker.mods.gregtech.oredict.CTPrefix; +import stanhebben.zenscript.annotations.ZenGetter; +import stanhebben.zenscript.annotations.ZenMethod; + +public interface IPrefix { + @ZenGetter + long amount(); + + @ZenMethod + IItemStack withMaterial(IMaterial aMaterial); + + @ZenMethod + IItemStack mat(IMaterial aMaterial); + + @ZenMethod + IItemStack material(IMaterial aMaterial); + + @ZenMethod + IPrefix disableItemGeneration(); + + @ZenMethod + IPrefix forceItemGeneration(); + + @ZenMethod + boolean contains(IItemStack aIItemStack); + + @ZenMethod + boolean contains(IItemStack... aIItemStacks); + + @ZenMethod + // TODO there is more to this visit later, but it's rather ready for production + IPrefix contains(int stackSize); + + // TODO: to be implemented + boolean contains(IOreDictEntry aIOreDictEntry); +} diff --git a/src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipe.java b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipe.java new file mode 100644 index 0000000..c030458 --- /dev/null +++ b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipe.java @@ -0,0 +1,38 @@ +package mods.bio.gttweaker.api.mods.gregtech.recipe; + +import gregapi.recipes.Recipe; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenGetter; + +import java.util.List; + +@ZenClass("mods.gregtech.recipe.IRecipe") +public interface IRecipe { + @ZenGetter + int duration(); + + @ZenGetter + int EUt(); + + @ZenGetter + int meta(); + + @ZenGetter("outputs") + List getOutputs(); + + @ZenGetter("inputs") + List getInputs(); + + @ZenGetter("fluidOutputs") + List getFluidOutputs(); + + @ZenGetter("fluidInputs") + List getFluidInputs(); + + boolean remove(IRecipeMap recipeMap); + + boolean add(IRecipeMap recipeMap); +} diff --git a/src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipeFactory.java b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipeFactory.java new file mode 100644 index 0000000..16feaf5 --- /dev/null +++ b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipeFactory.java @@ -0,0 +1,81 @@ +package mods.bio.gttweaker.api.mods.gregtech.recipe; + +import minetweaker.api.item.IIngredient; +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterial; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IPrefix; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenMethod; + +@ZenClass("mods.gregtech.recipe.IRecipeFactory") +public interface IRecipeFactory { + @ZenMethod + IRecipeFactory EUt(int energy); + + @ZenMethod + IRecipeFactory duration(int ticks); + + @ZenMethod + IRecipeFactory nonConsumable(IItemStack stack); + + @ZenMethod + IRecipeFactory circuit(int config); + + @ZenMethod + IRecipeFactory specialValue(int config); + + @ZenMethod + IRecipeFactory input(IPrefix aPrefix, IMaterial aMaterial); + + @ZenMethod + IRecipeFactory input(IPrefix aPrefix, IMaterial aMaterial, int aAmount); + + @ZenMethod + IRecipeFactory output(IPrefix aPrefix, IMaterial aMaterial); + + @ZenMethod + IRecipeFactory output(IPrefix aPrefix, IMaterial aMaterial, int aAmount); + + @ZenMethod + IRecipeFactory input(IItemStack input); + + @ZenMethod + IRecipeFactory inputs(IItemStack... inputs); + + @ZenMethod("inputFluid") + IRecipeFactory fluidInput(ILiquidStack input); + + @ZenMethod("inputFluids") + IRecipeFactory fluidInputs(ILiquidStack... inputs); + + @ZenMethod + IRecipeFactory output(IItemStack output); + + @ZenMethod + IRecipeFactory outputs(IItemStack... outputs); + + @ZenMethod + IRecipeFactory chancedOutput(IItemStack output, int chance); + + @ZenMethod("outputFluid") + IRecipeFactory fluidOutput(ILiquidStack output); + + @ZenMethod("outputFluids") + IRecipeFactory fluidOutputs(ILiquidStack... fluids); + + @ZenMethod + IRecipeFactory output(IIngredient ingredient); + + @ZenMethod + IRecipeFactory input(IIngredient ingredient); + + @ZenMethod + IRecipeFactory inputs(IIngredient... ingredients); + + @ZenMethod + IRecipe build(); + + @ZenMethod + void buildAndRegister(); +} diff --git a/src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipeMap.java b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipeMap.java new file mode 100644 index 0000000..04d9b8c --- /dev/null +++ b/src/main/java/mods/bio/gttweaker/api/mods/gregtech/recipe/IRecipeMap.java @@ -0,0 +1,70 @@ +package mods.bio.gttweaker.api.mods.gregtech.recipe; + +import minetweaker.api.item.IItemStack; +import minetweaker.api.liquid.ILiquidStack; +import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipe; +import stanhebben.zenscript.annotations.ZenClass; +import stanhebben.zenscript.annotations.ZenGetter; +import stanhebben.zenscript.annotations.ZenMethod; + +import java.util.List; + +@ZenClass("mods.gregtech.recipe.IRecipeMap") +public interface IRecipeMap { + @ZenMethod("name") + String getNameShort(); + + @ZenMethod("nameInternal") + String getNameInternal(); + + @ZenMethod("getRecipes") + List getRecipesCT(); + + @ZenMethod("findRecipe") + CTRecipe findRecipeCT(IItemStack[] itemsIn, ILiquidStack[] liquidsIn); + + @ZenMethod("removeRecipe") + boolean removeRecipeCT(IItemStack[] itemsIn); + + @ZenMethod("removeRecipe") + boolean removeRecipeCT(ILiquidStack[] liquidsIn); + + @ZenMethod("removeRecipe") + boolean removeRecipeCT(IItemStack[] itemsIn, ILiquidStack[] liquidsIn); + + @ZenMethod + boolean remove(IRecipe recipe); + + @ZenMethod + boolean add(IRecipe recipe); + + @ZenMethod + IRecipeFactory factory(); + + @ZenGetter("minInputs") + int getMinInputs(); + + @ZenGetter("maxInputs") + int getMaxInputs(); + + @ZenGetter("minOutputs") + int getMinOutputs(); + + @ZenGetter("maxOutputs") + int getMaxOutputs(); + + @ZenGetter("minFluidInputs") + int getMinFluidInputs(); + + @ZenGetter("maxFluidInputs") + int getMaxFluidInputs(); + + @ZenGetter("minFluidOutputs") + int getMinFluidOutputs(); + + @ZenGetter("maxFluidOutputs") + int getMaxFluidOutputs(); + + @ZenMethod("register") + void registerRecipe(IRecipe recipe); +} diff --git a/src/main/java/mods/bio/gttweaker/core/GTTweaker.java b/src/main/java/mods/bio/gttweaker/core/GTTweaker.java index 44f41eb..02ad9a2 100644 --- a/src/main/java/mods/bio/gttweaker/core/GTTweaker.java +++ b/src/main/java/mods/bio/gttweaker/core/GTTweaker.java @@ -6,12 +6,17 @@ import minetweaker.MineTweakerImplementationAPI; import minetweaker.api.item.IIngredient; import minetweaker.util.IEventHandler; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterial; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterialData; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterialStack; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IPrefix; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipe; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipeFactory; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipeMap; import mods.bio.gttweaker.core.command.GTCommand; import mods.bio.gttweaker.core.json.OreDictMaterial_Serializable; import mods.bio.gttweaker.mods.gregtech.oredict.*; import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipe; -import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipeFactory; -import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipeMap; import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipeMaps; import mods.bio.gttweaker.mods.gregtech.oredict.bracket.CTMaterialBracketHandler; import mods.bio.gttweaker.mods.gregtech.oredict.bracket.CTPrefixBracketHandler; @@ -127,18 +132,21 @@ public void onModPreInit2(cpw.mods.fml.common.event.FMLPreInitializationEvent aE @Override public void onModInit2(FMLInitializationEvent aEvent) { OreDictMaterial_Serializable._INITLIZE(); - MineTweakerAPI.registerClass(CTRecipe.class); - MineTweakerAPI.registerClass(CTRecipeFactory.class); - MineTweakerAPI.registerClass(CTRecipeMap.class); + + MineTweakerAPI.registerClass(IRecipe.class); + MineTweakerAPI.registerClass(IRecipeFactory.class); + MineTweakerAPI.registerClass(IRecipeMap.class); + + MineTweakerAPI.registerClass(IMaterial.class); + MineTweakerAPI.registerClass(IMaterialStack.class); + MineTweakerAPI.registerClass(IPrefix.class); + MineTweakerAPI.registerClass(IMaterialData.class); + MineTweakerAPI.registerClass(CTRecipeMaps.class); MineTweakerAPI.registerClass(CTUnifier.class); MineTweakerAPI.registerClass(CTIOreDictExpansion.class); MineTweakerAPI.registerClass(CTIItemStackExpansion.class); MineTweakerAPI.registerClass(CTILiquidStackExpansion.class); - MineTweakerAPI.registerClass(CTMaterial.class); - MineTweakerAPI.registerClass(CTMaterialData.class); - MineTweakerAPI.registerClass(CTMaterialStack.class); - MineTweakerAPI.registerClass(CTPrefix.class); MineTweakerAPI.registerBracketHandler(new CTRecipeMapBracketHandler()); MineTweakerAPI.registerBracketHandler(new CTPrefixBracketHandler()); MineTweakerAPI.registerBracketHandler(new CTMaterialBracketHandler()); @@ -197,19 +205,4 @@ public void onModServerStopping2(cpw.mods.fml.common.event.FMLServerStoppingEven public void onModServerStopped2(cpw.mods.fml.common.event.FMLServerStoppedEvent aEvent) { // Insert your ServerStopped Code here and not above } - - public static ItemStack getItemStackOrNull(IIngredient ingredient) { - Object internal = ingredient.getInternal(); - if (internal instanceof ItemStack) return (ItemStack) internal; - else if (internal instanceof String) return OreDictionary.getOres((String) internal) - .size() > 0 ? OreDictionary.getOres((String) internal) - .get(0) : null; - return null; - } - - public static FluidStack getFluidStackOrNull(IIngredient ingredient) { - Object internal = ingredient.getInternal(); - if (internal instanceof FluidStack) return (FluidStack) internal; - return null; - } } diff --git a/src/main/java/mods/bio/gttweaker/core/RecipeHelper.java b/src/main/java/mods/bio/gttweaker/core/RecipeHelper.java index c922f00..2a883ea 100644 --- a/src/main/java/mods/bio/gttweaker/core/RecipeHelper.java +++ b/src/main/java/mods/bio/gttweaker/core/RecipeHelper.java @@ -2,6 +2,7 @@ import gregapi.recipes.Recipe; import minetweaker.MineTweakerAPI; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipe; import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipe; import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipeMap; import net.minecraft.item.ItemStack; diff --git a/src/main/java/mods/bio/gttweaker/core/command/GTCommand.java b/src/main/java/mods/bio/gttweaker/core/command/GTCommand.java index a8eb326..2854dd5 100644 --- a/src/main/java/mods/bio/gttweaker/core/command/GTCommand.java +++ b/src/main/java/mods/bio/gttweaker/core/command/GTCommand.java @@ -12,6 +12,7 @@ import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.player.IPlayer; import minetweaker.api.server.ICommandFunction; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterialData; import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterialData; import org.apache.commons.lang3.StringUtils; @@ -72,7 +73,7 @@ private static void HAND(String[] arguments, IPlayer player) { // TODO Implement GT Hand recipe for held item IItemStack item = player.getCurrentItem(); if (item != null) { - CTMaterialData data = CTMaterialData.association(item); + CTMaterialData data = (CTMaterialData) IMaterialData.association(item); if(data!=null){ List list = new ArrayList<>(); list.add("============================="); diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterial.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterial.java index 20ff7e7..16207f2 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterial.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterial.java @@ -1,19 +1,26 @@ package mods.bio.gttweaker.mods.gregtech.oredict; import gregapi.oredict.OreDictMaterial; +import gregapi.oredict.OreDictMaterialStack; import minetweaker.MineTweakerAPI; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterialStack; import stanhebben.zenscript.annotations.*; import java.util.Objects; -@ZenClass("mods.gregtech.oredict.Material") -public class CTMaterial { +public class CTMaterial implements mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterial { private final OreDictMaterial material_internal; + @Override public OreDictMaterial getMaterial(){ return material_internal; } + @Override + public IMaterialStack multiply(long amount) { + return new CTMaterialStack(new OreDictMaterialStack(getMaterial(),amount)); + } + public CTMaterial(OreDictMaterial aMaterial){ if (aMaterial == null){ MineTweakerAPI.logError("Null Material was provided unable to create a new "); diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterialData.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterialData.java index 3ed9883..4fc3d8b 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterialData.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterialData.java @@ -1,90 +1,56 @@ package mods.bio.gttweaker.mods.gregtech.oredict; import gregapi.oredict.OreDictItemData; -import gregapi.oredict.OreDictManager; -import gregapi.oredict.OreDictMaterial; -import gregapi.oredict.OreDictMaterialStack; import minetweaker.MineTweakerAPI; -import minetweaker.api.item.IItemStack; -import minetweaker.api.liquid.ILiquidStack; -import minetweaker.api.minecraft.MineTweakerMC; -import minetweaker.api.oredict.IOreDictEntry; -import stanhebben.zenscript.annotations.ZenClass; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterialStack; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IPrefix; import stanhebben.zenscript.annotations.ZenGetter; -import stanhebben.zenscript.annotations.ZenMethod; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import static gregapi.data.CS.F; - -@ZenClass("mods.gregtech.oredict.MaterialData") -public class CTMaterialData { +public class CTMaterialData implements mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterialData { public final OreDictItemData backingData; + @Override @ZenGetter - public CTMaterialStack material(){ + public IMaterialStack material(){ if(backingData.mMaterial != null) return new CTMaterialStack(backingData.mMaterial); MineTweakerAPI.logError(this + " dose not have any Main Material"); return null; } + @Override @ZenGetter - public CTPrefix prefix(){ + public IPrefix prefix(){ if(backingData.mPrefix != null) return new CTPrefix(backingData.mPrefix); MineTweakerAPI.logError(this + " dose not have any GT prefix"); return null; } - @ZenGetter - private List byProducts(){ + @Override + public List byProducts(){ if(backingData.mByProducts.length < 1) { MineTweakerAPI.logError(this + " dose not have any GT byproduct"); return new ArrayList<>(); } return Arrays.stream(backingData.mByProducts).map(CTMaterialStack::new).collect(Collectors.toList()); } + @Override @ZenGetter - public List materials(){ - List list = new ArrayList<>(); + public List materials(){ + List list = new ArrayList<>(); list.add(material()); list.addAll(byProducts()); return list; } - private CTMaterialData(OreDictItemData backingData) { + public CTMaterialData(OreDictItemData backingData) { this.backingData = backingData; if(backingData==null) { MineTweakerAPI.logError("Material Data cannot be null",new NullPointerException("Not a valid Material Data.")); } } - @ZenMethod - public static CTMaterialData association(IItemStack item){ - OreDictItemData data = OreDictManager.INSTANCE.getAssociation(MineTweakerMC.getItemStack(item),F); - if(data!=null) return new CTMaterialData(data); - MineTweakerAPI.logError(item + " dose not have a GT Association!"); - return null; - } - - @ZenMethod - public static CTMaterialData association(ILiquidStack iLiquidStack){ - OreDictMaterialStack stack = OreDictMaterial.FLUID_MAP.get(MineTweakerMC.getLiquidStack(iLiquidStack).getFluid().getName()); - if(stack!=null) { - OreDictItemData data = new OreDictItemData(stack); - return new CTMaterialData(data); - } - MineTweakerAPI.logError(iLiquidStack + " dose not have a GT Association!"); - return null; - } - - @ZenMethod - public static CTMaterialData association(IOreDictEntry ore){ - OreDictItemData data = OreDictManager.INSTANCE.getAutomaticItemData(ore.getName()); - if(data!=null) return new CTMaterialData(data); - MineTweakerAPI.logError(ore + " dose not have a GT Association!"); - return null; - } - /** * @return a very JSON like CTMaterialData Representation tough it's not ready for json parsing at all * but is human readable. @@ -103,7 +69,7 @@ public String toString() { StringBuilder builder = new StringBuilder(); if(material() != null) builder.append("{MainMaterial:").append(material()); else builder.append("{NULL"); - List list = byProducts(); + List list = byProducts(); if(!list.isEmpty()) builder.append(",ByProducts:["); list.forEach(s->builder.append(String.format("%d: %s,",list.indexOf(s),s))); if (!list.isEmpty()) builder.reverse().deleteCharAt(0).reverse().append("]}"); diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterialStack.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterialStack.java index c312cfa..365922d 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterialStack.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTMaterialStack.java @@ -1,20 +1,23 @@ package mods.bio.gttweaker.mods.gregtech.oredict; import gregapi.oredict.OreDictMaterialStack; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterial; +import stanhebben.zenscript.annotations.OperatorType; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; +import stanhebben.zenscript.annotations.ZenOperator; import static mods.bio.gttweaker.mods.gregtech.oredict.CTUnifier.U; -@ZenClass("mods.gregtech.MaterialStack") -public class CTMaterialStack { +public class CTMaterialStack implements mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterialStack { private final OreDictMaterialStack _backingStack; - @ZenGetter - public CTMaterial material(){ + @Override + public IMaterial material(){ return new CTMaterial(_backingStack.mMaterial); } + @Override public long amount(){ return _backingStack.mAmount; } @@ -28,7 +31,6 @@ public CTMaterialStack(OreDictMaterialStack backingStack) { */ @Override public String toString() { - // NOTE THAT THIS IS NOT VALID IN ZS return String.format("%s * %f U",material(),((double)amount())/ U()); } } diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTPrefix.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTPrefix.java index ff80866..5ec4d1f 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTPrefix.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/CTPrefix.java @@ -5,6 +5,8 @@ import minetweaker.api.item.IItemStack; import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.oredict.IOreDictEntry; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterial; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IPrefix; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; import stanhebben.zenscript.annotations.ZenMethod; @@ -12,7 +14,7 @@ import java.util.Objects; @ZenClass("mods.gregtech.oredict.Prefix") -public class CTPrefix { +public class CTPrefix implements mods.bio.gttweaker.api.mods.gregtech.oredict.IPrefix { public final OreDictPrefix prefix_internal; public CTPrefix(OreDictPrefix aPrefix) { @@ -45,6 +47,7 @@ public int hashCode() { /** * @return gets a qualified amount on terms of U, its a float TODO we need to work on Unit System and make it a bit unified */ + @Override @ZenGetter public long amount() { return prefix_internal.mAmount; @@ -52,57 +55,66 @@ public long amount() { /* METHODS */ + @Override @ZenMethod - public IItemStack withMaterial(CTMaterial aMaterial) { + public IItemStack withMaterial(IMaterial aMaterial) { IItemStack aStack = MineTweakerMC.getIItemStack(prefix_internal.mat(aMaterial.getMaterial(), 1)); if (aStack == null) MineTweakerAPI.logError(String.format("%s dose not return a valid Item in %s.", aMaterial, this)); return aStack; } + @Override @ZenMethod - public IItemStack mat(CTMaterial aMaterial) { + public IItemStack mat(IMaterial aMaterial) { return withMaterial(aMaterial); } + @Override @ZenMethod - public IItemStack material(CTMaterial aMaterial) { + public IItemStack material(IMaterial aMaterial) { return withMaterial(aMaterial); } + @Override @ZenMethod - public CTPrefix disableItemGeneration() { + public IPrefix disableItemGeneration() { prefix_internal.disableItemGeneration(); MineTweakerAPI.logInfo(String.format("ItemGeneration for %s has been disabled.", this)); return this; } + @Override @ZenMethod - public CTPrefix forceItemGeneration() { + public IPrefix forceItemGeneration() { prefix_internal.forceItemGeneration(); MineTweakerAPI.logInfo(String.format("ItemGeneration for %s has been Forced to be generated.", this)); return this; } + @Override @ZenMethod public boolean contains(IItemStack aIItemStack) { return prefix_internal.contains(MineTweakerMC.getItemStack(aIItemStack)); } + @Override @ZenMethod public boolean contains(IItemStack... aIItemStacks) { return prefix_internal.contains(MineTweakerMC.getItemStacks(aIItemStacks)); } + @Override @ZenMethod // TODO there is more to this visit later, but it's rather ready for production - public CTPrefix contains(int stackSize) { + public IPrefix contains(int stackSize) { MineTweakerAPI.logInfo(String.format("New StackSize has been set for %s from %d to %d", this, prefix_internal.mDefaultStackSize, stackSize)); prefix_internal.setStacksize(stackSize); return this; } // TODO: to be implemented + @Override public boolean contains(IOreDictEntry aIOreDictEntry) { return false; } diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/bracket/CTPrefixBracketHandler.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/bracket/CTPrefixBracketHandler.java index 28608ce..2473ba0 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/bracket/CTPrefixBracketHandler.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/oredict/bracket/CTPrefixBracketHandler.java @@ -5,6 +5,7 @@ import minetweaker.MineTweakerAPI; import minetweaker.annotations.BracketHandler; import minetweaker.runtime.GlobalRegistry; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IPrefix; import mods.bio.gttweaker.mods.gregtech.oredict.CTPrefix; import stanhebben.zenscript.compiler.IEnvironmentGlobal; import stanhebben.zenscript.expression.ExpressionCallStatic; @@ -21,7 +22,7 @@ @BracketHandler() public class CTPrefixBracketHandler implements IBracketHandler { - public static CTPrefix getPrefix(String name) { + public static IPrefix getPrefix(String name) { for (String prefixName : OreDictPrefix.sPrefixes.keySet()) if (prefixName.equalsIgnoreCase(name)) return new CTPrefix(OreDictPrefix.sPrefixes.get(prefixName)); diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipe.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipe.java index 79cf980..964b70c 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipe.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipe.java @@ -5,6 +5,8 @@ import minetweaker.api.liquid.ILiquidStack; import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.mc1710.liquid.MCLiquidStack; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipe; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipeMap; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; @@ -12,61 +14,61 @@ import java.util.List; import java.util.stream.Collectors; -@ZenClass("mods.gregtech.recipe.Recipe") - -public class CTRecipe { +public class CTRecipe implements mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipe { public final Recipe backingRecipe; - public static String format(Recipe recipe){ + + public static String format(Recipe recipe) { return String.format("Recipe(EUt=%d, duration=%d, enabled=%s)\nin=%s\nout=%s\nfluidIn=%s\nfluidOut=%s\nspecial_value=%s", recipe.mEUt, recipe.mDuration, recipe.mEnabled, recipe.mInputs.toString(), recipe.mOutputs.toString(), recipe.mFluidInputs.toString(), recipe.getFluidOutputs().toString(), recipe.mSpecialValue); } + public CTRecipe(Recipe recipe){ this.backingRecipe = recipe; } - @ZenGetter + @Override + public int duration() { return (int) this.backingRecipe.mDuration; } - @ZenGetter + @Override + public int EUt() { return (int) this.backingRecipe.mEUt; } - @ZenGetter + @Override + public int meta() { return (int) this.backingRecipe.mSpecialValue; } - @ZenGetter("outputs") + @Override public List getOutputs() { return Arrays.stream(this.backingRecipe.getOutputs()).map(MineTweakerMC::getIItemStack).collect(Collectors.toList()); } - @ZenGetter("inputs") + @Override public List getInputs() { return Arrays.stream(this.backingRecipe.mInputs).map(MineTweakerMC::getIItemStack).collect(Collectors.toList()); } -// @ZenGetter("chancedOutputs") -// public List getChancedOutputs() { -// return (List)this.backingRecipe.getChancedOutputs().stream().map(CTChancedOutput::new).collect(Collectors.toList()); -// } - - @ZenGetter("fluidOutputs") + @Override public List getFluidOutputs() { return Arrays.stream(this.backingRecipe.getFluidOutputs()).map(MCLiquidStack::new).collect(Collectors.toList()); } - @ZenGetter("fluidInputs") + @Override public List getFluidInputs() { return Arrays.stream(this.backingRecipe.mFluidInputs).map(MCLiquidStack::new).collect(Collectors.toList()); } - public boolean remove(CTRecipeMap recipeMap){ + @Override + public boolean remove(IRecipeMap recipeMap){ return recipeMap.remove(this); } - public boolean add(CTRecipeMap recipeMap){ + @Override + public boolean add(IRecipeMap recipeMap){ return recipeMap.add(this); } diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeFactory.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeFactory.java index 0b6c36b..88d2189 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeFactory.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeFactory.java @@ -8,13 +8,13 @@ import minetweaker.api.liquid.ILiquidStack; import minetweaker.api.minecraft.MineTweakerMC; import minetweaker.api.oredict.IOreDictEntry; -import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterial; -import mods.bio.gttweaker.mods.gregtech.oredict.CTPrefix; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterial; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IPrefix; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipe; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipeFactory; import mods.bio.gttweaker.mods.minetweaker.CTIOreDictExpansion; import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenMethod; import java.util.ArrayList; import java.util.Arrays; @@ -23,15 +23,12 @@ import static gregapi.data.CS.T; import static mods.bio.gttweaker.core.RecipeHelper.checkRecipeIO; -@ZenClass("mods.gregtech.recipe.RecipeFactory") -public class CTRecipeFactory { - private int energy, duration; - +public class CTRecipeFactory implements mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipeFactory { private final List inputs, outputs; private final List inputsFluid, outputsFluid; - private final List chanced; private final Recipe.RecipeMap recipeMap; + private int energy, duration; private int special_value = 0; public CTRecipeFactory(Recipe.RecipeMap recipeMap) { @@ -43,118 +40,122 @@ public CTRecipeFactory(Recipe.RecipeMap recipeMap) { chanced = new ArrayList<>(); } - @ZenMethod - public CTRecipeFactory EUt(int energy) { + @Override + public IRecipeFactory EUt(int energy) { MineTweakerAPI.logCommand("setting EUt: " + energy + "... "); this.energy = energy; return this; } - @ZenMethod - public CTRecipeFactory duration(int ticks) { + @Override + public IRecipeFactory duration(int ticks) { MineTweakerAPI.logCommand("setting duration: " + ticks + "... "); duration = ticks; return this; } - @ZenMethod - public CTRecipeFactory nonConsumable(IItemStack stack) { + @Override + public IRecipeFactory nonConsumable(IItemStack stack) { inputs.add(ST.size(0, MineTweakerMC.getItemStack(stack))); return this; } - @ZenMethod - public CTRecipeFactory circuit(int config) { + @Override + public IRecipeFactory circuit(int config) { return input(MineTweakerMC.getIItemStack(ST.tag(config))); } - @ZenMethod - public CTRecipeFactory specialValue(int config) { + @Override + public IRecipeFactory specialValue(int config) { special_value = config; return this; } - @ZenMethod - public CTRecipeFactory input(CTPrefix aPrefix, CTMaterial aMaterial) { + @Override + public IRecipeFactory input(IPrefix aPrefix, IMaterial aMaterial) { return input(aPrefix, aMaterial, 1); } - @ZenMethod - public CTRecipeFactory input(CTPrefix aPrefix, CTMaterial aMaterial, int aAmount) { + @Override + public IRecipeFactory input(IPrefix aPrefix, IMaterial aMaterial, int aAmount) { return input(aPrefix.withMaterial(aMaterial).amount(aAmount)); } - @ZenMethod - public CTRecipeFactory output(CTPrefix aPrefix, CTMaterial aMaterial) { + @Override + + public IRecipeFactory output(IPrefix aPrefix, IMaterial aMaterial) { return output(aPrefix, aMaterial, 1); } - @ZenMethod - public CTRecipeFactory output(CTPrefix aPrefix, CTMaterial aMaterial, int aAmount) { + @Override + public IRecipeFactory output(IPrefix aPrefix, IMaterial aMaterial, int aAmount) { return output(aPrefix.withMaterial(aMaterial).amount(aAmount)); } - @ZenMethod - public CTRecipeFactory input(IItemStack input) { + @Override + + public IRecipeFactory input(IItemStack input) { MineTweakerAPI.logCommand("adding Input " + input + "... "); inputs.add(MineTweakerMC.getItemStack(input)); return this; } - @ZenMethod - public CTRecipeFactory inputs(IItemStack... inputs) { + @Override + public IRecipeFactory inputs(IItemStack... inputs) { Arrays.stream(inputs).forEach(this::input); return this; } - @ZenMethod("inputFluid") - public CTRecipeFactory fluidInput(ILiquidStack input) { + @Override + public IRecipeFactory fluidInput(ILiquidStack input) { MineTweakerAPI.logCommand("adding Input " + input + "... "); inputsFluid.add(MineTweakerMC.getLiquidStack(input)); return this; } - @ZenMethod("inputFluids") - public CTRecipeFactory fluidInputs(ILiquidStack... inputs) { + @Override + + public IRecipeFactory fluidInputs(ILiquidStack... inputs) { Arrays.stream(inputs).forEach(this::fluidInput); return this; } - @ZenMethod - public CTRecipeFactory output(IItemStack output) { + @Override + public IRecipeFactory output(IItemStack output) { MineTweakerAPI.logCommand("adding Output " + output + "... "); outputs.add(MineTweakerMC.getItemStack(output)); return this; } - @ZenMethod - public CTRecipeFactory outputs(IItemStack... outputs) { + @Override + public IRecipeFactory outputs(IItemStack... outputs) { Arrays.stream(outputs).forEach(this::output); return this; } - @ZenMethod - public CTRecipeFactory chancedOutput(IItemStack output, int chance) { + @Override + public IRecipeFactory chancedOutput(IItemStack output, int chance) { output(output); chanced.set(outputs.size(), chance); return this; } - @ZenMethod("outputFluid") - public CTRecipeFactory fluidOutput(ILiquidStack output) { + @Override + public IRecipeFactory fluidOutput(ILiquidStack output) { MineTweakerAPI.logCommand("adding Output " + output + "... "); outputsFluid.add(MineTweakerMC.getLiquidStack(output)); return this; } - @ZenMethod("outputFluids") - public CTRecipeFactory fluidOutputs(ILiquidStack... fluids) { + @Override + + public IRecipeFactory fluidOutputs(ILiquidStack... fluids) { Arrays.stream(fluids).forEach(this::fluidOutput); return this; } - @ZenMethod - public CTRecipeFactory output(IIngredient ingredient) { + @Override + public IRecipeFactory output(IIngredient ingredient) { if (ingredient instanceof IItemStack) { return output((IItemStack) ingredient); } else if (ingredient instanceof IOreDictEntry) { @@ -166,8 +167,8 @@ public CTRecipeFactory output(IIngredient ingredient) { return this; } - @ZenMethod - public CTRecipeFactory input(IIngredient ingredient) { + @Override + public IRecipeFactory input(IIngredient ingredient) { if (ingredient instanceof IItemStack) { return input((IItemStack) ingredient); } else if (ingredient instanceof IOreDictEntry) { @@ -179,8 +180,8 @@ public CTRecipeFactory input(IIngredient ingredient) { return this; } - @ZenMethod - public CTRecipeFactory inputs(IIngredient... ingredients) { + @Override + public IRecipeFactory inputs(IIngredient... ingredients) { if (ingredients == null || ingredients.length < 1) MineTweakerAPI.logError(Arrays.toString(ingredients) + " is invalid! please provide more than 0 arguments"); else for (IIngredient ingredient : ingredients) { @@ -189,8 +190,8 @@ else for (IIngredient ingredient : ingredients) { return this; } - @ZenMethod - public CTRecipe build() { + @Override + public IRecipe build() { Recipe built; if (checkIO()) return null; long[] chance = new long[chanced.size()]; @@ -205,9 +206,10 @@ private boolean checkIO() { return checkRecipeIO(recipeMap, inputs, outputs, inputsFluid, outputsFluid); } - @ZenMethod + @Override + public void buildAndRegister() { - CTRecipe res = build(); + mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipe res = build(); if (res != null) { res.add(new CTRecipeMap(recipeMap)); } else MineTweakerAPI.logError("COULD NOT CREATE RECIPE FOR \n" + recipeMap.toString()); diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeMap.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeMap.java index c39b04d..5f2917e 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeMap.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeMap.java @@ -1,17 +1,15 @@ package mods.bio.gttweaker.mods.gregtech.recipe; -import cpw.mods.fml.common.Optional; import gregapi.recipes.Recipe; import minetweaker.MineTweakerAPI; import minetweaker.api.item.IItemStack; import minetweaker.api.liquid.ILiquidStack; import minetweaker.api.minecraft.MineTweakerMC; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipe; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipeFactory; import mods.bio.gttweaker.core.GTTweaker; import mods.bio.gttweaker.mods.gregtech.recipe.actions.AddRecipeAction; import mods.bio.gttweaker.mods.gregtech.recipe.actions.RemoveRecipeAction; -import stanhebben.zenscript.annotations.ZenClass; -import stanhebben.zenscript.annotations.ZenGetter; -import stanhebben.zenscript.annotations.ZenMethod; import java.util.*; import java.util.stream.Collectors; @@ -21,8 +19,7 @@ /** * Wraper for GT RecipeMap since that dose not have MT annotations */ -@ZenClass("mods.gregtech.recipe.RecipeMap") -public class CTRecipeMap { +public class CTRecipeMap implements mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipeMap { public final Recipe.RecipeMap backingRecipeMap; public final String nameShort,nameInternal; @@ -34,60 +31,39 @@ public CTRecipeMap(Recipe.RecipeMap mapIn){ nameInternal = mapIn.mNameInternal; nameShort = GTTweaker.FORMAT_RECIPE_MAP(mapIn); } - @ZenMethod("name") - @Optional.Method( - modid = "MineTweaker3" - ) + @Override public String getNameShort(){ return nameShort; } - @ZenMethod("nameInternal") - @Optional.Method( - modid = "MineTweaker3" - ) + @Override public String getNameInternal(){ return nameInternal; } - @ZenMethod("getRecipes") - @Optional.Method( - modid = "MineTweaker3" - ) - public List getRecipesCT() { + @Override + public List getRecipesCT() { return backingRecipeMap.mRecipeList.stream().map(CTRecipe::new).collect(Collectors.toList()); } - @ZenMethod("findRecipe") - @Optional.Method( - modid = "MineTweaker3" - ) + @Override public CTRecipe findRecipeCT(IItemStack[] itemsIn, ILiquidStack[] liquidsIn) { Recipe recipe = backingRecipeMap.findRecipe(null,null,T,Long.MAX_VALUE,null,MineTweakerMC.getLiquidStacks(liquidsIn),MineTweakerMC.getItemStacks(itemsIn)); if (recipe == null) MineTweakerAPI.logWarning(String.format("No Recipe with \nItems: %s - \nFluids: %s Was Found!", Arrays.toString(itemsIn), Arrays.toString(liquidsIn))); return recipe == null ? null : new CTRecipe(recipe); } - @ZenMethod("removeRecipe") - @Optional.Method( - modid = "MineTweaker3" - ) + @Override public boolean removeRecipeCT(IItemStack[] itemsIn) { return removeRecipeCT(itemsIn, null); } - @ZenMethod("removeRecipe") - @Optional.Method( - modid = "MineTweaker3" - ) + @Override public boolean removeRecipeCT(ILiquidStack[] liquidsIn) { return removeRecipeCT(null, liquidsIn); } - @ZenMethod("removeRecipe") - @Optional.Method( - modid = "MineTweaker3" - ) + @Override public boolean removeRecipeCT(IItemStack[] itemsIn, ILiquidStack[] liquidsIn){ return remove(findRecipeCT(itemsIn,liquidsIn)); } @@ -95,82 +71,70 @@ public boolean removeRecipeCT(IItemStack[] itemsIn, ILiquidStack[] liquidsIn){ /** * Remover dose not remove on Reload!!! but it hides and disables the recipes so do not worry. */ - @ZenMethod - @Optional.Method( - modid = "MineTweaker3" - ) - public boolean remove(CTRecipe recipe) { + @Override + public boolean remove(IRecipe recipe) { if(recipe == null) { MineTweakerAPI.logError("NULL recipe was tried to be removed!!!"); return false; } - return RemoveRecipeAction.removeRecipeAction(recipe.backingRecipe,backingRecipeMap); + return RemoveRecipeAction.removeRecipeAction(((CTRecipe) recipe).backingRecipe,backingRecipeMap); } - @ZenMethod - @Optional.Method( - modid = "MineTweaker3" - ) - public boolean add(CTRecipe recipe) { + @Override + public boolean add(IRecipe recipe) { MineTweakerAPI.logCommand("adding " + recipe + " to" + this); - return AddRecipeAction.addRecipe(recipe.backingRecipe,backingRecipeMap); + return AddRecipeAction.addRecipe(((CTRecipe) recipe).backingRecipe,backingRecipeMap); } - @ZenMethod("factory") - @Optional.Method( - modid = "MineTweaker3" - ) - public CTRecipeFactory factoryCT() { + @Override + public IRecipeFactory factory() { return new CTRecipeFactory(this.backingRecipeMap); } - @ZenGetter("minInputs") + @Override public int getMinInputs() { return backingRecipeMap.mMinimalInputItems; } - @ZenGetter("maxInputs") + @Override public int getMaxInputs() { return backingRecipeMap.mInputItemsCount; } - @ZenGetter("minOutputs") + @Override public int getMinOutputs() { //return backingRecipeMap.mOutputItemsCount; return 0; } - @ZenGetter("maxOutputs") + @Override public int getMaxOutputs() { return backingRecipeMap.mOutputItemsCount; } - @ZenGetter("minFluidInputs") + @Override public int getMinFluidInputs() { return backingRecipeMap.mMinimalInputFluids; } - @ZenGetter("maxFluidInputs") + @Override public int getMaxFluidInputs() { return backingRecipeMap.mInputFluidCount; } - @ZenGetter("minFluidOutputs") + @Override public int getMinFluidOutputs() { return 0; } - @ZenGetter("maxFluidOutputs") + @Override public int getMaxFluidOutputs() { return backingRecipeMap.mOutputFluidCount; } - @ZenMethod("register") - @Optional.Method( - modid = "MineTweaker3" - ) - public void registerCT(CTRecipe recipe) { + @Override + public void registerRecipe(IRecipe recipe) { add(recipe); } diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeMaps.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeMaps.java index aff3bb8..0d1c6af 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeMaps.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/CTRecipeMaps.java @@ -1,6 +1,7 @@ package mods.bio.gttweaker.mods.gregtech.recipe; import gregapi.recipes.Recipe; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipeMap; import mods.bio.gttweaker.core.GTTweaker; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; @@ -10,12 +11,12 @@ public class CTRecipeMaps { @ZenMethod - public static CTRecipeMap getRecipeMap(String name) { + public static IRecipeMap getRecipeMap(String name) { return new CTRecipeMap(GTTweaker.FORMAT_RECIPE_MAP(name)); } @ZenGetter - public static CTRecipeMap[] getRecipeMaps(){ - return Recipe.RecipeMap.RECIPE_MAP_LIST.stream().map(CTRecipeMap::new).toArray(CTRecipeMap[]::new); + public static IRecipeMap[] getRecipeMaps(){ + return Recipe.RecipeMap.RECIPE_MAP_LIST.stream().map(CTRecipeMap::new).toArray(IRecipeMap[]::new); } } diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/actions/AddRecipeAction.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/actions/AddRecipeAction.java index 4def719..942277d 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/actions/AddRecipeAction.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/actions/AddRecipeAction.java @@ -3,6 +3,7 @@ import gregapi.recipes.Recipe; import minetweaker.IUndoableAction; import minetweaker.MineTweakerAPI; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipe; import mods.bio.gttweaker.core.RecipeHelper; import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipe; import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipeMap; diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/actions/RemoveRecipeAction.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/actions/RemoveRecipeAction.java index 5a15278..4251b9a 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/actions/RemoveRecipeAction.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/actions/RemoveRecipeAction.java @@ -3,6 +3,7 @@ import gregapi.recipes.Recipe; import minetweaker.IUndoableAction; import minetweaker.MineTweakerAPI; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipe; import mods.bio.gttweaker.core.RecipeHelper; import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipe; import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipeMap; diff --git a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/bracket/CTRecipeMapBracketHandler.java b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/bracket/CTRecipeMapBracketHandler.java index b3e45ef..913455c 100644 --- a/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/bracket/CTRecipeMapBracketHandler.java +++ b/src/main/java/mods/bio/gttweaker/mods/gregtech/recipe/bracket/CTRecipeMapBracketHandler.java @@ -5,6 +5,7 @@ import minetweaker.MineTweakerAPI; import minetweaker.annotations.BracketHandler; import minetweaker.runtime.GlobalRegistry; +import mods.bio.gttweaker.api.mods.gregtech.recipe.IRecipeMap; import mods.bio.gttweaker.core.GTTweaker; import mods.bio.gttweaker.mods.gregtech.recipe.CTRecipeMap; import stanhebben.zenscript.compiler.IEnvironmentGlobal; @@ -22,7 +23,7 @@ @BracketHandler(priority = 99) public class CTRecipeMapBracketHandler implements IBracketHandler { - public static CTRecipeMap getRM(String name){ + public static IRecipeMap getRM(String name){ Recipe.RecipeMap out = GTTweaker.FORMAT_RECIPE_MAP(name); if(out!=null){ return new CTRecipeMap(out); diff --git a/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTIItemStackExpansion.java b/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTIItemStackExpansion.java index 4e0e231..12a5244 100644 --- a/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTIItemStackExpansion.java +++ b/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTIItemStackExpansion.java @@ -1,13 +1,9 @@ package mods.bio.gttweaker.mods.minetweaker; -import gregapi.oredict.OreDictItemData; -import gregapi.oredict.OreDictManager; -import minetweaker.MineTweakerAPI; import minetweaker.api.item.IItemStack; -import minetweaker.api.minecraft.MineTweakerMC; -import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterialData; -import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterialStack; -import mods.bio.gttweaker.mods.gregtech.oredict.CTPrefix; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterialData; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterialStack; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IPrefix; import mods.bio.gttweaker.mods.gregtech.oredict.CTUnifier; import stanhebben.zenscript.annotations.ZenExpansion; import stanhebben.zenscript.annotations.ZenGetter; @@ -29,29 +25,29 @@ public static boolean removeMaterialData(IItemStack aIItemStack) { } @ZenGetter - public static CTMaterialData association(IItemStack iItemStack){ - return CTMaterialData.association(iItemStack); + public static IMaterialData association(IItemStack iItemStack){ + return IMaterialData.association(iItemStack); } @ZenGetter - public static CTMaterialData data(IItemStack iItemStack){ + public static IMaterialData data(IItemStack iItemStack){ return association(iItemStack); } @ZenGetter - public static List materials(IItemStack aIItemStack) { + public static List materials(IItemStack aIItemStack) { if(data(aIItemStack) == null) return null; return Objects.requireNonNull(data(aIItemStack)).materials(); } @ZenGetter - public static CTMaterialStack material(IItemStack aIItemStack) { + public static IMaterialStack material(IItemStack aIItemStack) { if(data(aIItemStack) == null) return null; return Objects.requireNonNull(data(aIItemStack)).material(); } @ZenGetter - public static CTPrefix prefix(IItemStack aIItemStack) { + public static IPrefix prefix(IItemStack aIItemStack) { if(data(aIItemStack) == null) return null; return Objects.requireNonNull(data(aIItemStack)).prefix(); } diff --git a/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTILiquidStackExpansion.java b/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTILiquidStackExpansion.java index a57a539..c1d578f 100644 --- a/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTILiquidStackExpansion.java +++ b/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTILiquidStackExpansion.java @@ -1,6 +1,7 @@ package mods.bio.gttweaker.mods.minetweaker; import minetweaker.api.liquid.ILiquidStack; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterialData; import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterialData; import stanhebben.zenscript.annotations.ZenClass; import stanhebben.zenscript.annotations.ZenGetter; @@ -8,12 +9,12 @@ @ZenClass("minetweaker.item.ILiquidStack") public class CTILiquidStackExpansion { @ZenGetter - public static CTMaterialData association(ILiquidStack iLiquidStack) { - return CTMaterialData.association(iLiquidStack); + public static IMaterialData association(ILiquidStack iLiquidStack) { + return IMaterialData.association(iLiquidStack); } @ZenGetter - public static CTMaterialData data(ILiquidStack iLiquidStack) { + public static IMaterialData data(ILiquidStack iLiquidStack) { return association(iLiquidStack); } } diff --git a/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTIOreDictExpansion.java b/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTIOreDictExpansion.java index 4b57664..206ca29 100644 --- a/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTIOreDictExpansion.java +++ b/src/main/java/mods/bio/gttweaker/mods/minetweaker/CTIOreDictExpansion.java @@ -3,6 +3,8 @@ import gregapi.oredict.OreDictManager; import minetweaker.api.item.IItemStack; import minetweaker.api.oredict.IOreDictEntry; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IMaterialData; +import mods.bio.gttweaker.api.mods.gregtech.oredict.IPrefix; import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterial; import mods.bio.gttweaker.mods.gregtech.oredict.CTMaterialData; import mods.bio.gttweaker.mods.gregtech.oredict.CTPrefix; @@ -22,7 +24,7 @@ public static CTMaterial material(IOreDictEntry oreDictEntry){ } @ZenGetter - public static CTPrefix prefix(IOreDictEntry oreDictEntry){ + public static IPrefix prefix(IOreDictEntry oreDictEntry){ return new CTPrefix(OreDictManager.INSTANCE.getAutomaticItemData(oreDictEntry.getName()).mPrefix); } @@ -32,12 +34,12 @@ public static long amount(IOreDictEntry oreDictEntry){ } @ZenGetter - public static CTMaterialData association(IOreDictEntry oreDictEntry){ - return CTMaterialData.association(oreDictEntry); + public static IMaterialData association(IOreDictEntry oreDictEntry){ + return IMaterialData.association(oreDictEntry); } @ZenGetter - public static CTMaterialData data(IOreDictEntry oreDictEntry){ + public static IMaterialData data(IOreDictEntry oreDictEntry){ return association(oreDictEntry); } }