From c0b64abbeb55abab0b67f0da4dca4b25eb7f3eeb Mon Sep 17 00:00:00 2001 From: Boblet Date: Wed, 11 Aug 2021 13:47:09 +0200 Subject: [PATCH] patched up shredder recipe shenanigans --- .../java/com/hbm/inventory/RecipesCommon.java | 10 ++ .../com/hbm/inventory/ShredderRecipes.java | 115 +++++++----------- 2 files changed, 55 insertions(+), 70 deletions(-) diff --git a/src/main/java/com/hbm/inventory/RecipesCommon.java b/src/main/java/com/hbm/inventory/RecipesCommon.java index 6bfa5c395..b8ffc69e4 100644 --- a/src/main/java/com/hbm/inventory/RecipesCommon.java +++ b/src/main/java/com/hbm/inventory/RecipesCommon.java @@ -3,7 +3,10 @@ package com.hbm.inventory; import java.util.Arrays; import java.util.List; +import com.hbm.main.MainRegistry; + import net.minecraft.block.Block; +import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -166,6 +169,13 @@ public class RecipesCommon { @Override public int hashCode() { + + if(item == null) { + MainRegistry.logger.error("ComparableStack has a null item! This is a serious issue!"); + Thread.currentThread().dumpStack(); + item = Items.stick; + } + final int prime = 31; int result = 1; result = prime * result + Item.itemRegistry.getNameForObject(item).hashCode(); //using the int ID will cause fucky-wuckys if IDs are scrambled diff --git a/src/main/java/com/hbm/inventory/ShredderRecipes.java b/src/main/java/com/hbm/inventory/ShredderRecipes.java index 6265e5965..d6826f408 100644 --- a/src/main/java/com/hbm/inventory/ShredderRecipes.java +++ b/src/main/java/com/hbm/inventory/ShredderRecipes.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; import com.hbm.blocks.ModBlocks; +import com.hbm.interfaces.Untested; import com.hbm.inventory.RecipesCommon.ComparableStack; import com.hbm.items.ModItems; import com.hbm.main.MainRegistry; @@ -39,82 +40,56 @@ public class ShredderRecipes { if(matches == null || matches.isEmpty()) continue; - if(name.length() > 5 && name.substring(0, 5).equals("ingot")) { - ItemStack dust = getDustByName(name.substring(5)); - - if(dust != null && dust.getItem() != ModItems.scrap) { - - for(ItemStack stack : matches) { - if(stack != null) - shredderRecipes.put(new ComparableStack(stack), dust); - else - MainRegistry.logger.error("Ore dict entry '" + name + "' has a null stack!"); - } - } - } else if(name.length() > 3 && name.substring(0, 3).equals("ore")) { - ItemStack dust = getDustByName(name.substring(3)); - - if(dust != null && dust.getItem() != ModItems.scrap) { - - dust.stackSize = 2; - - for(ItemStack stack : matches) { - if(stack != null) - shredderRecipes.put(new ComparableStack(stack), dust); - else - MainRegistry.logger.error("Ore dict entry '" + name + "' has a null stack!"); - } - } - } else if(name.length() > 5 && name.substring(0, 5).equals("block")) { - ItemStack dust = getDustByName(name.substring(5)); - - if(dust != null && dust.getItem() != ModItems.scrap) { - - dust.stackSize = 9; - - for(ItemStack stack : matches) { - if(stack != null) - shredderRecipes.put(new ComparableStack(stack), dust); - else - MainRegistry.logger.error("Ore dict entry '" + name + "' has a null stack!"); - } - } - } else if(name.length() > 3 && name.substring(0, 3).equals("gem")) { - ItemStack dust = getDustByName(name.substring(3)); - - if(dust != null && dust.getItem() != ModItems.scrap) { - - for(ItemStack stack : matches) { - if(stack != null) - shredderRecipes.put(new ComparableStack(stack), dust); - else - MainRegistry.logger.error("Ore dict entry '" + name + "' has a null stack!"); - } - } - } else if(name.length() > 7 && name.substring(0, 7).equals("crystal")) { - ItemStack dust = getDustByName(name.substring(7)); - - if(dust != null && dust.getItem() != ModItems.scrap) { - - for(ItemStack stack : matches) { - if(stack != null) - shredderRecipes.put(new ComparableStack(stack), dust); - else - MainRegistry.logger.error("Ore dict entry '" + name + "' has a null stack!"); - } - } - } else if(name.length() > 3 && name.substring(0, 4).equals("dust")) { - + generateRecipes("ingot", name, matches, 1); + generateRecipes("ore", name, matches, 2); + generateRecipes("block", name, matches, 9); + generateRecipes("gem", name, matches, 1); + generateRecipes("crystal", name, matches, 1); + + if(name.length() > 3 && name.substring(0, 4).equals("dust")) { for(ItemStack stack : matches) { - if(stack != null) - shredderRecipes.put(new ComparableStack(stack), new ItemStack(ModItems.dust)); - else - MainRegistry.logger.error("Ore dict entry '" + name + "' has a null stack!"); + putIfValid(stack, new ItemStack(ModItems.dust), name); } } } } + @Untested + private static void generateRecipes(String prefix, String name, List matches, int outCount) { + + int len = prefix.length(); + + if(name.length() > len && name.substring(0, len).equals(prefix)) { + ItemStack dust = getDustByName(name.substring(len)); + + if(dust != null && dust.getItem() != ModItems.scrap) { + + dust.stackSize = outCount; + + for(ItemStack stack : matches) { + putIfValid(stack, dust, name); + } + } + } + } + + private static void putIfValid(ItemStack in, ItemStack dust, String name) { + + if(in != null) { + + if(in.getItem() != null) { + shredderRecipes.put(new ComparableStack(in), dust); + } else { + MainRegistry.logger.error("Ore dict entry '" + name + "' has a null item in its stack! How does that even happen?"); + Thread.currentThread().dumpStack(); + } + + } else { + MainRegistry.logger.error("Ore dict entry '" + name + "' has a null stack!"); + Thread.currentThread().dumpStack(); + } + } + public static void registerOverrides() { ShredderRecipes.setRecipe(ModItems.scrap, new ItemStack(ModItems.dust));