From c373d79151c4ad99a3090c0922e97164b3f5daad Mon Sep 17 00:00:00 2001 From: CraftedMods Date: Tue, 5 May 2020 09:31:06 +0200 Subject: [PATCH] Closed #1 --- CHANGELOG.md | 5 + build.gradle | 2 +- .../jeiLotr/FactionCraftingTable.java | 11 +- .../java/craftedMods/jeiLotr/JEIPlugin.java | 116 ++++++++---------- src/main/resources/META-INF/mods.toml | 2 +- versions.json | 7 +- 6 files changed, 69 insertions(+), 74 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eaaba37..e29498b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ # Changelog of JEI LOTR + +## 1.1.0-BETA +* New faction crafting tables will now be discovered automatically +* Fixed that some recipes were not shown for faction crafting tables + ## 1.0.0-BETA: * First release for LOTR Renewed-1.1 and jei-1.15.2-6.0.0.4 \ No newline at end of file diff --git a/build.gradle b/build.gradle index 29e3dca..24d52b9 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ apply plugin: 'eclipse' apply plugin: 'maven-publish' apply plugin: "net.minecrell.licenser" -version = '1.0.0-BETA' +version = '1.1.0-BETA' group = 'craftedMods.jeiLotr' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'jeilotr' diff --git a/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java b/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java index 72e203c..96118c7 100644 --- a/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java +++ b/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java @@ -21,7 +21,6 @@ import mezz.jei.api.gui.drawable.IDrawable; import mezz.jei.api.helpers.*; import mezz.jei.plugins.vanilla.crafting.*; -import net.minecraft.block.Block; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.ICraftingRecipe; @@ -31,17 +30,17 @@ public class FactionCraftingTable extends CraftingRecipeCategory { private final ResourceLocation uid; - private final Block ctBlock; + private final ItemStack ctIcon; private final IDrawable icon; - public FactionCraftingTable (ResourceLocation uid, Block ctBlock, IGuiHelper guiHelper, + public FactionCraftingTable (ResourceLocation uid, ItemStack ctIcon, IGuiHelper guiHelper, IModIdHelper modIdHelper) { super (guiHelper, modIdHelper); this.uid = uid; - this.ctBlock = ctBlock; - icon = guiHelper.createDrawableIngredient (new ItemStack (ctBlock)); + this.ctIcon = ctIcon; + icon = guiHelper.createDrawableIngredient (ctIcon); this.addCategoryExtension (LOTRShapedRecipe.class, CraftingCategoryExtension::new); this.addCategoryExtension (LOTRShapelessRecipe.class, CraftingCategoryExtension::new); @@ -62,7 +61,7 @@ public Class getRecipeClass () @Override public String getTitle () { - return I18n.format (ctBlock.getTranslationKey ()); + return I18n.format (ctIcon.getTranslationKey ()); } @Override diff --git a/src/main/java/craftedMods/jeiLotr/JEIPlugin.java b/src/main/java/craftedMods/jeiLotr/JEIPlugin.java index 257f21e..0a76681 100644 --- a/src/main/java/craftedMods/jeiLotr/JEIPlugin.java +++ b/src/main/java/craftedMods/jeiLotr/JEIPlugin.java @@ -17,35 +17,21 @@ package craftedMods.jeiLotr; -import java.lang.reflect.Method; +import java.lang.reflect.*; import java.util.*; -import lotr.common.init.*; -import lotr.common.recipe.LOTRRecipes; +import lotr.common.recipe.*; import mezz.jei.api.*; import mezz.jei.api.registration.*; -import net.minecraft.block.*; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Vector4f; -import net.minecraft.item.*; +import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.*; import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.RegistryObject; @JeiPlugin public class JEIPlugin implements IModPlugin { - public static final ResourceLocation DWARVEN_CT_UID = new ResourceLocation ("lotr", "dwarven_ct"); - public static final ResourceLocation GONDOR_CT_UID = new ResourceLocation ("lotr", "gondor_ct"); - public static final ResourceLocation GALADHRIM_CT_UID = new ResourceLocation ("lotr", "galadhrim_ct"); - public static final ResourceLocation HARAD_CT_UID = new ResourceLocation ("lotr", "harad_ct"); - public static final ResourceLocation LINDON_CT_UID = new ResourceLocation ("lotr", "lindon_ct"); - public static final ResourceLocation MORDOR_CT_UID = new ResourceLocation ("lotr", "mordor_ct"); - public static final ResourceLocation RIVENDELL_CT_UID = new ResourceLocation ("lotr", "rivendell_ct"); - public static final ResourceLocation ROHAN_CT_UID = new ResourceLocation ("lotr", "rohan_ct"); - public static final ResourceLocation UMBAR_CT_UID = new ResourceLocation ("lotr", "umbar_ct"); - public static final ResourceLocation WOOD_ELVEN_CT_UID = new ResourceLocation ("lotr", "wood_elven_ct"); - private static Method getRecipesMethod; static @@ -84,39 +70,39 @@ public void initCraftingTables () { craftingTables = new HashSet<> (); - craftingTables.add (new LOTRCraftingTable (DWARVEN_CT_UID, - getCTBlock (LOTRBlocks.DWARVEN_CRAFTING_TABLE), LOTRRecipes.DWARVEN_CRAFTING)); - craftingTables.add (new LOTRCraftingTable (GONDOR_CT_UID, - getCTBlock (LOTRBlocks.GONDOR_CRAFTING_TABLE), LOTRRecipes.GONDOR_CRAFTING)); - craftingTables.add (new LOTRCraftingTable (GALADHRIM_CT_UID, - getCTBlock (LOTRBlocks.GALADHRIM_CRAFTING_TABLE), LOTRRecipes.GALADHRIM_CRAFTING)); - craftingTables.add (new LOTRCraftingTable (HARAD_CT_UID, - getCTBlock (LOTRBlocks.HARAD_CRAFTING_TABLE), LOTRRecipes.HARAD_CRAFTING)); - craftingTables.add (new LOTRCraftingTable (LINDON_CT_UID, - getCTBlock (LOTRBlocks.LINDON_CRAFTING_TABLE), LOTRRecipes.LINDON_CRAFTING)); - craftingTables.add (new LOTRCraftingTable (MORDOR_CT_UID, - getCTBlock (LOTRBlocks.MORDOR_CRAFTING_TABLE), LOTRRecipes.MORDOR_CRAFTING)); - craftingTables.add (new LOTRCraftingTable (RIVENDELL_CT_UID, - getCTBlock (LOTRBlocks.RIVENDELL_CRAFTING_TABLE), LOTRRecipes.RIVENDELL_CRAFTING)); - craftingTables.add (new LOTRCraftingTable (ROHAN_CT_UID, - getCTBlock (LOTRBlocks.ROHAN_CRAFTING_TABLE), LOTRRecipes.ROHAN_CRAFTING)); - craftingTables.add (new LOTRCraftingTable (UMBAR_CT_UID, - getCTBlock (LOTRBlocks.UMBAR_CRAFTING_TABLE), LOTRRecipes.UMBAR_CRAFTING)); - craftingTables.add (new LOTRCraftingTable (WOOD_ELVEN_CT_UID, - getCTBlock (LOTRBlocks.WOOD_ELVEN_CRAFTING_TABLE), LOTRRecipes.WOOD_ELVEN_CRAFTING)); - } - } + try + { + for (Field field : LOTRRecipes.class.getDeclaredFields ()) + { + if (field.getType () == FactionTableType.class && field.getName ().contains ("CRAFTING")) + { + FactionTableType type = (FactionTableType) field.get (null); + + Collection> types = new ArrayList<> (); + types.add (type); + types.addAll (type.getMultiTableTypes ()); + + craftingTables + .add (new LOTRCraftingTable (new ResourceLocation ("lotr", type.recipeID.split (":")[1]), + type.getIcon (), types)); + } + } + JEILotr.LOGGER.debug ("Found " + craftingTables.size () + " faction crafting tables"); + } + catch (Exception e) + { + JEILotr.LOGGER + .error ("Couldn't instantiate the faction crafting tables from the LOTRRecipes type fields", e); + } - private Block getCTBlock (RegistryObject ctBlockRegistryObject) - { - return ctBlockRegistryObject.orElseGet ( () -> Blocks.CRAFTING_TABLE); + } } @Override public void registerRecipeCatalysts (IRecipeCatalystRegistration registration) { initCraftingTables (); - craftingTables.forEach (table -> registration.addRecipeCatalyst (new ItemStack (table.ctBlock), table.uid)); + craftingTables.forEach (table -> registration.addRecipeCatalyst (table.ctIcon.copy (), table.uid)); } @Override @@ -127,7 +113,7 @@ public void registerCategories (IRecipeCategoryRegistration registration) { registration .addRecipeCategories ( - new FactionCraftingTable (table.uid, table.ctBlock, registration.getJeiHelpers ().getGuiHelper (), + new FactionCraftingTable (table.uid, table.ctIcon, registration.getJeiHelpers ().getGuiHelper (), registration.getJeiHelpers ().getModIdHelper ())); }); } @@ -136,27 +122,31 @@ public void registerCategories (IRecipeCategoryRegistration registration) public void registerRecipes (IRecipeRegistration registration) { initCraftingTables (); - craftingTables.forEach (table -> registration.addRecipes (getRecipesOfType (table.recipeType), table.uid)); + craftingTables.forEach (table -> registration.addRecipes (getRecipesOfTypes (table.recipeTypes), table.uid)); } @SuppressWarnings("unchecked") - private Collection> getRecipesOfType (IRecipeType type) + private Collection> getRecipesOfTypes (Collection> types) { + Collection> recipes = new ArrayList<> (); if (getRecipesMethod != null) { try { - return ((Map>) getRecipesMethod.invoke ( - Minecraft.getInstance ().world.getRecipeManager (), - type)).values (); + for (IRecipeType type : types) + { + recipes.addAll ( ((Map>) getRecipesMethod.invoke ( + Minecraft.getInstance ().world.getRecipeManager (), + type)).values ()); + } } catch (Exception e) { JEILotr.LOGGER.error ("Couldn't get the recipes of the specified type", e); } } - return Arrays.asList (); + return recipes; } @Override @@ -175,16 +165,16 @@ public void registerRecipeTransferHandlers (IRecipeTransferRegistration registra private class LOTRCraftingTable { private ResourceLocation uid; - private Block ctBlock; - private IRecipeType recipeType; + private ItemStack ctIcon; + private Collection> recipeTypes; private Class guiClass; private Vector4f guiHandlerArea; - public LOTRCraftingTable (ResourceLocation uid, Block ctBlock, IRecipeType recipeType) + public LOTRCraftingTable (ResourceLocation uid, ItemStack ctIcon, Collection> recipeTypes) { this.uid = uid; - this.ctBlock = ctBlock; - this.recipeType = recipeType; + this.ctIcon = ctIcon; + this.recipeTypes = recipeTypes; } @Override @@ -193,10 +183,10 @@ public int hashCode () final int prime = 31; int result = 1; result = prime * result + getOuterType ().hashCode (); - result = prime * result + (ctBlock == null ? 0 : ctBlock.hashCode ()); + result = prime * result + (ctIcon == null ? 0 : ctIcon.hashCode ()); result = prime * result + (guiClass == null ? 0 : guiClass.hashCode ()); result = prime * result + (guiHandlerArea == null ? 0 : guiHandlerArea.hashCode ()); - result = prime * result + (recipeType == null ? 0 : recipeType.hashCode ()); + result = prime * result + (recipeTypes == null ? 0 : recipeTypes.hashCode ()); result = prime * result + (uid == null ? 0 : uid.hashCode ()); return result; } @@ -213,12 +203,12 @@ public boolean equals (Object obj) LOTRCraftingTable other = (LOTRCraftingTable) obj; if (!getOuterType ().equals (other.getOuterType ())) return false; - if (ctBlock == null) + if (ctIcon == null) { - if (other.ctBlock != null) + if (other.ctIcon != null) return false; } - else if (!ctBlock.equals (other.ctBlock)) + else if (!ctIcon.equals (other.ctIcon)) return false; if (guiClass == null) { @@ -234,12 +224,12 @@ else if (!guiClass.equals (other.guiClass)) } else if (!guiHandlerArea.equals (other.guiHandlerArea)) return false; - if (recipeType == null) + if (recipeTypes == null) { - if (other.recipeType != null) + if (other.recipeTypes != null) return false; } - else if (!recipeType.equals (other.recipeType)) + else if (!recipeTypes.equals (other.recipeTypes)) return false; if (uid == null) { diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index bdf0b53..0184b26 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -3,7 +3,7 @@ loaderVersion="[27,)" issueTrackerURL="http:/github.com/CraftedMods/jei-lotr/issues" [[mods]] modId="jeilotr" -version="1.0.0-BETA" +version="1.1.0-BETA" displayName="JEI LOTR" updateJSONURL="https://raw.githubusercontent.com/CraftedMods/jei-lotr/master/versions.json" displayURL="http://github.com/CraftedMods/jei-lotr" diff --git a/versions.json b/versions.json index 9c217db..dc588de 100644 --- a/versions.json +++ b/versions.json @@ -2,10 +2,11 @@ "homepage": "https://www.curseforge.com/minecraft/mc-mods/jei-lotr/files", "1.15.2": { "1.0.0-ALPHA": "First release for LOTR Renewed-1.0", - "1.0.0-BETA": "Updated to LOTR Renewed-1.1" + "1.0.0-BETA": "Updated to LOTR Renewed-1.1", + "1.1.0-BETA": "Fixed that some faction crafting table recipes were not shown" }, "promos": { - "1.15.2-latest": "1.0.0-BETA", - "1.15.2-recommended": "1.0.0-BETA" + "1.15.2-latest": "1.1.0-BETA", + "1.15.2-recommended": "1.1.0-BETA" } }