Skip to content

Commit

Permalink
feat: add fast mob data infuser
Browse files Browse the repository at this point in the history
  • Loading branch information
ybw0014 committed Aug 5, 2024
1 parent accdd7c commit a5d040a
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public final class FastMachinesItems {
// </editor-fold>

// <editor-fold desc="Machines">
// vanilla
public static final SlimefunItemStack FAST_CRAFTING_TABLE = FastMachines.getLocalization().getItem(
"FAST_CRAFTING_TABLE",
Material.CRAFTING_TABLE
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package net.guizhanss.fastmachines.items.machines.infinityexpansion;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;

Expand Down Expand Up @@ -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<RawRecipe> rawRecipes = new ArrayList<>();
for (var recipe : recipeType.recipes().entrySet()) {
RawRecipe rawRecipe = new RawRecipe(recipe.getKey(), new ItemStack[] {recipe.getValue()});
rawRecipes.add(rawRecipe);
}
List<RawRecipe> 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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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<RawRecipe> 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;
}
}
7 changes: 7 additions & 0 deletions src/main/java/net/guizhanss/fastmachines/setup/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/net/guizhanss/fastmachines/utils/RecipeUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -437,4 +439,39 @@ private static <T extends Recipe> void registerVanillaRecipe(List<IRecipe> 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<RawRecipe> getInfinityMachineRecipes(Class<? extends SlimefunItem> clazz) {
MachineRecipeType type = null;
List<RawRecipe> 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;
}
}
5 changes: 5 additions & 0 deletions src/main/resources/lang/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a5d040a

Please sign in to comment.