Skip to content

Commit

Permalink
+ use interfaces for cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
bioastroiner committed Dec 30, 2023
1 parent 5fac88d commit 407657f
Show file tree
Hide file tree
Showing 26 changed files with 557 additions and 250 deletions.
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<IMaterialStack> byProducts();

@ZenGetter
List<IMaterialStack> materials();
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<IItemStack> getOutputs();

@ZenGetter("inputs")
List<IItemStack> getInputs();

@ZenGetter("fluidOutputs")
List<ILiquidStack> getFluidOutputs();

@ZenGetter("fluidInputs")
List<ILiquidStack> getFluidInputs();

boolean remove(IRecipeMap recipeMap);

boolean add(IRecipeMap recipeMap);
}
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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<IRecipe> 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);
}
Loading

0 comments on commit 407657f

Please sign in to comment.