diff --git a/src/main/java/net/prehistoricdiner/PrehistoricDiner.java b/src/main/java/net/prehistoricdiner/PrehistoricDiner.java index 939a572..703988a 100644 --- a/src/main/java/net/prehistoricdiner/PrehistoricDiner.java +++ b/src/main/java/net/prehistoricdiner/PrehistoricDiner.java @@ -1,12 +1,17 @@ package net.prehistoricdiner; import net.minecraft.creativetab.CreativeTabs; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.common.Mod.EventHandler; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.registry.ForgeRegistries; +import net.minecraftforge.oredict.OreDictionary; +import net.prehistoricdiner.item.ItemDamageableCrafted; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -31,7 +36,22 @@ public void preInit(FMLPreInitializationEvent event) { @EventHandler public void init(FMLInitializationEvent event) { - + try { + for (Object item : Item.REGISTRY) { + if (item instanceof ItemDamageableCrafted) { + String oreDict = ForgeRegistries.ITEMS.getKey((Item)item).toString(); + OreDictionary.registerOre(oreDict, new ItemStack((Item) item, 1)); + int i = 1; + while (i <= ((ItemDamageableCrafted) item).getMaxDamage()) { + ItemStack stack = new ItemStack((Item) item, 1); + stack.setItemDamage(i); + OreDictionary.registerOre(oreDict, stack); + i ++; + } + } + } + } catch (Exception e) { + } } @EventHandler diff --git a/src/main/java/net/prehistoricdiner/RegistrationHandler.java b/src/main/java/net/prehistoricdiner/RegistrationHandler.java index 3078eae..db10c21 100644 --- a/src/main/java/net/prehistoricdiner/RegistrationHandler.java +++ b/src/main/java/net/prehistoricdiner/RegistrationHandler.java @@ -30,12 +30,12 @@ public static void registerItems(RegistryEvent.Register event) { //Non-food items: - ((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "skillet")).setTranslationKey("prehistoricdiner.skillet").setCreativeTab(PrehistoricDiner.CREATIVE_TAB), - ((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "pot")).setTranslationKey("prehistoricdiner.pot").setCreativeTab(PrehistoricDiner.CREATIVE_TAB), - ((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "knife")).setTranslationKey("prehistoricdiner.knife").setCreativeTab(PrehistoricDiner.CREATIVE_TAB), - ((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "ladle")).setTranslationKey("prehistoricdiner.ladle").setCreativeTab(PrehistoricDiner.CREATIVE_TAB), - ((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "grinder")).setTranslationKey("prehistoricdiner.grinder").setCreativeTab(PrehistoricDiner.CREATIVE_TAB), - ((Item)(new ItemDamageableCrafted()).setRegistryName("prehistoricdiner", "rolling_pin")).setTranslationKey("prehistoricdiner.rolling_pin").setCreativeTab(PrehistoricDiner.CREATIVE_TAB) + ((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "skillet")).setTranslationKey("prehistoricdiner.skillet").setCreativeTab(PrehistoricDiner.CREATIVE_TAB), + ((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "pot")).setTranslationKey("prehistoricdiner.pot").setCreativeTab(PrehistoricDiner.CREATIVE_TAB), + ((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "knife")).setTranslationKey("prehistoricdiner.knife").setCreativeTab(PrehistoricDiner.CREATIVE_TAB), + ((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "ladle")).setTranslationKey("prehistoricdiner.ladle").setCreativeTab(PrehistoricDiner.CREATIVE_TAB), + ((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "grinder")).setTranslationKey("prehistoricdiner.grinder").setCreativeTab(PrehistoricDiner.CREATIVE_TAB), + ((Item)(new ItemDamageableCrafted(32)).setRegistryName("prehistoricdiner", "rolling_pin")).setTranslationKey("prehistoricdiner.rolling_pin").setCreativeTab(PrehistoricDiner.CREATIVE_TAB) }; diff --git a/src/main/java/net/prehistoricdiner/item/ItemDamageableCrafted.java b/src/main/java/net/prehistoricdiner/item/ItemDamageableCrafted.java index 76d7046..f41db6a 100644 --- a/src/main/java/net/prehistoricdiner/item/ItemDamageableCrafted.java +++ b/src/main/java/net/prehistoricdiner/item/ItemDamageableCrafted.java @@ -3,17 +3,24 @@ import net.minecraft.item.Item; import net.minecraft.item.ItemStack; +import javax.annotation.Nonnull; + public class ItemDamageableCrafted extends Item { + public ItemDamageableCrafted(int maxDamage) { + setContainerItem(this); + setMaxDamage(maxDamage); + } + @Override - public ItemStack getContainerItem(ItemStack stack) { - ItemStack result = stack.copy(); - result.setItemDamage(stack.getItemDamage() + 1); + public ItemStack getContainerItem(@Nonnull ItemStack itemStack) { + ItemStack result = itemStack.copy(); + result.setItemDamage(itemStack.getItemDamage() + 1); return result; } @Override - public boolean hasContainerItem(ItemStack stack) { + public boolean hasContainerItem(@Nonnull ItemStack stack) { return stack.getItemDamage() < stack.getMaxDamage(); } } diff --git a/src/main/resources/assets/prehistoricdiner/recipes/flour.json b/src/main/resources/assets/prehistoricdiner/recipes/flour.json index 644f851..73d40a1 100644 --- a/src/main/resources/assets/prehistoricdiner/recipes/flour.json +++ b/src/main/resources/assets/prehistoricdiner/recipes/flour.json @@ -20,7 +20,8 @@ "ore": "cropWheat" }, "7": { - "item": "prehistoricdiner:grinder" + "type": "forge:ore_dict", + "ore": "prehistoricdiner:grinder" } }, "result": {