Skip to content

Commit

Permalink
Closed #1
Browse files Browse the repository at this point in the history
  • Loading branch information
CraftedMods committed May 5, 2020
1 parent 4d71c51 commit c373d79
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 74 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Changelog of JEI LOTR

## 1.1.0-BETA
* New faction crafting tables will now be discovered automatically
* Fixed that some recipes were not shown for faction crafting tables

## 1.0.0-BETA:
* First release for LOTR Renewed-1.1 and jei-1.15.2-6.0.0.4
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ apply plugin: 'eclipse'
apply plugin: 'maven-publish'
apply plugin: "net.minecrell.licenser"

version = '1.0.0-BETA'
version = '1.1.0-BETA'
group = 'craftedMods.jeiLotr' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'jeilotr'

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/craftedMods/jeiLotr/FactionCraftingTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import mezz.jei.api.gui.drawable.IDrawable;
import mezz.jei.api.helpers.*;
import mezz.jei.plugins.vanilla.crafting.*;
import net.minecraft.block.Block;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.ICraftingRecipe;
Expand All @@ -31,17 +30,17 @@ public class FactionCraftingTable extends CraftingRecipeCategory
{

private final ResourceLocation uid;
private final Block ctBlock;
private final ItemStack ctIcon;
private final IDrawable icon;

public FactionCraftingTable (ResourceLocation uid, Block ctBlock, IGuiHelper guiHelper,
public FactionCraftingTable (ResourceLocation uid, ItemStack ctIcon, IGuiHelper guiHelper,
IModIdHelper modIdHelper)
{
super (guiHelper, modIdHelper);

this.uid = uid;
this.ctBlock = ctBlock;
icon = guiHelper.createDrawableIngredient (new ItemStack (ctBlock));
this.ctIcon = ctIcon;
icon = guiHelper.createDrawableIngredient (ctIcon);

this.addCategoryExtension (LOTRShapedRecipe.class, CraftingCategoryExtension::new);
this.addCategoryExtension (LOTRShapelessRecipe.class, CraftingCategoryExtension::new);
Expand All @@ -62,7 +61,7 @@ public Class<? extends ICraftingRecipe> getRecipeClass ()
@Override
public String getTitle ()
{
return I18n.format (ctBlock.getTranslationKey ());
return I18n.format (ctIcon.getTranslationKey ());
}

@Override
Expand Down
116 changes: 53 additions & 63 deletions src/main/java/craftedMods/jeiLotr/JEIPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,21 @@

package craftedMods.jeiLotr;

import java.lang.reflect.Method;
import java.lang.reflect.*;
import java.util.*;

import lotr.common.init.*;
import lotr.common.recipe.LOTRRecipes;
import lotr.common.recipe.*;
import mezz.jei.api.*;
import mezz.jei.api.registration.*;
import net.minecraft.block.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Vector4f;
import net.minecraft.item.*;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.*;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.RegistryObject;

@JeiPlugin
public class JEIPlugin implements IModPlugin
{
public static final ResourceLocation DWARVEN_CT_UID = new ResourceLocation ("lotr", "dwarven_ct");
public static final ResourceLocation GONDOR_CT_UID = new ResourceLocation ("lotr", "gondor_ct");
public static final ResourceLocation GALADHRIM_CT_UID = new ResourceLocation ("lotr", "galadhrim_ct");
public static final ResourceLocation HARAD_CT_UID = new ResourceLocation ("lotr", "harad_ct");
public static final ResourceLocation LINDON_CT_UID = new ResourceLocation ("lotr", "lindon_ct");
public static final ResourceLocation MORDOR_CT_UID = new ResourceLocation ("lotr", "mordor_ct");
public static final ResourceLocation RIVENDELL_CT_UID = new ResourceLocation ("lotr", "rivendell_ct");
public static final ResourceLocation ROHAN_CT_UID = new ResourceLocation ("lotr", "rohan_ct");
public static final ResourceLocation UMBAR_CT_UID = new ResourceLocation ("lotr", "umbar_ct");
public static final ResourceLocation WOOD_ELVEN_CT_UID = new ResourceLocation ("lotr", "wood_elven_ct");

private static Method getRecipesMethod;

static
Expand Down Expand Up @@ -84,39 +70,39 @@ public void initCraftingTables ()
{
craftingTables = new HashSet<> ();

craftingTables.add (new LOTRCraftingTable (DWARVEN_CT_UID,
getCTBlock (LOTRBlocks.DWARVEN_CRAFTING_TABLE), LOTRRecipes.DWARVEN_CRAFTING));
craftingTables.add (new LOTRCraftingTable (GONDOR_CT_UID,
getCTBlock (LOTRBlocks.GONDOR_CRAFTING_TABLE), LOTRRecipes.GONDOR_CRAFTING));
craftingTables.add (new LOTRCraftingTable (GALADHRIM_CT_UID,
getCTBlock (LOTRBlocks.GALADHRIM_CRAFTING_TABLE), LOTRRecipes.GALADHRIM_CRAFTING));
craftingTables.add (new LOTRCraftingTable (HARAD_CT_UID,
getCTBlock (LOTRBlocks.HARAD_CRAFTING_TABLE), LOTRRecipes.HARAD_CRAFTING));
craftingTables.add (new LOTRCraftingTable (LINDON_CT_UID,
getCTBlock (LOTRBlocks.LINDON_CRAFTING_TABLE), LOTRRecipes.LINDON_CRAFTING));
craftingTables.add (new LOTRCraftingTable (MORDOR_CT_UID,
getCTBlock (LOTRBlocks.MORDOR_CRAFTING_TABLE), LOTRRecipes.MORDOR_CRAFTING));
craftingTables.add (new LOTRCraftingTable (RIVENDELL_CT_UID,
getCTBlock (LOTRBlocks.RIVENDELL_CRAFTING_TABLE), LOTRRecipes.RIVENDELL_CRAFTING));
craftingTables.add (new LOTRCraftingTable (ROHAN_CT_UID,
getCTBlock (LOTRBlocks.ROHAN_CRAFTING_TABLE), LOTRRecipes.ROHAN_CRAFTING));
craftingTables.add (new LOTRCraftingTable (UMBAR_CT_UID,
getCTBlock (LOTRBlocks.UMBAR_CRAFTING_TABLE), LOTRRecipes.UMBAR_CRAFTING));
craftingTables.add (new LOTRCraftingTable (WOOD_ELVEN_CT_UID,
getCTBlock (LOTRBlocks.WOOD_ELVEN_CRAFTING_TABLE), LOTRRecipes.WOOD_ELVEN_CRAFTING));
}
}
try
{
for (Field field : LOTRRecipes.class.getDeclaredFields ())
{
if (field.getType () == FactionTableType.class && field.getName ().contains ("CRAFTING"))
{
FactionTableType type = (FactionTableType) field.get (null);

Collection<IRecipeType<?>> types = new ArrayList<> ();
types.add (type);
types.addAll (type.getMultiTableTypes ());

craftingTables
.add (new LOTRCraftingTable (new ResourceLocation ("lotr", type.recipeID.split (":")[1]),
type.getIcon (), types));
}
}
JEILotr.LOGGER.debug ("Found " + craftingTables.size () + " faction crafting tables");
}
catch (Exception e)
{
JEILotr.LOGGER
.error ("Couldn't instantiate the faction crafting tables from the LOTRRecipes type fields", e);
}

private Block getCTBlock (RegistryObject<Block> ctBlockRegistryObject)
{
return ctBlockRegistryObject.orElseGet ( () -> Blocks.CRAFTING_TABLE);
}
}

@Override
public void registerRecipeCatalysts (IRecipeCatalystRegistration registration)
{
initCraftingTables ();
craftingTables.forEach (table -> registration.addRecipeCatalyst (new ItemStack (table.ctBlock), table.uid));
craftingTables.forEach (table -> registration.addRecipeCatalyst (table.ctIcon.copy (), table.uid));
}

@Override
Expand All @@ -127,7 +113,7 @@ public void registerCategories (IRecipeCategoryRegistration registration)
{
registration
.addRecipeCategories (
new FactionCraftingTable (table.uid, table.ctBlock, registration.getJeiHelpers ().getGuiHelper (),
new FactionCraftingTable (table.uid, table.ctIcon, registration.getJeiHelpers ().getGuiHelper (),
registration.getJeiHelpers ().getModIdHelper ()));
});
}
Expand All @@ -136,27 +122,31 @@ public void registerCategories (IRecipeCategoryRegistration registration)
public void registerRecipes (IRecipeRegistration registration)
{
initCraftingTables ();
craftingTables.forEach (table -> registration.addRecipes (getRecipesOfType (table.recipeType), table.uid));
craftingTables.forEach (table -> registration.addRecipes (getRecipesOfTypes (table.recipeTypes), table.uid));

}

@SuppressWarnings("unchecked")
private Collection<IRecipe<?>> getRecipesOfType (IRecipeType<?> type)
private Collection<IRecipe<?>> getRecipesOfTypes (Collection<IRecipeType<?>> types)
{
Collection<IRecipe<?>> recipes = new ArrayList<> ();
if (getRecipesMethod != null)
{
try
{
return ((Map<ResourceLocation, IRecipe<?>>) getRecipesMethod.invoke (
Minecraft.getInstance ().world.getRecipeManager (),
type)).values ();
for (IRecipeType<?> type : types)
{
recipes.addAll ( ((Map<ResourceLocation, IRecipe<?>>) getRecipesMethod.invoke (
Minecraft.getInstance ().world.getRecipeManager (),
type)).values ());
}
}
catch (Exception e)
{
JEILotr.LOGGER.error ("Couldn't get the recipes of the specified type", e);
}
}
return Arrays.asList ();
return recipes;
}

@Override
Expand All @@ -175,16 +165,16 @@ public void registerRecipeTransferHandlers (IRecipeTransferRegistration registra
private class LOTRCraftingTable
{
private ResourceLocation uid;
private Block ctBlock;
private IRecipeType<?> recipeType;
private ItemStack ctIcon;
private Collection<IRecipeType<?>> recipeTypes;
private Class<?> guiClass;
private Vector4f guiHandlerArea;

public LOTRCraftingTable (ResourceLocation uid, Block ctBlock, IRecipeType<?> recipeType)
public LOTRCraftingTable (ResourceLocation uid, ItemStack ctIcon, Collection<IRecipeType<?>> recipeTypes)
{
this.uid = uid;
this.ctBlock = ctBlock;
this.recipeType = recipeType;
this.ctIcon = ctIcon;
this.recipeTypes = recipeTypes;
}

@Override
Expand All @@ -193,10 +183,10 @@ public int hashCode ()
final int prime = 31;
int result = 1;
result = prime * result + getOuterType ().hashCode ();
result = prime * result + (ctBlock == null ? 0 : ctBlock.hashCode ());
result = prime * result + (ctIcon == null ? 0 : ctIcon.hashCode ());
result = prime * result + (guiClass == null ? 0 : guiClass.hashCode ());
result = prime * result + (guiHandlerArea == null ? 0 : guiHandlerArea.hashCode ());
result = prime * result + (recipeType == null ? 0 : recipeType.hashCode ());
result = prime * result + (recipeTypes == null ? 0 : recipeTypes.hashCode ());
result = prime * result + (uid == null ? 0 : uid.hashCode ());
return result;
}
Expand All @@ -213,12 +203,12 @@ public boolean equals (Object obj)
LOTRCraftingTable other = (LOTRCraftingTable) obj;
if (!getOuterType ().equals (other.getOuterType ()))
return false;
if (ctBlock == null)
if (ctIcon == null)
{
if (other.ctBlock != null)
if (other.ctIcon != null)
return false;
}
else if (!ctBlock.equals (other.ctBlock))
else if (!ctIcon.equals (other.ctIcon))
return false;
if (guiClass == null)
{
Expand All @@ -234,12 +224,12 @@ else if (!guiClass.equals (other.guiClass))
}
else if (!guiHandlerArea.equals (other.guiHandlerArea))
return false;
if (recipeType == null)
if (recipeTypes == null)
{
if (other.recipeType != null)
if (other.recipeTypes != null)
return false;
}
else if (!recipeType.equals (other.recipeType))
else if (!recipeTypes.equals (other.recipeTypes))
return false;
if (uid == null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ loaderVersion="[27,)"
issueTrackerURL="http:/github.com/CraftedMods/jei-lotr/issues"
[[mods]]
modId="jeilotr"
version="1.0.0-BETA"
version="1.1.0-BETA"
displayName="JEI LOTR"
updateJSONURL="https://raw.githubusercontent.com/CraftedMods/jei-lotr/master/versions.json"
displayURL="http://github.com/CraftedMods/jei-lotr"
Expand Down
7 changes: 4 additions & 3 deletions versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"homepage": "https://www.curseforge.com/minecraft/mc-mods/jei-lotr/files",
"1.15.2": {
"1.0.0-ALPHA": "First release for LOTR Renewed-1.0",
"1.0.0-BETA": "Updated to LOTR Renewed-1.1"
"1.0.0-BETA": "Updated to LOTR Renewed-1.1",
"1.1.0-BETA": "Fixed that some faction crafting table recipes were not shown"
},
"promos": {
"1.15.2-latest": "1.0.0-BETA",
"1.15.2-recommended": "1.0.0-BETA"
"1.15.2-latest": "1.1.0-BETA",
"1.15.2-recommended": "1.1.0-BETA"
}
}

0 comments on commit c373d79

Please sign in to comment.