diff --git a/CHANGELOG.md b/CHANGELOG.md index c8b4960..c097d88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog of JEI LOTR +## 3.0.0-BETA +* Updated to LOTR Renewed-4.5 +* Added support for addons + ## 2.0.0-BETA * Updated to 1.16.5 and LOTR Renewed-3.0 diff --git a/README.md b/README.md index 1834f69..e843f73 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ The plugin adds JEI support for all devices and recipes added by the LOTR Mod. ## Dependencies JEI LOTR has the following dependencies: -- [The Lord of the Rings Mod Renewed v3.0](https://www.curseforge.com/minecraft/mc-mods/the-lord-of-the-rings-mod-renewed/files) +- [The Lord of the Rings Mod Renewed v4.5](https://www.curseforge.com/minecraft/mc-mods/the-lord-of-the-rings-mod-renewed/files) - [JEI 1.16.5-7.6.4.86](https://www.curseforge.com/minecraft/mc-mods/jei/files/all) The plugin was created with the MinecraftForge version "1.16.5-36.1.0". diff --git a/build.gradle b/build.gradle index ce9f927..77549c7 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ apply plugin: 'eclipse' apply plugin: 'maven-publish' apply plugin: "net.minecrell.licenser" -version = '2.0.0-BETA' +version = '3.0.0-BETA' group = 'craftedMods.jeiLotr' // http://maven.apache.org/guides/mini/guide-naming-conventions.html archivesBaseName = 'jeilotr' @@ -34,7 +34,7 @@ minecraft { // stable_# Stables are built at the discretion of the MCP team. // Use non-default mappings at your own risk. they may not always work. // Simply re-run your setup task after changing the mappings to update your workspace. - mappings channel: 'official', version: '1.16.5' + mappings channel: 'snapshot', version: '20210309-1.16.5' // makeObfSourceJar = false // an Srg named sources jar is made by default. uncomment this to disable. // accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') @@ -107,7 +107,7 @@ dependencies { // Specify the version of Minecraft to use, If this is any group other then 'net.minecraft' it is assumed // that the dep is a ForgeGradle 'patcher' dependency. And it's patches will be applied. // The userdev artifact is a special name and will get all sorts of transformations applied to it. - minecraft 'net.minecraftforge:forge:1.16.5-36.1.0' + minecraft 'net.minecraftforge:forge:1.16.5-36.2.2' compileOnly fg.deobf("mezz.jei:jei-${jei_mc_version}:${jei_version}") diff --git a/gradle.properties b/gradle.properties index 442e711..0ae3346 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,4 +4,4 @@ org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false jei_mc_version=1.16.5 jei_version=7.6.4.86 -lotr_version=3.0 +lotr_version=4.5 diff --git a/src/main/java/craftedMods/jeiLotr/AlloyForge.java b/src/main/java/craftedMods/jeiLotr/AlloyForge.java index 337e9e9..39e2aef 100644 --- a/src/main/java/craftedMods/jeiLotr/AlloyForge.java +++ b/src/main/java/craftedMods/jeiLotr/AlloyForge.java @@ -22,8 +22,7 @@ import lotr.common.recipe.AbstractAlloyForgeRecipe; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.gui.drawable.IDrawableAnimated; +import mezz.jei.api.gui.drawable.*; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.ingredients.IIngredients; @@ -33,107 +32,126 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.AbstractCookingRecipe; -import net.minecraft.item.crafting.IRecipe; +import net.minecraft.item.crafting.*; import net.minecraft.util.ResourceLocation; -public class AlloyForge extends FurnaceVariantCategory> { - - private final ResourceLocation uid; - private final ItemStack forgeIcon; - private final IDrawable icon; - private final IDrawable background; - private final IDrawable arrow; - - public static final ResourceLocation ALLOY_FORGE_GUI_LOCATION = new ResourceLocation( - "lotr:textures/gui/alloy_forge.png"); - - public AlloyForge(ResourceLocation uid, ItemStack forgeIcon, IGuiHelper guiHelper) { - super(guiHelper); - this.uid = uid; - this.forgeIcon = forgeIcon; - this.icon = guiHelper.createDrawableIngredient(forgeIcon); - this.background = guiHelper.createDrawable(ALLOY_FORGE_GUI_LOCATION, 45, 20, 85, 130); - this.arrow = guiHelper.drawableBuilder(ALLOY_FORGE_GUI_LOCATION, 176, 14, 16, 30).buildAnimated(200, - IDrawableAnimated.StartDirection.TOP, false); - } - - @Override - public ResourceLocation getUid() { - return uid; - } - - @Override - public String getTitle() { - return I18n.get(forgeIcon.getDescriptionId()); - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public IDrawable getBackground() { - return background; - } - - @Override - @SuppressWarnings("unchecked") - public Class> getRecipeClass() { - return (Class>) (Class) IRecipe.class; - } - - @Override - public void setIngredients(IRecipe recipe, IIngredients ingreds) { - ingreds.setInputIngredients(recipe.getIngredients()); - ingreds.setOutput(VanillaTypes.ITEM, recipe.getResultItem()); - } - - @Override - public void setRecipe(IRecipeLayout layout, IRecipe recipe, IIngredients ingreds) { - IGuiItemStackGroup guiItemStacks = layout.getItemStacks(); - - for (int i = 0; i < 4; i++) { - guiItemStacks.init(i, true, 7 + 18 * i, 18); - guiItemStacks.set(i, ingreds.getInputs(VanillaTypes.ITEM).get(0)); - } - - // Alloy items are not required - if (ingreds.getInputs(VanillaTypes.ITEM).size() > 1) { - for (int i = 0; i < 4; i++) { - guiItemStacks.init(i + 4, true, 7 + 18 * i, 0); - guiItemStacks.set(i + 4, ingreds.getInputs(VanillaTypes.ITEM).get(1)); - } - } - - for (int i = 0; i < 4; i++) { - guiItemStacks.init(i + 8, false, 7 + 18 * i, 64); - guiItemStacks.set(i + 8, ingreds.getOutputs(VanillaTypes.ITEM).get(0)); - } - } - - @Override - public void draw(IRecipe recipe, MatrixStack matrixStack, double mouseX, double mouseY) { - animatedFlame.draw(matrixStack, 35, 92); - arrow.draw(matrixStack, 35, 38); - - float experience = 0f; - - if (recipe instanceof AbstractCookingRecipe) { - experience = ((AbstractCookingRecipe) recipe).getExperience(); - } else if (recipe instanceof AbstractAlloyForgeRecipe) { - experience = ((AbstractAlloyForgeRecipe) recipe).getExperience(); - } - - if (experience > 0.0f) { - String experienceString = Translator.translateToLocalFormatted("gui.jei.category.smelting.experience", - new Object[] { Float.valueOf(experience) }); - Minecraft minecraft = Minecraft.getInstance(); - FontRenderer fontRenderer = minecraft.font; - int stringWidth = fontRenderer.width(experienceString); - fontRenderer.draw(matrixStack, experienceString, background.getWidth() - stringWidth, 43.0f, -8355712); - } - } +public class AlloyForge extends FurnaceVariantCategory> +{ + + private final ResourceLocation uid; + private final ItemStack forgeIcon; + private final IDrawable icon; + private final IDrawable background; + private final IDrawable arrow; + + public static final ResourceLocation ALLOY_FORGE_GUI_LOCATION = new ResourceLocation ( + "lotr:textures/gui/alloy_forge.png"); + + public AlloyForge (ResourceLocation uid, ItemStack forgeIcon, IGuiHelper guiHelper) + { + super (guiHelper); + this.uid = uid; + this.forgeIcon = forgeIcon; + this.icon = guiHelper.createDrawableIngredient (forgeIcon); + this.background = guiHelper.createDrawable (ALLOY_FORGE_GUI_LOCATION, 45, 20, 85, 130); + this.arrow = guiHelper.drawableBuilder (ALLOY_FORGE_GUI_LOCATION, 176, 14, 16, 30).buildAnimated (200, + IDrawableAnimated.StartDirection.TOP, false); + } + + @Override + public ResourceLocation getUid () + { + return uid; + } + + @Override + public String getTitle () + { + return I18n.format (forgeIcon.getTranslationKey ()); + } + + @Override + public IDrawable getIcon () + { + return icon; + } + + @Override + public IDrawable getBackground () + { + return background; + } + + @Override + @SuppressWarnings("unchecked") + public Class> getRecipeClass () + { + return (Class>) (Class) IRecipe.class; + } + + @Override + public void setIngredients (IRecipe recipe, IIngredients ingreds) + { + ingreds.setInputIngredients (recipe.getIngredients ()); + ingreds.setOutput (VanillaTypes.ITEM, recipe.getRecipeOutput ()); + } + + @Override + public void setRecipe (IRecipeLayout layout, IRecipe recipe, IIngredients ingreds) + { + IGuiItemStackGroup guiItemStacks = layout.getItemStacks (); + + for (int i = 0; i < 4; i++) + { + guiItemStacks.init (i, true, 7 + 18 * i, 18); + guiItemStacks.set (i, ingreds.getInputs (VanillaTypes.ITEM).get (0)); + } + + // Alloy items are not required + if (ingreds.getInputs (VanillaTypes.ITEM).size () > 1) + { + for (int i = 0; i < 4; i++) + { + guiItemStacks.init (i + 4, true, 7 + 18 * i, 0); + guiItemStacks.set (i + 4, ingreds.getInputs (VanillaTypes.ITEM).get (1)); + } + } + + for (int i = 0; i < 4; i++) + { + guiItemStacks.init (i + 8, false, 7 + 18 * i, 64); + guiItemStacks.set (i + 8, ingreds.getOutputs (VanillaTypes.ITEM).get (0)); + } + } + + @Override + public void draw (IRecipe recipe, MatrixStack matrixStack, double mouseX, double mouseY) + { + animatedFlame.draw (matrixStack, 35, 92); + arrow.draw (matrixStack, 35, 38); + + float experience = 0f; + + if (recipe instanceof AbstractCookingRecipe) + { + experience = ((AbstractCookingRecipe) recipe).getExperience (); + } + else if (recipe instanceof AbstractAlloyForgeRecipe) + { + experience = ((AbstractAlloyForgeRecipe) recipe).getExperience (); + } + + if (experience > 0.0f) + { + String experienceString = Translator.translateToLocalFormatted ("gui.jei.category.smelting.experience", + new Object[] + {Float.valueOf (experience)}); + Minecraft minecraft = Minecraft.getInstance (); + FontRenderer fontRenderer = minecraft.fontRenderer; + int stringWidth = fontRenderer.getStringWidth (experienceString); + fontRenderer.drawString (matrixStack, experienceString, background.getWidth () - stringWidth, 43.0f, + -8355712); + } + } } diff --git a/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java b/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java index a24ad18..360da98 100644 --- a/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java +++ b/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java @@ -17,65 +17,67 @@ package craftedMods.jeiLotr; -import lotr.common.recipe.LOTRShapedRecipe; -import lotr.common.recipe.LOTRShapelessRecipe; +import lotr.common.recipe.*; import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.helpers.IGuiHelper; -import mezz.jei.api.helpers.IModIdHelper; -import mezz.jei.plugins.vanilla.crafting.CraftingCategoryExtension; -import mezz.jei.plugins.vanilla.crafting.CraftingRecipeCategory; +import mezz.jei.api.helpers.*; +import mezz.jei.plugins.vanilla.crafting.*; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.ICraftingRecipe; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TranslationTextComponent; -public class FactionCraftingTable extends CraftingRecipeCategory { +public class FactionCraftingTable extends CraftingRecipeCategory +{ - private final ResourceLocation uid; - private final ItemStack ctIcon; - private final IDrawable icon; - - private ITextComponent titleTextComponent; + private final ResourceLocation uid; + private final ItemStack ctIcon; + private final IDrawable icon; - public FactionCraftingTable(ResourceLocation uid, ItemStack ctIcon, IGuiHelper guiHelper, - IModIdHelper modIdHelper) { - super(guiHelper); + private ITextComponent titleTextComponent; - this.uid = uid; - this.ctIcon = ctIcon; - this.icon = guiHelper.createDrawableIngredient(ctIcon); + public FactionCraftingTable (ResourceLocation uid, ItemStack ctIcon, IGuiHelper guiHelper, IModIdHelper modIdHelper) + { + super (guiHelper); - this.addCategoryExtension(LOTRShapedRecipe.class, CraftingCategoryExtension::new); - this.addCategoryExtension(LOTRShapelessRecipe.class, CraftingCategoryExtension::new); - - this.titleTextComponent = new TranslationTextComponent(I18n.get(ctIcon.getDescriptionId())); - } + this.uid = uid; + this.ctIcon = ctIcon; + this.icon = guiHelper.createDrawableIngredient (ctIcon); - @Override - public ResourceLocation getUid() { - return uid; - } + this.addCategoryExtension (FactionShapedRecipe.class, CraftingCategoryExtension::new); + this.addCategoryExtension (FactionShapelessRecipe.class, CraftingCategoryExtension::new); - @Override - public Class getRecipeClass() { - return ICraftingRecipe.class; - } + this.titleTextComponent = ctIcon.getDisplayName (); + } - @Override - public String getTitle() { - return I18n.get(ctIcon.getDescriptionId()); - } - - @Override - public ITextComponent getTitleAsTextComponent() { - return this.titleTextComponent; - } + @Override + public ResourceLocation getUid () + { + return uid; + } - @Override - public IDrawable getIcon() { - return icon; - } + @Override + public Class getRecipeClass () + { + return ICraftingRecipe.class; + } + + @Override + public String getTitle () + { + return I18n.format (ctIcon.getTranslationKey ()); + } + + @Override + public ITextComponent getTitleAsTextComponent () + { + return this.titleTextComponent; + } + + @Override + public IDrawable getIcon () + { + return icon; + } } diff --git a/src/main/java/craftedMods/jeiLotr/JEILotr.java b/src/main/java/craftedMods/jeiLotr/JEILotr.java index 6cde723..f42b447 100644 --- a/src/main/java/craftedMods/jeiLotr/JEILotr.java +++ b/src/main/java/craftedMods/jeiLotr/JEILotr.java @@ -35,40 +35,50 @@ import net.minecraftforge.fml.loading.FMLEnvironment; @Mod("jeilotr") -public class JEILotr { - private static int ALLOY_FORGE_RECIPE_VERSION = 3; +public class JEILotr +{ + private static int ALLOY_FORGE_RECIPE_VERSION = 3; - public static final Logger LOGGER = LogManager.getLogger(); + public static final Logger LOGGER = LogManager.getLogger (); - public JEILotr() { - if (FMLEnvironment.dist == Dist.CLIENT) { - FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup); + public JEILotr () + { + if (FMLEnvironment.dist == Dist.CLIENT) + { + FMLJavaModLoadingContext.get ().getModEventBus ().addListener (this::setup); - MinecraftForge.EVENT_BUS.register(this); - } else { - LOGGER.warn("JEI LOTR was loaded on a server - it doesn't do anyting there and may cause crashes"); - } - } + MinecraftForge.EVENT_BUS.register (this); + } + else + { + LOGGER.warn ("JEI LOTR was loaded on a server - it doesn't do anything there and may cause crashes"); + } + } - private void setup(final FMLCommonSetupEvent event) { - if (ALLOY_FORGE_RECIPE_VERSION != AbstractAlloyForgeTileEntity.RECIPE_FUNCTIONALITY_VERSION_FOR_JEI) { - LOGGER.warn( - "The supported alloy forge recipe version differs from the one in the current LOTR Mod version - the alloy forge recipe handlers could show wrong recipes."); - } - } + private void setup (final FMLCommonSetupEvent event) + { + if (ALLOY_FORGE_RECIPE_VERSION != AbstractAlloyForgeTileEntity.RECIPE_FUNCTIONALITY_VERSION_FOR_JEI) + { + LOGGER.warn ( + "The supported alloy forge recipe version differs from the one in the current LOTR Mod version - the alloy forge recipe handlers could show wrong recipes."); + } + } - @SubscribeEvent - public void login(EntityJoinWorldEvent event) { - if (event.getEntity() instanceof ClientPlayerEntity) { - VersionChecker.CheckResult result = VersionChecker - .getResult(ModList.get().getModContainerById("jeilotr").get().getModInfo()); - if (result != null && (result.status == VersionChecker.Status.OUTDATED - || result.status == VersionChecker.Status.BETA_OUTDATED)) { - ((ClientPlayerEntity) event.getEntity()).sendMessage( - new StringTextComponent( - "\u00A73[JEI LOTR]:\u00A7r A new version (" + result.target.toString() + ") was found"), - event.getEntity().getUUID()); - } - } - } + @SubscribeEvent + public void login (EntityJoinWorldEvent event) + { + if (event.getEntity () instanceof ClientPlayerEntity) + { + VersionChecker.CheckResult result = VersionChecker + .getResult (ModList.get ().getModContainerById ("jeilotr").get ().getModInfo ()); + if (result != null && (result.status == VersionChecker.Status.OUTDATED + || result.status == VersionChecker.Status.BETA_OUTDATED)) + { + ((ClientPlayerEntity) event.getEntity ()).sendMessage ( + new StringTextComponent ( + "\u00A73[JEI LOTR]:\u00A7r A new version (" + result.target.toString () + ") was found"), + event.getEntity ().getUniqueID ()); + } + } + } } diff --git a/src/main/java/craftedMods/jeiLotr/JEIPlugin.java b/src/main/java/craftedMods/jeiLotr/JEIPlugin.java index db22344..1079d8a 100644 --- a/src/main/java/craftedMods/jeiLotr/JEIPlugin.java +++ b/src/main/java/craftedMods/jeiLotr/JEIPlugin.java @@ -17,473 +17,531 @@ package craftedMods.jeiLotr; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; +import java.lang.reflect.*; +import java.util.*; import java.util.function.BiFunction; import java.util.stream.Collectors; -import lotr.client.gui.inv.AlloyForgeScreen; -import lotr.client.gui.inv.FactionCraftingScreen; -import lotr.client.gui.inv.KegScreen; -import lotr.common.init.LOTRBlocks; -import lotr.common.init.LOTRContainers; -import lotr.common.inv.AbstractAlloyForgeContainer; -import lotr.common.inv.AlloyForgeContainer; -import lotr.common.inv.FactionCraftingContainer; -import lotr.common.inv.KegContainer; -import lotr.common.recipe.AbstractAlloyForgeRecipe; -import lotr.common.recipe.FactionTableType; -import lotr.common.recipe.LOTRRecipes; -import lotr.common.tileentity.AbstractAlloyForgeTileEntity; -import lotr.common.tileentity.AlloyForgeTileEntity; -import lotr.common.tileentity.DwarvenForgeTileEntity; -import lotr.common.tileentity.ElvenForgeTileEntity; -import lotr.common.tileentity.HobbitOvenTileEntity; -import lotr.common.tileentity.OrcForgeTileEntity; -import mezz.jei.api.IModPlugin; -import mezz.jei.api.JeiPlugin; +import lotr.client.gui.inv.*; +import lotr.common.init.*; +import lotr.common.inv.*; +import lotr.common.recipe.*; +import lotr.common.tileentity.*; +import mezz.jei.api.*; import mezz.jei.api.constants.VanillaRecipeCategoryUid; -import mezz.jei.api.gui.handlers.IGuiClickableArea; -import mezz.jei.api.gui.handlers.IGuiContainerHandler; -import mezz.jei.api.helpers.IGuiHelper; -import mezz.jei.api.helpers.IModIdHelper; +import mezz.jei.api.gui.handlers.*; +import mezz.jei.api.helpers.*; import mezz.jei.api.recipe.category.IRecipeCategory; -import mezz.jei.api.registration.IGuiHandlerRegistration; -import mezz.jei.api.registration.IRecipeCatalystRegistration; -import mezz.jei.api.registration.IRecipeCategoryRegistration; -import mezz.jei.api.registration.IRecipeRegistration; -import mezz.jei.api.registration.IRecipeTransferRegistration; +import mezz.jei.api.registration.*; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.inventory.Inventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.AbstractCookingRecipe; -import net.minecraft.item.crafting.IRecipe; -import net.minecraft.item.crafting.IRecipeType; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.RecipeManager; +import net.minecraft.item.crafting.*; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.vector.Vector4f; -import net.minecraftforge.fml.RegistryObject; +import net.minecraftforge.fml.*; @JeiPlugin -public class JEIPlugin implements IModPlugin { - - private static Method getRecipesMethod; - private static Field theForgeField; - - static { - try { - try { - getRecipesMethod = RecipeManager.class.getDeclaredMethod("byType", IRecipeType.class); - } catch (NoSuchMethodException e) { - // Trying the obfuscated version - getRecipesMethod = RecipeManager.class.getDeclaredMethod("func_215366_a", IRecipeType.class); - } - getRecipesMethod.setAccessible(true); - } catch (Exception e) { - getRecipesMethod = null; - e.printStackTrace(); - } - - try { - theForgeField = AbstractAlloyForgeContainer.class.getDeclaredField("theForge"); - theForgeField.setAccessible(true); - } catch (Exception e) { - theForgeField = null; - e.printStackTrace(); - } - } - - private Collection devices; - private Map devicesByBlock; - - @Override - public ResourceLocation getPluginUid() { - return new ResourceLocation("crafted_mods", "jei_lotr"); - } - - @SuppressWarnings("unchecked") - public void initDevices() { - if (devices == null) { - devices = new HashSet<>(); - devicesByBlock = new HashMap<>(); - - 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()); - - RegistryObject> container = null; - - try { - Field containerField = LOTRContainers.class.getDeclaredField(field.getName()); - container = (RegistryObject>) containerField - .get(null); - } catch (NoSuchFieldException e) { - JEILotr.LOGGER.warn("No container field named \"" + field.getName() + "\" was found"); - } - - LOTRCraftingTable device = new LOTRCraftingTable( - new ResourceLocation("lotr", type.recipeID.split(":")[1]), type.getIcon(), types, - container); - - devices.add(device); - devicesByBlock.put(Block.byItem(type.getIcon().getItem()), device); - } - } - JEILotr.LOGGER.debug("Found " + devices.size() + " faction crafting tables"); - } catch (Exception e) { - JEILotr.LOGGER - .error("Couldn't instantiate the faction crafting tables from the LOTRRecipes type fields", e); - } - - LOTRAlloyForge dwarvenForgeDevice = new LOTRAlloyForge(new ResourceLocation("lotr", "dwarven_forge"), - new ItemStack(LOTRBlocks.DWARVEN_FORGE.get()), Arrays.asList(IRecipeType.SMELTING, - LOTRRecipes.DWARVEN_FORGE, LOTRRecipes.ALLOY_FORGE, LOTRRecipes.DWARVEN_FORGE_ALLOY), - new DwarvenForgeTileEntity()); - LOTRAlloyForge orcForgeDevice = new LOTRAlloyForge(new ResourceLocation("lotr", "orc_forge"), - new ItemStack(LOTRBlocks.ORC_FORGE.get()), Arrays.asList(IRecipeType.SMELTING, - LOTRRecipes.ORC_FORGE, LOTRRecipes.ALLOY_FORGE, LOTRRecipes.ORC_FORGE_ALLOY), - new OrcForgeTileEntity()); - LOTRAlloyForge elvenForgeDevice = new LOTRAlloyForge(new ResourceLocation("lotr", "elven_forge"), - new ItemStack(LOTRBlocks.ELVEN_FORGE.get()), Arrays.asList(IRecipeType.SMELTING, - LOTRRecipes.ELVEN_FORGE, LOTRRecipes.ALLOY_FORGE, LOTRRecipes.ELVEN_FORGE_ALLOY), - new ElvenForgeTileEntity()); - LOTRAlloyForge alloyForgeDevice = new LOTRAlloyForge(new ResourceLocation("lotr", "alloy_forge"), - new ItemStack(LOTRBlocks.ALLOY_FORGE.get()), - Arrays.asList(LOTRRecipes.ALLOY_FORGE, IRecipeType.SMELTING), new AlloyForgeTileEntity()); - LOTRAlloyForge hobbitOvenDevice = new LOTRAlloyForge(new ResourceLocation("lotr", "hobbit_oven"), - new ItemStack(LOTRBlocks.HOBBIT_OVEN.get()), - Arrays.asList(LOTRRecipes.HOBBIT_OVEN, LOTRRecipes.HOBBIT_OVEN_ALLOY, IRecipeType.SMELTING), - new HobbitOvenTileEntity()); - - devices.add(dwarvenForgeDevice); - devices.add(orcForgeDevice); - devices.add(elvenForgeDevice); - devices.add(alloyForgeDevice); - devices.add(hobbitOvenDevice); - - devicesByBlock.put(Block.byItem(dwarvenForgeDevice.icon.getItem()), dwarvenForgeDevice); - devicesByBlock.put(Block.byItem(orcForgeDevice.icon.getItem()), orcForgeDevice); - devicesByBlock.put(Block.byItem(elvenForgeDevice.icon.getItem()), elvenForgeDevice); - devicesByBlock.put(Block.byItem(alloyForgeDevice.icon.getItem()), alloyForgeDevice); - devicesByBlock.put(Block.byItem(hobbitOvenDevice.icon.getItem()), hobbitOvenDevice); - - LOTRKeg keg = new LOTRKeg(new ResourceLocation("lotr", "keg"), new ItemStack(LOTRBlocks.KEG.get()), - Arrays.asList(LOTRRecipes.DRINK_BREWING)); - - devices.add(keg); - } - } - - @Override - public void registerRecipeCatalysts(IRecipeCatalystRegistration registration) { - initDevices(); - devices.forEach(device -> registration.addRecipeCatalyst(device.icon.copy(), device.uid)); - - registration.addRecipeCatalyst(new ItemStack(LOTRBlocks.DWARVEN_FORGE.get()), VanillaRecipeCategoryUid.FUEL); - registration.addRecipeCatalyst(new ItemStack(LOTRBlocks.ORC_FORGE.get()), VanillaRecipeCategoryUid.FUEL); - registration.addRecipeCatalyst(new ItemStack(LOTRBlocks.ELVEN_FORGE.get()), VanillaRecipeCategoryUid.FUEL); - registration.addRecipeCatalyst(new ItemStack(LOTRBlocks.ALLOY_FORGE.get()), VanillaRecipeCategoryUid.FUEL); - registration.addRecipeCatalyst(new ItemStack(LOTRBlocks.HOBBIT_OVEN.get()), VanillaRecipeCategoryUid.FUEL); - } - - @Override - public void registerCategories(IRecipeCategoryRegistration registration) { - initDevices(); - devices.forEach(device -> { - registration.addRecipeCategories(device.createCategoryInstance(registration.getJeiHelpers().getGuiHelper(), - registration.getJeiHelpers().getModIdHelper())); - }); - } - - @Override - public void registerRecipes(IRecipeRegistration registration) { - initDevices(); - devices.forEach(device -> registration.addRecipes(getRecipesOfTypes(device), device.uid)); - } - - @SuppressWarnings("unchecked") - private Collection> getRecipesOfTypes(LOTRDevice device) { - Collection> recipes = new ArrayList<>(); - if (getRecipesMethod != null) { - try { - - Minecraft minecraft = Minecraft.getInstance(); - - for (IRecipeType type : device.recipeTypes) { - recipes.addAll(((Map>) getRecipesMethod - .invoke(minecraft.level.getRecipeManager(), type)).values().stream() - .filter(device::isRecipeValid).collect(Collectors.toList())); - } - } catch (Exception e) { - JEILotr.LOGGER.error("Couldn't get the recipes of the specified type", e); - } - } - return recipes; - } - - @Override - public void registerGuiHandlers(IGuiHandlerRegistration registration) { - initDevices(); - - registration.addRecipeClickArea(KegScreen.class, 71, 48, 28, 23, new ResourceLocation("lotr", "keg")); - - registration.addGuiContainerHandler(FactionCraftingScreen.class, - new IGuiContainerHandler() { - - @Override - public Collection getGuiClickableAreas(FactionCraftingScreen containerScreen, - double mouseX, double mouseY) { - ResourceLocation uid = containerScreen.getMenu().isStandardCraftingActive() - ? VanillaRecipeCategoryUid.CRAFTING - : devicesByBlock.get(containerScreen.getMenu().getCraftingBlock()).uid; - - IGuiClickableArea clickableArea = IGuiClickableArea.createBasic(88, 32, 28, 23, uid); - return Collections.singleton(clickableArea); - } - }); - - if (theForgeField != null) { - registration.addGuiContainerHandler(AlloyForgeScreen.class, new IGuiContainerHandler() { - - @Override - public Collection getGuiClickableAreas(AlloyForgeScreen containerScreen, - double mouseX, double mouseY) { - AbstractAlloyForgeTileEntity forge = null; - try { - forge = (AbstractAlloyForgeTileEntity) theForgeField.get(containerScreen.getMenu()); - } catch (Exception e) { - JEILotr.LOGGER.error("Couldn't get the alloy forge tile entity from the container", e); - } - - if (forge != null) { - IGuiClickableArea clickableArea = IGuiClickableArea.createBasic(77, 55, 22, 30, - devicesByBlock.get(forge.getBlockState().getBlock()).uid); - return Collections.singleton(clickableArea); - } - - return new HashSet<>(); - } - }); - } - } - - @Override - public void registerRecipeTransferHandlers(IRecipeTransferRegistration registration) { - initDevices(); // TODO implement - - devices.forEach(device -> device.registerTransferHandlers(registration)); - } - - private class LOTRKeg extends LOTRDevice { - - public LOTRKeg(ResourceLocation uid, ItemStack icon, Collection> recipeTypes) { - super(uid, icon, recipeTypes); - } - - @Override - public IRecipeCategory createCategoryInstance(IGuiHelper guiHelper, IModIdHelper modIdHelper) { - return new Keg(uid, icon, guiHelper); - } - - @Override - public void registerTransferHandlers(IRecipeTransferRegistration registration) { - super.registerTransferHandlers(registration); - - registration.addRecipeTransferHandler(KegContainer.class, uid, 0, 9, 10, 36); - } - - } - - private class LOTRAlloyForge extends LOTRDevice { - - protected final AbstractAlloyForgeTileEntity forge; - - @SuppressWarnings("resource") - public LOTRAlloyForge(ResourceLocation uid, ItemStack icon, Collection> recipeTypes, - AbstractAlloyForgeTileEntity forge) { - super(uid, icon, recipeTypes); - this.forge = forge; - this.forge.setLevelAndPosition(Minecraft.getInstance().level, BlockPos.ZERO); - } - - @Override - public IRecipeCategory createCategoryInstance(IGuiHelper guiHelper, IModIdHelper modIdHelper) { - return new AlloyForge(uid, icon, guiHelper); - } - - @Override - public boolean isRecipeValid(IRecipe recipe) { - if (recipe instanceof AbstractAlloyForgeRecipe) { - AbstractAlloyForgeRecipe alloyRecipe = (AbstractAlloyForgeRecipe) recipe; - return isRecipeValid(alloyRecipe.getIngredients().get(0), alloyRecipe.getIngredients().get(1), - (alloy, ingred) -> { - Inventory testInv = new Inventory(2); - testInv.setItem(0, ingred); - testInv.setItem(1, alloy); - return alloyRecipe.assemble(testInv); - }); - } else if (recipe instanceof AbstractCookingRecipe) { - AbstractCookingRecipe cookingRecipe = (AbstractCookingRecipe) recipe; - return isRecipeValid(cookingRecipe.getIngredients().get(0), Ingredient.EMPTY, (alloy, ingred) -> { - Inventory testInv = new Inventory(1); - testInv.setItem(0, ingred); - return cookingRecipe.assemble(testInv); - }); - } - - return true; - } - - private boolean isRecipeValid(Ingredient ingredientItem, Ingredient alloyItem, - BiFunction resultFunction) { - ItemStack[] ingredientStacks = ingredientItem.getItems(); - ItemStack[] alloyStacks = alloyItem == Ingredient.EMPTY ? new ItemStack[] { ItemStack.EMPTY } - : alloyItem.getItems(); - - for (ItemStack ingredient : ingredientStacks) { - for (ItemStack alloy : alloyStacks) { - ItemStack result = forge.getSmeltingResult(ingredient, alloy); - if (result == ItemStack.EMPTY || !result.equals(resultFunction.apply(ingredient, alloy), false)) - return false; // Invalid recipe - } - } - - return true; - } - - @Override - public void registerTransferHandlers(IRecipeTransferRegistration registration) { - super.registerTransferHandlers(registration); - - registration.addRecipeTransferHandler(AlloyForgeContainer.class, uid, 0, 8, 13, 36); - } - - } - - private class LOTRCraftingTable extends LOTRDevice { - - private final RegistryObject> container; - - public LOTRCraftingTable(ResourceLocation uid, ItemStack icon, Collection> recipeTypes, - RegistryObject> container) { - super(uid, icon, recipeTypes); - this.container = container; - } - - @Override - public IRecipeCategory createCategoryInstance(IGuiHelper guiHelper, IModIdHelper modIdHelper) { - return new FactionCraftingTable(uid, icon, guiHelper, modIdHelper); - } - - @SuppressWarnings("resource") - @Override - public void registerTransferHandlers(IRecipeTransferRegistration registration) { - super.registerTransferHandlers(registration); - - registration.addRecipeTransferHandler( - container.get().create(0, Minecraft.getInstance().player.inventory).getClass(), uid, 1, 9, 10, 36); - registration.addRecipeTransferHandler( - container.get().create(0, Minecraft.getInstance().player.inventory).getClass(), - VanillaRecipeCategoryUid.CRAFTING, 1, 9, 10, 36); - } - - } - - private abstract class LOTRDevice { - protected ResourceLocation uid; - protected ItemStack icon; - protected Collection> recipeTypes; - protected Class guiClass; - protected Vector4f guiHandlerArea; - - public LOTRDevice(ResourceLocation uid, ItemStack icon, Collection> recipeTypes) { - this.uid = uid; - this.icon = icon; - this.recipeTypes = recipeTypes; - } - - public abstract IRecipeCategory createCategoryInstance(IGuiHelper guiHelper, IModIdHelper modIdHelper); - - public boolean isRecipeValid(IRecipe recipe) { - return true; - } - - public void registerTransferHandlers(IRecipeTransferRegistration registration) { - - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + getOuterType().hashCode(); - result = prime * result + (icon == null ? 0 : icon.hashCode()); - result = prime * result + (guiClass == null ? 0 : guiClass.hashCode()); - result = prime * result + (guiHandlerArea == null ? 0 : guiHandlerArea.hashCode()); - result = prime * result + (recipeTypes == null ? 0 : recipeTypes.hashCode()); - result = prime * result + (uid == null ? 0 : uid.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - LOTRDevice other = (LOTRDevice) obj; - if (!getOuterType().equals(other.getOuterType())) - return false; - if (icon == null) { - if (other.icon != null) - return false; - } else if (!icon.equals(other.icon)) - return false; - if (guiClass == null) { - if (other.guiClass != null) - return false; - } else if (!guiClass.equals(other.guiClass)) - return false; - if (guiHandlerArea == null) { - if (other.guiHandlerArea != null) - return false; - } else if (!guiHandlerArea.equals(other.guiHandlerArea)) - return false; - if (recipeTypes == null) { - if (other.recipeTypes != null) - return false; - } else if (!recipeTypes.equals(other.recipeTypes)) - return false; - if (uid == null) { - if (other.uid != null) - return false; - } else if (!uid.equals(other.uid)) - return false; - return true; - } - - private JEIPlugin getOuterType() { - return JEIPlugin.this; - } - - } +public class JEIPlugin implements IModPlugin +{ + + private static Method getRecipesMethod; + private static Field theForgeField; + + static + { + try + { + try + { + getRecipesMethod = RecipeManager.class.getDeclaredMethod ("getRecipes", IRecipeType.class); + } + catch (NoSuchMethodException e) + { + // Trying the obfuscated version + getRecipesMethod = RecipeManager.class.getDeclaredMethod ("func_215366_a", IRecipeType.class); + } + getRecipesMethod.setAccessible (true); + } + catch (Exception e) + { + getRecipesMethod = null; + e.printStackTrace (); + } + + try + { + theForgeField = AbstractAlloyForgeContainer.class.getDeclaredField ("theForge"); + theForgeField.setAccessible (true); + } + catch (Exception e) + { + theForgeField = null; + e.printStackTrace (); + } + } + + private Collection devices; + private Map devicesByBlock; + + @Override + public ResourceLocation getPluginUid () + { + return new ResourceLocation ("crafted_mods", "jei_lotr"); + } + + public void initDevices () + { + if (devices == null) + { + devices = new HashSet<> (); + devicesByBlock = new HashMap<> (); + + scanFields (LOTRRecipes.class.getName (), LOTRContainers.class.getName (), "lotr"); + + if (ModList.get ().isLoaded ("lotrfa")) + { + scanFields ("eoa.lotrfa.common.recipe.LOTRFARecipes", "eoa.lotrfa.common.init.LOTRFAContainers", + "lotrfa"); + } + + LOTRAlloyForge dwarvenForgeDevice = new LOTRAlloyForge (new ResourceLocation ("lotr", "dwarven_forge"), + new ItemStack (LOTRBlocks.DWARVEN_FORGE.get ()), Arrays.asList (IRecipeType.SMELTING, + LOTRRecipes.DWARVEN_FORGE, LOTRRecipes.ALLOY_FORGE, LOTRRecipes.DWARVEN_FORGE_ALLOY), + new DwarvenForgeTileEntity ()); + LOTRAlloyForge orcForgeDevice = new LOTRAlloyForge (new ResourceLocation ("lotr", "orc_forge"), + new ItemStack (LOTRBlocks.ORC_FORGE.get ()), Arrays.asList (IRecipeType.SMELTING, LOTRRecipes.ORC_FORGE, + LOTRRecipes.ALLOY_FORGE, LOTRRecipes.ORC_FORGE_ALLOY), + new OrcForgeTileEntity ()); + LOTRAlloyForge elvenForgeDevice = new LOTRAlloyForge (new ResourceLocation ("lotr", "elven_forge"), + new ItemStack (LOTRBlocks.ELVEN_FORGE.get ()), Arrays.asList (IRecipeType.SMELTING, + LOTRRecipes.ELVEN_FORGE, LOTRRecipes.ALLOY_FORGE, LOTRRecipes.ELVEN_FORGE_ALLOY), + new ElvenForgeTileEntity ()); + LOTRAlloyForge alloyForgeDevice = new LOTRAlloyForge (new ResourceLocation ("lotr", "alloy_forge"), + new ItemStack (LOTRBlocks.ALLOY_FORGE.get ()), + Arrays.asList (LOTRRecipes.ALLOY_FORGE, IRecipeType.SMELTING), new AlloyForgeTileEntity ()); + LOTRAlloyForge hobbitOvenDevice = new LOTRAlloyForge (new ResourceLocation ("lotr", "hobbit_oven"), + new ItemStack (LOTRBlocks.HOBBIT_OVEN.get ()), + Arrays.asList (LOTRRecipes.HOBBIT_OVEN, LOTRRecipes.HOBBIT_OVEN_ALLOY, IRecipeType.SMELTING), + new HobbitOvenTileEntity ()); + + devices.add (dwarvenForgeDevice); + devices.add (orcForgeDevice); + devices.add (elvenForgeDevice); + devices.add (alloyForgeDevice); + devices.add (hobbitOvenDevice); + + devicesByBlock.put (Block.getBlockFromItem (dwarvenForgeDevice.icon.getItem ()), dwarvenForgeDevice); + devicesByBlock.put (Block.getBlockFromItem (orcForgeDevice.icon.getItem ()), orcForgeDevice); + devicesByBlock.put (Block.getBlockFromItem (elvenForgeDevice.icon.getItem ()), elvenForgeDevice); + devicesByBlock.put (Block.getBlockFromItem (alloyForgeDevice.icon.getItem ()), alloyForgeDevice); + devicesByBlock.put (Block.getBlockFromItem (hobbitOvenDevice.icon.getItem ()), hobbitOvenDevice); + + LOTRKeg keg = new LOTRKeg (new ResourceLocation ("lotr", "keg"), new ItemStack (LOTRBlocks.KEG.get ()), + Arrays.asList (LOTRRecipes.DRINK_BREWING)); + + devices.add (keg); + } + } + + @SuppressWarnings("unchecked") + private void scanFields (String recipeClass, String containerclass, String modid) + { + try + { + for (Field field : Class.forName (recipeClass).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 ()); + + RegistryObject> container = null; + + try + { + Field containerField = Class.forName (containerclass).getDeclaredField (field.getName ()); + container = (RegistryObject>) containerField.get (null); + } + catch (NoSuchFieldException e) + { + JEILotr.LOGGER.warn ("No container field named \"" + field.getName () + "\" was found"); + } + + LOTRCraftingTable device = new LOTRCraftingTable ( + new ResourceLocation (modid, type.recipeID.split (":")[1]), type.getIcon (), types, container); + + devices.add (device); + devicesByBlock.put (Block.getBlockFromItem (type.getIcon ().getItem ()), device); + } + } + JEILotr.LOGGER.debug ("Found " + devices.size () + " faction crafting tables for " + modid); + } + catch (Exception e) + { + JEILotr.LOGGER.error ("Couldn't instantiate the faction crafting tables for " + modid, e); + } + } + + @Override + public void registerRecipeCatalysts (IRecipeCatalystRegistration registration) + { + initDevices (); + devices.forEach (device -> registration.addRecipeCatalyst (device.icon.copy (), device.uid)); + + registration.addRecipeCatalyst (new ItemStack (LOTRBlocks.DWARVEN_FORGE.get ()), VanillaRecipeCategoryUid.FUEL); + registration.addRecipeCatalyst (new ItemStack (LOTRBlocks.ORC_FORGE.get ()), VanillaRecipeCategoryUid.FUEL); + registration.addRecipeCatalyst (new ItemStack (LOTRBlocks.ELVEN_FORGE.get ()), VanillaRecipeCategoryUid.FUEL); + registration.addRecipeCatalyst (new ItemStack (LOTRBlocks.ALLOY_FORGE.get ()), VanillaRecipeCategoryUid.FUEL); + registration.addRecipeCatalyst (new ItemStack (LOTRBlocks.HOBBIT_OVEN.get ()), VanillaRecipeCategoryUid.FUEL); + } + + @Override + public void registerCategories (IRecipeCategoryRegistration registration) + { + initDevices (); + devices.forEach (device -> + { + registration.addRecipeCategories (device.createCategoryInstance ( + registration.getJeiHelpers ().getGuiHelper (), registration.getJeiHelpers ().getModIdHelper ())); + }); + } + + @Override + public void registerRecipes (IRecipeRegistration registration) + { + initDevices (); + devices.forEach (device -> registration.addRecipes (getRecipesOfTypes (device), device.uid)); + } + + @SuppressWarnings("unchecked") + private Collection> getRecipesOfTypes (LOTRDevice device) + { + Collection> recipes = new ArrayList<> (); + if (getRecipesMethod != null) + { + try + { + + Minecraft minecraft = Minecraft.getInstance (); + + for (IRecipeType type : device.recipeTypes) + { + recipes.addAll ( ((Map>) getRecipesMethod + .invoke (minecraft.world.getRecipeManager (), type)).values ().stream () + .filter (device::isRecipeValid).collect (Collectors.toList ())); + } + } + catch (Exception e) + { + JEILotr.LOGGER.error ("Couldn't get the recipes of the specified type", e); + } + } + return recipes; + } + + @Override + public void registerGuiHandlers (IGuiHandlerRegistration registration) + { + initDevices (); + + registration.addRecipeClickArea (KegScreen.class, 71, 48, 28, 23, new ResourceLocation ("lotr", "keg")); + + registration.addGuiContainerHandler (FactionCraftingScreen.class, + new IGuiContainerHandler () + { + + @Override + public Collection getGuiClickableAreas (FactionCraftingScreen containerScreen, + double mouseX, double mouseY) + { + ResourceLocation uid = containerScreen.getContainer ().isStandardCraftingActive () + ? VanillaRecipeCategoryUid.CRAFTING + : devicesByBlock.get (containerScreen.getContainer ().getCraftingBlock ()).uid; + + IGuiClickableArea clickableArea = IGuiClickableArea.createBasic (88, 32, 28, 23, uid); + return Collections.singleton (clickableArea); + } + }); + + if (theForgeField != null) + { + registration.addGuiContainerHandler (AlloyForgeScreen.class, new IGuiContainerHandler () + { + + @Override + public Collection getGuiClickableAreas (AlloyForgeScreen containerScreen, + double mouseX, double mouseY) + { + AbstractAlloyForgeTileEntity forge = null; + try + { + forge = (AbstractAlloyForgeTileEntity) theForgeField.get (containerScreen.getContainer ()); + } + catch (Exception e) + { + JEILotr.LOGGER.error ("Couldn't get the alloy forge tile entity from the container", e); + } + + if (forge != null) + { + IGuiClickableArea clickableArea = IGuiClickableArea.createBasic (77, 55, 22, 30, + devicesByBlock.get (forge.getBlockState ().getBlock ()).uid); + return Collections.singleton (clickableArea); + } + + return new HashSet<> (); + } + }); + } + } + + @Override + public void registerRecipeTransferHandlers (IRecipeTransferRegistration registration) + { + initDevices (); // TODO implement + + devices.forEach (device -> device.registerTransferHandlers (registration)); + } + + private class LOTRKeg extends LOTRDevice + { + + public LOTRKeg (ResourceLocation uid, ItemStack icon, Collection> recipeTypes) + { + super (uid, icon, recipeTypes); + } + + @Override + public IRecipeCategory createCategoryInstance (IGuiHelper guiHelper, IModIdHelper modIdHelper) + { + return new Keg (uid, icon, guiHelper); + } + + @Override + public void registerTransferHandlers (IRecipeTransferRegistration registration) + { + super.registerTransferHandlers (registration); + + registration.addRecipeTransferHandler (KegContainer.class, uid, 0, 9, 10, 36); + } + + } + + private class LOTRAlloyForge extends LOTRDevice + { + + protected final AbstractAlloyForgeTileEntity forge; + + @SuppressWarnings("resource") + public LOTRAlloyForge (ResourceLocation uid, ItemStack icon, Collection> recipeTypes, + AbstractAlloyForgeTileEntity forge) + { + super (uid, icon, recipeTypes); + this.forge = forge; + this.forge.setWorldAndPos (Minecraft.getInstance ().world, BlockPos.ZERO); + } + + @Override + public IRecipeCategory createCategoryInstance (IGuiHelper guiHelper, IModIdHelper modIdHelper) + { + return new AlloyForge (uid, icon, guiHelper); + } + + @Override + public boolean isRecipeValid (IRecipe recipe) + { + if (recipe instanceof AbstractAlloyForgeRecipe) + { + AbstractAlloyForgeRecipe alloyRecipe = (AbstractAlloyForgeRecipe) recipe; + return isRecipeValid (alloyRecipe.getIngredients ().get (0), alloyRecipe.getIngredients ().get (1), + (alloy, ingred) -> + { + Inventory testInv = new Inventory (2); + testInv.setInventorySlotContents (0, ingred); + testInv.setInventorySlotContents (1, alloy); + return alloyRecipe.getCraftingResult (testInv); + }); + } + else if (recipe instanceof AbstractCookingRecipe) + { + AbstractCookingRecipe cookingRecipe = (AbstractCookingRecipe) recipe; + return isRecipeValid (cookingRecipe.getIngredients ().get (0), Ingredient.EMPTY, (alloy, ingred) -> + { + Inventory testInv = new Inventory (1); + testInv.setInventorySlotContents (0, ingred); + return cookingRecipe.getCraftingResult (testInv); + }); + } + + return true; + } + + private boolean isRecipeValid (Ingredient ingredientItem, Ingredient alloyItem, + BiFunction resultFunction) + { + ItemStack[] ingredientStacks = ingredientItem.getMatchingStacks (); + ItemStack[] alloyStacks = alloyItem == Ingredient.EMPTY ? new ItemStack[] + {ItemStack.EMPTY} : alloyItem.getMatchingStacks (); + + for (ItemStack ingredient : ingredientStacks) + { + for (ItemStack alloy : alloyStacks) + { + ItemStack result = forge.getSmeltingResult (ingredient, alloy); + if (result == ItemStack.EMPTY || !result.equals (resultFunction.apply (ingredient, alloy), false)) + return false; // Invalid recipe + } + } + + return true; + } + + @Override + public void registerTransferHandlers (IRecipeTransferRegistration registration) + { + super.registerTransferHandlers (registration); + + registration.addRecipeTransferHandler (AlloyForgeContainer.class, uid, 0, 8, 13, 36); + } + + } + + private class LOTRCraftingTable extends LOTRDevice + { + + private final RegistryObject> container; + + public LOTRCraftingTable (ResourceLocation uid, ItemStack icon, Collection> recipeTypes, + RegistryObject> container) + { + super (uid, icon, recipeTypes); + this.container = container; + } + + @Override + public IRecipeCategory createCategoryInstance (IGuiHelper guiHelper, IModIdHelper modIdHelper) + { + return new FactionCraftingTable (uid, icon, guiHelper, modIdHelper); + } + + @SuppressWarnings("resource") + @Override + public void registerTransferHandlers (IRecipeTransferRegistration registration) + { + super.registerTransferHandlers (registration); + + registration.addRecipeTransferHandler ( + container.get ().create (0, Minecraft.getInstance ().player.inventory).getClass (), uid, 1, 9, 10, 36); + registration.addRecipeTransferHandler ( + container.get ().create (0, Minecraft.getInstance ().player.inventory).getClass (), + VanillaRecipeCategoryUid.CRAFTING, 1, 9, 10, 36); + } + + } + + private abstract class LOTRDevice + { + protected ResourceLocation uid; + protected ItemStack icon; + protected Collection> recipeTypes; + protected Class guiClass; + protected Vector4f guiHandlerArea; + + public LOTRDevice (ResourceLocation uid, ItemStack icon, Collection> recipeTypes) + { + this.uid = uid; + this.icon = icon; + this.recipeTypes = recipeTypes; + } + + public abstract IRecipeCategory createCategoryInstance (IGuiHelper guiHelper, IModIdHelper modIdHelper); + + public boolean isRecipeValid (IRecipe recipe) + { + return true; + } + + public void registerTransferHandlers (IRecipeTransferRegistration registration) + { + + } + + @Override + public int hashCode () + { + final int prime = 31; + int result = 1; + result = prime * result + getOuterType ().hashCode (); + result = prime * result + (icon == null ? 0 : icon.hashCode ()); + result = prime * result + (guiClass == null ? 0 : guiClass.hashCode ()); + result = prime * result + (guiHandlerArea == null ? 0 : guiHandlerArea.hashCode ()); + result = prime * result + (recipeTypes == null ? 0 : recipeTypes.hashCode ()); + result = prime * result + (uid == null ? 0 : uid.hashCode ()); + return result; + } + + @Override + public boolean equals (Object obj) + { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass () != obj.getClass ()) + return false; + LOTRDevice other = (LOTRDevice) obj; + if (!getOuterType ().equals (other.getOuterType ())) + return false; + if (icon == null) + { + if (other.icon != null) + return false; + } + else if (!icon.equals (other.icon)) + return false; + if (guiClass == null) + { + if (other.guiClass != null) + return false; + } + else if (!guiClass.equals (other.guiClass)) + return false; + if (guiHandlerArea == null) + { + if (other.guiHandlerArea != null) + return false; + } + else if (!guiHandlerArea.equals (other.guiHandlerArea)) + return false; + if (recipeTypes == null) + { + if (other.recipeTypes != null) + return false; + } + else if (!recipeTypes.equals (other.recipeTypes)) + return false; + if (uid == null) + { + if (other.uid != null) + return false; + } + else if (!uid.equals (other.uid)) + return false; + return true; + } + + private JEIPlugin getOuterType () + { + return JEIPlugin.this; + } + + } } diff --git a/src/main/java/craftedMods/jeiLotr/Keg.java b/src/main/java/craftedMods/jeiLotr/Keg.java index ceedee1..05faf4f 100644 --- a/src/main/java/craftedMods/jeiLotr/Keg.java +++ b/src/main/java/craftedMods/jeiLotr/Keg.java @@ -17,9 +17,7 @@ package craftedMods.jeiLotr; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import java.util.*; import com.mojang.blaze3d.matrix.MatrixStack; @@ -38,106 +36,124 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.resources.I18n; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; +import net.minecraft.item.*; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.ResourceLocation; -public class Keg implements IRecipeCategory { - - private final ResourceLocation uid; - private final ItemStack kegIcon; - private final IDrawable icon; - private final IDrawable background; - - public Keg(ResourceLocation uid, ItemStack forgeIcon, IGuiHelper guiHelper) { - this.uid = uid; - this.kegIcon = forgeIcon; - this.icon = guiHelper.createDrawableIngredient(forgeIcon); - this.background = guiHelper.createDrawable(Constants.RECIPE_GUI_VANILLA, 0, 60, 116, 54); - } - - @Override - public ResourceLocation getUid() { - return uid; - } - - @Override - public String getTitle() { - return I18n.get(kegIcon.getDescriptionId()); - } - - @Override - public IDrawable getIcon() { - return icon; - } - - @Override - public IDrawable getBackground() { - return background; - } - - @Override - public Class getRecipeClass() { - return DrinkBrewingRecipe.class; - } - - @Override - public void setIngredients(DrinkBrewingRecipe recipe, IIngredients ingreds) { - List ingredients = new ArrayList<>(recipe.getIngredients()); - ingredients.addAll(Arrays.asList(Ingredient.of(new ItemStack(Items.WATER_BUCKET)), - Ingredient.of(new ItemStack(Items.WATER_BUCKET)), Ingredient.of(new ItemStack(Items.WATER_BUCKET)))); - ingreds.setInputIngredients(ingredients); - ingreds.setOutput(VanillaTypes.ITEM, recipe.getResultItem()); - } - - @Override - public void setRecipe(IRecipeLayout layout, DrinkBrewingRecipe recipe, IIngredients ingreds) { - IGuiItemStackGroup guiItemStacks = layout.getItemStacks(); - - for (int i = 0; i < ingreds.getInputs(VanillaTypes.ITEM).size(); i++) { - guiItemStacks.init(i, true, 18 * (i % 3), 18 * (int) Math.floor(i / 3)); - guiItemStacks.set(i, ingreds.getInputs(VanillaTypes.ITEM).get(i)); - } - - ItemStack resultItem = ingreds.getOutputs(VanillaTypes.ITEM).get(0).get(0); - - List resultItems = new ArrayList<>(); - - if (resultItem.getItem() instanceof VesselDrinkItem) { - guiItemStacks.init(9, false, 94, 18); - - for (Potency potency : Potency.values()) { - ItemStack newStack = resultItem.copy(); - VesselDrinkItem.setPotency(newStack, potency); - resultItems.add(newStack); - } - } else { - resultItems.add(resultItem); - } - - guiItemStacks.set(9, resultItems); - } - - @Override - public void draw(DrinkBrewingRecipe recipe, MatrixStack matrixStack, double mouseX, double mouseY) { - Minecraft minecraft = Minecraft.getInstance(); - FontRenderer fontRenderer = minecraft.font; - - float experience = recipe.getExperience(); - - if (experience > 0.0f) { - String experienceString = Translator.translateToLocalFormatted("gui.jei.category.smelting.experience", - new Object[] { Float.valueOf(experience) }); - - int stringWidth = fontRenderer.width(experienceString); - fontRenderer.draw(matrixStack, experienceString, background.getWidth() - stringWidth, 0.0f, -8355712); - } - - String brewingTimeString = String.format("%.1f min", recipe.getBrewTime() / 1200.0f); - - int stringWidth = fontRenderer.width(brewingTimeString); - fontRenderer.draw(matrixStack, brewingTimeString, background.getWidth() - stringWidth, 45.0f, -8355712); - } +public class Keg implements IRecipeCategory +{ + + private final ResourceLocation uid; + private final ItemStack kegIcon; + private final IDrawable icon; + private final IDrawable background; + + public Keg (ResourceLocation uid, ItemStack forgeIcon, IGuiHelper guiHelper) + { + this.uid = uid; + this.kegIcon = forgeIcon; + this.icon = guiHelper.createDrawableIngredient (forgeIcon); + this.background = guiHelper.createDrawable (Constants.RECIPE_GUI_VANILLA, 0, 60, 116, 54); + } + + @Override + public ResourceLocation getUid () + { + return uid; + } + + @Override + public String getTitle () + { + return I18n.format (kegIcon.getTranslationKey ()); + } + + @Override + public IDrawable getIcon () + { + return icon; + } + + @Override + public IDrawable getBackground () + { + return background; + } + + @Override + public Class getRecipeClass () + { + return DrinkBrewingRecipe.class; + } + + @Override + public void setIngredients (DrinkBrewingRecipe recipe, IIngredients ingreds) + { + List ingredients = new ArrayList<> (recipe.getIngredients ()); + ingredients.addAll (Arrays.asList (Ingredient.fromStacks (new ItemStack (Items.WATER_BUCKET)), + Ingredient.fromStacks (new ItemStack (Items.WATER_BUCKET)), + Ingredient.fromStacks (new ItemStack (Items.WATER_BUCKET)))); + ingreds.setInputIngredients (ingredients); + ingreds.setOutput (VanillaTypes.ITEM, recipe.getRecipeOutput ()); + } + + @Override + public void setRecipe (IRecipeLayout layout, DrinkBrewingRecipe recipe, IIngredients ingreds) + { + IGuiItemStackGroup guiItemStacks = layout.getItemStacks (); + + for (int i = 0; i < ingreds.getInputs (VanillaTypes.ITEM).size (); i++) + { + guiItemStacks.init (i, true, 18 * (i % 3), 18 * (int) Math.floor (i / 3)); + guiItemStacks.set (i, ingreds.getInputs (VanillaTypes.ITEM).get (i)); + } + + ItemStack resultItem = ingreds.getOutputs (VanillaTypes.ITEM).get (0).get (0); + + List resultItems = new ArrayList<> (); + + if (resultItem.getItem () instanceof VesselDrinkItem) + { + guiItemStacks.init (9, false, 94, 18); + + for (Potency potency : Potency.values ()) + { + ItemStack newStack = resultItem.copy (); + VesselDrinkItem.setPotency (newStack, potency); + resultItems.add (newStack); + } + } + else + { + resultItems.add (resultItem); + } + + guiItemStacks.set (9, resultItems); + } + + @Override + public void draw (DrinkBrewingRecipe recipe, MatrixStack matrixStack, double mouseX, double mouseY) + { + Minecraft minecraft = Minecraft.getInstance (); + FontRenderer fontRenderer = minecraft.fontRenderer; + + float experience = recipe.getExperience (); + + if (experience > 0.0f) + { + String experienceString = Translator.translateToLocalFormatted ("gui.jei.category.smelting.experience", + new Object[] + {Float.valueOf (experience)}); + + int stringWidth = fontRenderer.getStringWidth (experienceString); + fontRenderer.drawString (matrixStack, experienceString, background.getWidth () - stringWidth, 0.0f, + -8355712); + } + + String brewingTimeString = String.format ("%.1f min", recipe.getBrewTime () / 1200.0f); + + int stringWidth = fontRenderer.getStringWidth (brewingTimeString); + fontRenderer.drawString (matrixStack, brewingTimeString, background.getWidth () - stringWidth, 45.0f, -8355712); + } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 164ad2a..2a9ff48 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -4,7 +4,7 @@ issueTrackerURL="http:/github.com/CraftedMods/jei-lotr/issues" license="GNU GENERAL PUBLIC LICENSE Version 3" [[mods]] modId="jeilotr" -version="2.0.0-BETA" +version="3.0.0-BETA" displayName="JEI LOTR" updateJSONURL="https://raw.githubusercontent.com/CraftedMods/jei-lotr/master/versions.json" displayURL="http://github.com/CraftedMods/jei-lotr" @@ -34,7 +34,7 @@ A JEI-Plugin for the "The Lord of the Rings" Minecraft Mod. [[dependencies.jeilotr]] modId="lotr" mandatory=true - versionRange="[Renewed-3.0,)" + versionRange="[Renewed-4.5,)" ordering="NONE" side="BOTH" [[dependencies.jeilotr]] diff --git a/versions.json b/versions.json index af8b23b..ebde19f 100644 --- a/versions.json +++ b/versions.json @@ -1,7 +1,8 @@ { "homepage": "https://www.curseforge.com/minecraft/mc-mods/jei-lotr/files", "1.16.5": { - "2.0.0-BETA": "Updated to LOTR Renewed-3.0" + "2.0.0-BETA": "Updated to LOTR Renewed-3.0", + "3.0.0-BETA": "Updated to LOTR Renewed-4.5" }, "1.15.2": { "1.0.0-ALPHA": "First release for LOTR Renewed-1.0", @@ -14,7 +15,7 @@ "promos": { "1.15.2-latest": "1.3.1-BETA", "1.15.2-recommended": "1.3.1-BETA", - "1.16.5-latest": "2.0.0-BETA", - "1.16.5-recommended": "2.0.0-BETA" + "1.16.5-latest": "3.0.0-BETA", + "1.16.5-recommended": "3.0.0-BETA" } }