From 120bdae9c612525844fbdaba54a0676551a8c481 Mon Sep 17 00:00:00 2001 From: CraftedMods Date: Mon, 12 Apr 2021 17:21:10 +0200 Subject: [PATCH] Updated to 1.16.5 --- CHANGELOG.md | 3 + README.md | 6 +- build.gradle | 8 +- gradle.properties | 6 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../java/craftedMods/jeiLotr/AlloyForge.java | 228 ++--- .../jeiLotr/FactionCraftingTable.java | 86 +- .../java/craftedMods/jeiLotr/JEILotr.java | 79 +- .../java/craftedMods/jeiLotr/JEIPlugin.java | 967 ++++++++---------- src/main/java/craftedMods/jeiLotr/Keg.java | 226 ++-- src/main/resources/META-INF/mods.toml | 11 +- versions.json | 7 +- 12 files changed, 772 insertions(+), 857 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 867957c..c8b4960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog of JEI LOTR +## 2.0.0-BETA +* Updated to 1.16.5 and LOTR Renewed-3.0 + ## 1.3.1-BETA * Updated to LOTR Renewed-2.2 * Fixed that the transfer/click handlers didn't work anymore diff --git a/README.md b/README.md index 2f7580b..1834f69 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ 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 v2.2](https://www.curseforge.com/minecraft/mc-mods/the-lord-of-the-rings-mod-renewed/files) -- [JEI 1.15.2-6.0.3.15](https://www.curseforge.com/minecraft/mc-mods/jei/files/all) +- [The Lord of the Rings Mod Renewed v3.0](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.15.2-31.2.31". +The plugin was created with the MinecraftForge version "1.16.5-36.1.0". ## Announcements and Documentation Announcements regarding the plugin can be found at the official Discord server (https://discord.gg/37GanUf) and here: http://lotrminecraftmod.wikia.com/wiki/Thread:174874 ## Download diff --git a/build.gradle b/build.gradle index 6c6257a..ce9f927 100644 --- a/build.gradle +++ b/build.gradle @@ -12,7 +12,7 @@ buildscript { } } dependencies { - classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '3.+', changing: true + classpath group: 'net.minecraftforge.gradle', name: 'ForgeGradle', version: '4.1+', changing: true classpath "net.minecrell.licenser:net.minecrell.licenser.gradle.plugin:0.+" } } @@ -22,7 +22,7 @@ apply plugin: 'eclipse' apply plugin: 'maven-publish' apply plugin: "net.minecrell.licenser" -version = '1.3.1-BETA' +version = '2.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: 'snapshot', version: '20200225-1.15.1' + mappings channel: 'official', version: '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.15.2-31.2.31' + minecraft 'net.minecraftforge:forge:1.16.5-36.1.0' compileOnly fg.deobf("mezz.jei:jei-${jei_mc_version}:${jei_version}") diff --git a/gradle.properties b/gradle.properties index 604e4ae..442e711 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,6 +2,6 @@ # This is required to provide enough memory for the Minecraft decompilation process. org.gradle.jvmargs=-Xmx3G org.gradle.daemon=false -jei_mc_version=1.15.2 -jei_version=6.0.3.15 -lotr_version=2.2 +jei_mc_version=1.16.5 +jei_version=7.6.4.86 +lotr_version=3.0 diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1d5b29f..703238f 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.1-all.zip diff --git a/src/main/java/craftedMods/jeiLotr/AlloyForge.java b/src/main/java/craftedMods/jeiLotr/AlloyForge.java index 7ac8553..337e9e9 100644 --- a/src/main/java/craftedMods/jeiLotr/AlloyForge.java +++ b/src/main/java/craftedMods/jeiLotr/AlloyForge.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2020 CraftedMods (see http://github.com/CraftedMods) + * Copyright (C) 2020-2021 CraftedMods (see http://github.com/CraftedMods) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -17,10 +17,13 @@ package craftedMods.jeiLotr; +import com.mojang.blaze3d.matrix.MatrixStack; + import lotr.common.recipe.AbstractAlloyForgeRecipe; import mezz.jei.api.constants.VanillaTypes; import mezz.jei.api.gui.IRecipeLayout; -import mezz.jei.api.gui.drawable.*; +import mezz.jei.api.gui.drawable.IDrawable; +import mezz.jei.api.gui.drawable.IDrawableAnimated; import mezz.jei.api.gui.ingredient.IGuiItemStackGroup; import mezz.jei.api.helpers.IGuiHelper; import mezz.jei.api.ingredients.IIngredients; @@ -30,128 +33,107 @@ import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.resources.I18n; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.*; +import net.minecraft.item.crafting.AbstractCookingRecipe; +import net.minecraft.item.crafting.IRecipe; 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; - icon = guiHelper.createDrawableIngredient (forgeIcon); - background = guiHelper.createDrawable (ALLOY_FORGE_GUI_LOCATION, 45, 20, 85, 130); - 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, double mouseX, double mouseY) - { - animatedFlame.draw (35, 92); - arrow.draw (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 (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.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); + } + } } diff --git a/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java b/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java index 96118c7..a24ad18 100644 --- a/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java +++ b/src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2020 CraftedMods (see http://github.com/CraftedMods) + * Copyright (C) 2020-2021 CraftedMods (see http://github.com/CraftedMods) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -17,57 +17,65 @@ package craftedMods.jeiLotr; -import lotr.common.recipe.*; +import lotr.common.recipe.LOTRShapedRecipe; +import lotr.common.recipe.LOTRShapelessRecipe; import mezz.jei.api.gui.drawable.IDrawable; -import mezz.jei.api.helpers.*; -import mezz.jei.plugins.vanilla.crafting.*; +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 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 final ResourceLocation uid; + private final ItemStack ctIcon; + private final IDrawable icon; + + private ITextComponent titleTextComponent; - public FactionCraftingTable (ResourceLocation uid, ItemStack ctIcon, IGuiHelper guiHelper, - IModIdHelper modIdHelper) - { - super (guiHelper, modIdHelper); + public FactionCraftingTable(ResourceLocation uid, ItemStack ctIcon, IGuiHelper guiHelper, + IModIdHelper modIdHelper) { + super(guiHelper); - this.uid = uid; - this.ctIcon = ctIcon; - icon = guiHelper.createDrawableIngredient (ctIcon); + this.uid = uid; + this.ctIcon = ctIcon; + this.icon = guiHelper.createDrawableIngredient(ctIcon); - this.addCategoryExtension (LOTRShapedRecipe.class, CraftingCategoryExtension::new); - this.addCategoryExtension (LOTRShapelessRecipe.class, CraftingCategoryExtension::new); - } + this.addCategoryExtension(LOTRShapedRecipe.class, CraftingCategoryExtension::new); + this.addCategoryExtension(LOTRShapelessRecipe.class, CraftingCategoryExtension::new); + + this.titleTextComponent = new TranslationTextComponent(I18n.get(ctIcon.getDescriptionId())); + } - @Override - public ResourceLocation getUid () - { - return uid; - } + @Override + public ResourceLocation getUid() { + return uid; + } - @Override - public Class getRecipeClass () - { - return ICraftingRecipe.class; - } + @Override + public Class getRecipeClass() { + return ICraftingRecipe.class; + } - @Override - public String getTitle () - { - return I18n.format (ctIcon.getTranslationKey ()); - } + @Override + public String getTitle() { + return I18n.get(ctIcon.getDescriptionId()); + } + + @Override + public ITextComponent getTitleAsTextComponent() { + return this.titleTextComponent; + } - @Override - public IDrawable getIcon () - { - return icon; - } + @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 053c546..6cde723 100644 --- a/src/main/java/craftedMods/jeiLotr/JEILotr.java +++ b/src/main/java/craftedMods/jeiLotr/JEILotr.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2020 CraftedMods (see http://github.com/CraftedMods) + * Copyright (C) 2020-2021 CraftedMods (see http://github.com/CraftedMods) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -17,7 +17,8 @@ package craftedMods.jeiLotr; -import org.apache.logging.log4j.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import lotr.common.tileentity.AbstractAlloyForgeTileEntity; import net.minecraft.client.entity.player.ClientPlayerEntity; @@ -26,56 +27,48 @@ import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.EntityJoinWorldEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; -import net.minecraftforge.fml.*; +import net.minecraftforge.fml.ModList; +import net.minecraftforge.fml.VersionChecker; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; 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 anyting 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")); - } - } - } + @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()); + } + } + } } diff --git a/src/main/java/craftedMods/jeiLotr/JEIPlugin.java b/src/main/java/craftedMods/jeiLotr/JEIPlugin.java index 343011a..db22344 100644 --- a/src/main/java/craftedMods/jeiLotr/JEIPlugin.java +++ b/src/main/java/craftedMods/jeiLotr/JEIPlugin.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2020 CraftedMods (see http://github.com/CraftedMods) + * Copyright (C) 2020-2021 CraftedMods (see http://github.com/CraftedMods) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -17,532 +17,473 @@ package craftedMods.jeiLotr; -import java.lang.reflect.*; -import java.util.*; +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.util.function.BiFunction; import java.util.stream.Collectors; -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 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 mezz.jei.api.constants.VanillaRecipeCategoryUid; -import mezz.jei.api.gui.handlers.*; -import mezz.jei.api.helpers.*; +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.recipe.category.IRecipeCategory; -import mezz.jei.api.registration.*; +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 net.minecraft.block.Block; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.Vector4f; import net.minecraft.inventory.Inventory; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.*; +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.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.vector.Vector4f; import net.minecraftforge.fml.RegistryObject; @JeiPlugin -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"); - } - - @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.getBlockFromItem (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.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); - } - } - - @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.isItemEqual (resultFunction.apply (ingredient, alloy))) - 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("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; + } + + } } diff --git a/src/main/java/craftedMods/jeiLotr/Keg.java b/src/main/java/craftedMods/jeiLotr/Keg.java index e0bab57..ceedee1 100644 --- a/src/main/java/craftedMods/jeiLotr/Keg.java +++ b/src/main/java/craftedMods/jeiLotr/Keg.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2020 CraftedMods (see http://github.com/CraftedMods) + * Copyright (C) 2020-2021 CraftedMods (see http://github.com/CraftedMods) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by @@ -17,7 +17,11 @@ package craftedMods.jeiLotr; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import com.mojang.blaze3d.matrix.MatrixStack; import lotr.common.item.VesselDrinkItem; import lotr.common.item.VesselDrinkItem.Potency; @@ -34,128 +38,106 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; import net.minecraft.client.resources.I18n; -import net.minecraft.item.*; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; import net.minecraft.item.crafting.Ingredient; import net.minecraft.util.ResourceLocation; -public class Keg implements IRecipeCategory -{ - - private final ResourceLocation uid; - private final ItemStack forgeIcon; - private final IDrawable icon; - private final IDrawable background; - - public Keg (ResourceLocation uid, ItemStack forgeIcon, IGuiHelper guiHelper) - { - this.uid = uid; - this.forgeIcon = forgeIcon; - icon = guiHelper.createDrawableIngredient (forgeIcon); - background = guiHelper.createDrawable (Constants.RECIPE_GUI_VANILLA, 0, 60, 116, 54); - } - - @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 - 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, 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 (experienceString, background.getWidth () - stringWidth, 0.0f, - -8355712); - } - - String brewingTimeString = String.format ("%.1f min", recipe.getBrewTime () / 1200.0f); - - int stringWidth = fontRenderer.getStringWidth (brewingTimeString); - fontRenderer.drawString (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.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); + } } diff --git a/src/main/resources/META-INF/mods.toml b/src/main/resources/META-INF/mods.toml index 90417b4..164ad2a 100644 --- a/src/main/resources/META-INF/mods.toml +++ b/src/main/resources/META-INF/mods.toml @@ -1,9 +1,10 @@ modLoader="javafml" loaderVersion="[27,)" -issueTrackerURL="http:/github.com/CraftedMods/jei-lotr/issues" +issueTrackerURL="http:/github.com/CraftedMods/jei-lotr/issues" +license="GNU GENERAL PUBLIC LICENSE Version 3" [[mods]] modId="jeilotr" -version="1.3.1-BETA" +version="2.0.0-BETA" displayName="JEI LOTR" updateJSONURL="https://raw.githubusercontent.com/CraftedMods/jei-lotr/master/versions.json" displayURL="http://github.com/CraftedMods/jei-lotr" @@ -27,18 +28,18 @@ A JEI-Plugin for the "The Lord of the Rings" Minecraft Mod. [[dependencies.jeilotr]] modId="minecraft" mandatory=true - versionRange="[1.15.2]" + versionRange="[1.16.5]" ordering="NONE" side="BOTH" [[dependencies.jeilotr]] modId="lotr" mandatory=true - versionRange="[Renewed-2.2,)" + versionRange="[Renewed-3.0,)" ordering="NONE" side="BOTH" [[dependencies.jeilotr]] modId="jei" mandatory=true - versionRange="[6.0.3.15,)" + versionRange="[7.6.4.86,)" ordering="NONE" side="BOTH" diff --git a/versions.json b/versions.json index 321ee28..af8b23b 100644 --- a/versions.json +++ b/versions.json @@ -1,5 +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" + }, "1.15.2": { "1.0.0-ALPHA": "First release for LOTR Renewed-1.0", "1.0.0-BETA": "Updated to LOTR Renewed-1.1", @@ -10,6 +13,8 @@ }, "promos": { "1.15.2-latest": "1.3.1-BETA", - "1.15.2-recommended": "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" } }