diff --git a/src/main/java/net/guizhanss/fastmachines/items/FastMachinesItems.java b/src/main/java/net/guizhanss/fastmachines/items/FastMachinesItems.java index 8aede88..20b47c7 100644 --- a/src/main/java/net/guizhanss/fastmachines/items/FastMachinesItems.java +++ b/src/main/java/net/guizhanss/fastmachines/items/FastMachinesItems.java @@ -26,6 +26,7 @@ public final class FastMachinesItems { // // + // vanilla public static final SlimefunItemStack FAST_CRAFTING_TABLE = FastMachines.getLocalization().getItem( "FAST_CRAFTING_TABLE", Material.CRAFTING_TABLE @@ -34,6 +35,8 @@ public final class FastMachinesItems { "FAST_FURNACE", Material.FURNACE ); + + // Slimefun public static final SlimefunItemStack FAST_ENHANCED_CRAFTING_TABLE = FastMachines.getLocalization().getItem( "FAST_ENHANCED_CRAFTING_TABLE", Material.CARTOGRAPHY_TABLE @@ -90,10 +93,18 @@ public final class FastMachinesItems { "FAST_ANCIENT_ALTAR", Material.ENCHANTING_TABLE ); + + // InfinityExpansion public static final SlimefunItemStack FAST_INFINITY_WORKBENCH = FastMachines.getLocalization().getItem( "FAST_INFINITY_WORKBENCH", Material.RESPAWN_ANCHOR ); + public static final SlimefunItemStack FAST_MOB_DATA_INFUSER = FastMachines.getLocalization().getItem( + "FAST_MOB_DATA_INFUSER", + Material.LODESTONE + ); + + // SlimeFrame public static final SlimefunItemStack FAST_SLIMEFRAME_FOUNDRY = FastMachines.getLocalization().getItem( "FAST_SLIMEFRAME_FOUNDRY", Material.ANVIL diff --git a/src/main/java/net/guizhanss/fastmachines/items/machines/infinityexpansion/FastInfinityWorkbench.java b/src/main/java/net/guizhanss/fastmachines/items/machines/infinityexpansion/FastInfinityWorkbench.java index dcc889c..52dd5a3 100644 --- a/src/main/java/net/guizhanss/fastmachines/items/machines/infinityexpansion/FastInfinityWorkbench.java +++ b/src/main/java/net/guizhanss/fastmachines/items/machines/infinityexpansion/FastInfinityWorkbench.java @@ -1,6 +1,5 @@ package net.guizhanss.fastmachines.items.machines.infinityexpansion; -import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -28,12 +27,7 @@ public FastInfinityWorkbench(SlimefunItemStack item, RecipeType recipeType, Item public void registerRecipes() { FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName()); try { - var recipeType = InfinityWorkbench.TYPE; - List rawRecipes = new ArrayList<>(); - for (var recipe : recipeType.recipes().entrySet()) { - RawRecipe rawRecipe = new RawRecipe(recipe.getKey(), new ItemStack[] {recipe.getValue()}); - rawRecipes.add(rawRecipe); - } + List rawRecipes = RecipeUtils.getInfinityMachineRecipes(InfinityWorkbench.class); RecipeUtils.registerRecipes(recipes, rawRecipes, false); } catch (Exception ex) { FastMachines.log(Level.SEVERE, ex, "An error has occurred while registering recipes for {0}", getClass().getSimpleName()); diff --git a/src/main/java/net/guizhanss/fastmachines/items/machines/infinityexpansion/FastMobDataInfuser.java b/src/main/java/net/guizhanss/fastmachines/items/machines/infinityexpansion/FastMobDataInfuser.java new file mode 100644 index 0000000..2234ef2 --- /dev/null +++ b/src/main/java/net/guizhanss/fastmachines/items/machines/infinityexpansion/FastMobDataInfuser.java @@ -0,0 +1,41 @@ +package net.guizhanss.fastmachines.items.machines.infinityexpansion; + +import java.util.List; +import java.util.logging.Level; + +import org.bukkit.Material; +import org.bukkit.inventory.ItemStack; + +import io.github.mooy1.infinityexpansion.items.mobdata.MobDataInfuser; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; +import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; + +import net.guizhanss.fastmachines.FastMachines; +import net.guizhanss.fastmachines.core.recipes.RawRecipe; +import net.guizhanss.fastmachines.items.machines.generic.AInfinityMachine; +import net.guizhanss.fastmachines.utils.RecipeUtils; + +public final class FastMobDataInfuser extends AInfinityMachine { + private static final ItemStack CRAFT_ITEM = FastMachines.getLocalization().getItem( + "CRAFT", Material.LODESTONE); + + public FastMobDataInfuser(SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) { + super(item, recipeType, recipe); + } + + @Override + public void registerRecipes() { + FastMachines.debug("Registering recipes for {0}", getClass().getSimpleName()); + try { + List rawRecipes = RecipeUtils.getInfinityMachineRecipes(MobDataInfuser.class); + RecipeUtils.registerRecipes(recipes, rawRecipes, false); + } catch (Exception ex) { + FastMachines.log(Level.SEVERE, ex, "An error has occurred while registering recipes for {0}", getClass().getSimpleName()); + } + } + + @Override + protected ItemStack getCraftItem() { + return CRAFT_ITEM; + } +} diff --git a/src/main/java/net/guizhanss/fastmachines/setup/Items.java b/src/main/java/net/guizhanss/fastmachines/setup/Items.java index 159acf1..1ce248c 100644 --- a/src/main/java/net/guizhanss/fastmachines/setup/Items.java +++ b/src/main/java/net/guizhanss/fastmachines/setup/Items.java @@ -13,6 +13,7 @@ import net.guizhanss.fastmachines.FastMachines; import net.guizhanss.fastmachines.items.FastMachinesItems; import net.guizhanss.fastmachines.items.machines.infinityexpansion.FastInfinityWorkbench; +import net.guizhanss.fastmachines.items.machines.infinityexpansion.FastMobDataInfuser; import net.guizhanss.fastmachines.items.machines.slimeframe.FastSlimeFrameFoundry; import net.guizhanss.fastmachines.items.machines.slimefun.FastAncientAltar; import net.guizhanss.fastmachines.items.machines.slimefun.FastArmorForge; @@ -152,6 +153,12 @@ public static void setupIE(FastMachines plugin) { null, null, null, SlimefunItems.OUTPUT_CHEST, getSf("INFINITY_FORGE"), fastCore }).register(plugin); + + new FastMobDataInfuser(FastMachinesItems.FAST_MOB_DATA_INFUSER, RecipeType.MAGIC_WORKBENCH, new ItemStack[] { + null, null, null, + null, null, null, + SlimefunItems.OUTPUT_CHEST, getSf("DATA_INFUSER"), fastCore + }).register(plugin); } public static void setupSFrame(FastMachines plugin) { diff --git a/src/main/java/net/guizhanss/fastmachines/utils/RecipeUtils.java b/src/main/java/net/guizhanss/fastmachines/utils/RecipeUtils.java index 6ffb1b8..dc2ef3d 100644 --- a/src/main/java/net/guizhanss/fastmachines/utils/RecipeUtils.java +++ b/src/main/java/net/guizhanss/fastmachines/utils/RecipeUtils.java @@ -1,5 +1,6 @@ package net.guizhanss.fastmachines.utils; +import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.ArrayList; @@ -25,6 +26,7 @@ import org.bukkit.inventory.ShapedRecipe; import org.bukkit.inventory.ShapelessRecipe; +import io.github.mooy1.infinityexpansion.infinitylib.machines.MachineRecipeType; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItem; import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem; @@ -437,4 +439,39 @@ private static void registerVanillaRecipe(List recip recipes.add(iRecipe); } } + + /** + * Obtain and parse the recipes from an InfinityExpansion item. + * It must have a static MachineRecipeType field TYPE. + * + * @param clazz The class of the InfinityExpansion item. + * + * @return The list of {@link RawRecipe}s parsed from the item. + */ + @Nonnull + public static List getInfinityMachineRecipes(Class clazz) { + MachineRecipeType type = null; + List recipes = new ArrayList<>(); + + // get the TYPE field from the class + try { + Field field = clazz.getDeclaredField("TYPE"); + field.setAccessible(true); + + type = (MachineRecipeType) field.get(null); + } catch (NoSuchFieldException | IllegalAccessException | ClassCastException e) { + FastMachines.log(Level.SEVERE, "An error has occurred while getting recipes from InfinityExpansion item class: {0}", clazz.getSimpleName()); + } + if (type == null) { + return recipes; + } + + // parse recipes + for (var recipe : type.recipes().entrySet()) { + RawRecipe rawRecipe = new RawRecipe(recipe.getKey(), new ItemStack[] {recipe.getValue()}); + recipes.add(rawRecipe); + } + + return recipes; + } } diff --git a/src/main/resources/lang/en-US.yml b/src/main/resources/lang/en-US.yml index b10bb1a..7d93406 100644 --- a/src/main/resources/lang/en-US.yml +++ b/src/main/resources/lang/en-US.yml @@ -170,6 +170,11 @@ items: lore: - "&7More useful Infinity Workbench." - "&7Craft without need to put items in order." + FAST_MOB_DATA_INFUSER: + name: "&aFast Mob Data Infuser" + lore: + - "&7More useful Mob Data Infuser." + - "&7Craft without need to put items in order." FAST_SLIMEFRAME_FOUNDRY: name: "&aFast SlimeFrame Foundry" lore: