@@ -69,13 +69,36 @@ public class SmartFactory extends SlimefunItem implements EnergyNetComponent, Re
6969 SlimefunItems .GOLD_10K , SlimefunItems .GOLD_12K , SlimefunItems .GOLD_14K , SlimefunItems .GOLD_16K ,
7070 SlimefunItems .GOLD_18K , SlimefunItems .GOLD_20K , SlimefunItems .GOLD_22K , SlimefunItems .GOLD_24K
7171 ));
72- private final Map <SlimefunItem , ItemStack []> ITEM_RECIPES = new HashMap <>();
72+
73+ // Hidden recipes for items that can use magma blocks instead of netherrack. Must exist in ACCEPTED_ITEMS as well
74+ private static final List <SlimefunItemStack > MAGMA_ALTERNATIVES = new ArrayList <>(Arrays .asList (
75+ SlimefunItems .ELECTRO_MAGNET , SlimefunItems .ELECTRIC_MOTOR , SlimefunItems .HEATING_COIL
76+ ));
77+
78+ private final Map <SlimefunItem , List <ItemStack []>> ITEM_RECIPES = new HashMap <>(); // Items may have multiple recipe variations
7379
7480 public SmartFactory (ItemGroup itemGroup , SlimefunItemStack item , RecipeType recipeType , ItemStack [] recipe ) {
7581 super (itemGroup , item , recipeType , recipe );
7682
7783 for (SlimefunItemStack sfItem : ACCEPTED_ITEMS ) {
78- ITEM_RECIPES .put (sfItem .getItem (), collectRawRecipe (sfItem .getItem ()));
84+ List <ItemStack []> variationList = new ArrayList <>();
85+ variationList .add (collectRawRecipe (sfItem .getItem ()));
86+ ITEM_RECIPES .put (sfItem .getItem (), variationList );
87+ }
88+
89+ for (SlimefunItemStack alternative : MAGMA_ALTERNATIVES ) {
90+ ItemStack [] original = ITEM_RECIPES .get (alternative .getItem ()).get (0 );
91+ ItemStack [] variation = new ItemStack [original .length ];
92+ for (int i = 0 ; i < original .length ; i ++) {
93+ if (original [i ].getType () == Material .NETHERRACK && original [i ].getAmount () % 16 == 0 ) {
94+ variation [i ] = new ItemStack (Material .MAGMA_BLOCK , original [i ].getAmount () / 16 );
95+ } else {
96+ variation [i ] = original [i ].clone ();
97+ }
98+ }
99+
100+ List <ItemStack []> variations = ITEM_RECIPES .get (alternative .getItem ());
101+ variations .add (variation );
79102 }
80103
81104 buildPreset ();
@@ -199,7 +222,7 @@ protected void tick(Block b) {
199222 int currentProgress = progress .getOrDefault (pos , 0 ); // Get current progress from map
200223
201224 // Check if we are ready to send the output
202- HashMap <Integer , Integer > ingredients = getIngredientSlots (b , inv );
225+ HashMap <Integer , Integer > ingredients = getIngredientSlots (inv );
203226 if (ingredients == null ) {
204227 resetProgress (pos , inv );
205228 return ;
@@ -226,7 +249,7 @@ protected void tick(Block b) {
226249 resetProgress (pos , inv );
227250 }
228251
229- private HashMap <Integer , Integer > getIngredientSlots (Block b , BlockMenu inv ) {
252+ private HashMap <Integer , Integer > getIngredientSlots (BlockMenu inv ) {
230253 SlimefunItem key = SlimefunItem .getByItem (inv .getItemInSlot (RECIPE_SLOT ));
231254 if (key == null ) {
232255 return null ;
@@ -238,34 +261,41 @@ private HashMap<Integer, Integer> getIngredientSlots(Block b, BlockMenu inv) {
238261
239262 HashMap <Integer , Integer > ingredientSlots = new HashMap <>();
240263
241- for (ItemStack recipeItem : ITEM_RECIPES .get (key )) {
242- boolean exists = false ;
243-
244- for (int slot : getInputSlots ()) {
245- ItemStack slotItem = inv .getItemInSlot (slot );
246-
247- // Match item and amount
248- if (slotItem != null && SlimefunUtils .isItemSimilar (recipeItem , slotItem , true , false )) {
249- if (recipeItem .getType () == Material .COAL ) {
250- if (slotItem .getAmount () < recipeItem .getAmount ()) {
251- continue ; // Don't leave 1 for coal
264+ for (ItemStack [] variation : ITEM_RECIPES .get (key )) {
265+ boolean validVariation = true ;
266+ for (ItemStack recipeItem : variation ) {
267+ boolean exists = false ;
268+
269+ for (int slot : getInputSlots ()) {
270+ ItemStack slotItem = inv .getItemInSlot (slot );
271+
272+ // Match item and amount
273+ if (slotItem != null && SlimefunUtils .isItemSimilar (recipeItem , slotItem , true , false )) {
274+ if (recipeItem .getType () == Material .COAL ) {
275+ if (slotItem .getAmount () < recipeItem .getAmount ()) {
276+ continue ; // Don't leave 1 for coal
277+ }
278+ } else if (slotItem .getAmount () < recipeItem .getAmount () + 1 ) {
279+ continue ; // Make sure misc items have 1 item left
252280 }
253- } else if (slotItem .getAmount () < recipeItem .getAmount () + 1 ) {
254- continue ; // Make sure misc items have 1 item left
281+
282+ exists = true ;
283+ ingredientSlots .put (slot , recipeItem .getAmount ()); // Save slots and amounts of ingredients
284+ break ;
255285 }
286+ }
256287
257- exists = true ;
258- ingredientSlots .put (slot , recipeItem .getAmount ()); // Save slots and amounts of ingredients
259- break ;
288+ if (!exists ) {
289+ ingredientSlots .clear ();
290+ validVariation = false ;
291+ break ; // Next variation
260292 }
261293 }
262294
263- if (!exists ) {
264- return null ;
265- }
295+ if (validVariation ) return ingredientSlots ;
266296 }
267297
268- return ingredientSlots ;
298+ return null ;
269299 }
270300
271301 private void craft (Block b ) {
@@ -388,10 +418,16 @@ public List<ItemStack> getDisplayRecipes() {
388418 ItemMeta displayMeta = display .getItemMeta ();
389419
390420 List <String > lore = new ArrayList <>();
391- for (ItemStack item : ITEM_RECIPES .get (sfStack .getItem ())) {
421+ // Display the first variation of the recipe to avoid clutter
422+ for (ItemStack item : ITEM_RECIPES .get (sfStack .getItem ()).get (0 )) {
392423 lore .add (Utils .color ("&e" + item .getAmount () + "x " + Utils .getViewableName (item )));
393424 }
394425
426+ if (ITEM_RECIPES .get (sfStack .getItem ()).size () > 1 ) {
427+ lore .add ("" );
428+ lore .add (Utils .color ("&7This recipe has a Magma Block alternative" ));
429+ }
430+
395431 displayMeta .setLore (lore );
396432 display .setItemMeta (displayMeta );
397433 recipes .add (display );
0 commit comments