JEI method deprecation causes NPE in RegisterCategoriesEventJS.wrap
omgimanerd opened this issue ยท 1 comments
I have some code along the lines of the following:
Minecraft Version: 1.20.1
Forge: 47.3.0
KJS Additions: v4.3.2
JEI: v15.20.0.104
JEIAddedEvents.registerCategories((e) => {
// The vanilla Anvil recipe category, contains the code that performs the
// actual rendering of the recipe inputs and outputs in JEI.
const $AnvilRecipeCategory = Java.loadClass(
'mezz.jei.library.plugins.vanilla.anvil.AnvilRecipeCategory'
)
// RecipeType and the actual underlying processing recipe. Needed to create a
// RecipeType for the custom category registration.
const $RecipeType = Java.loadClass('mezz.jei.api.recipe.RecipeType')
const $IJeiAnvilRecipe = Java.loadClass(
'mezz.jei.api.recipe.vanilla.IJeiAnvilRecipe'
)
const nutrientInfusionRecipeType = $RecipeType.create(
'kubejs',
'nutrient_infusion',
$IJeiAnvilRecipe
)
const guiHelper = e.data.jeiHelpers.guiHelper
// Create an concrete instance of the anvil recipe category and defer our
// custom category to use its render code.
const anvilRecipeCategory = new $AnvilRecipeCategory(guiHelper)
e.wrap(nutrientInfusionRecipeType, anvilRecipeCategory, (category) => {
category
.title('Nutrient Infusion')
.icon(
doubleItemIcon('minecraft:anvil', 'minecraft:enchanted_golden_apple')
)
.isRecipeHandled(() => true) // Only relevant recipes are registered
})
})
which causes the following NPE:
[04:04:31] [ERROR] ! Error in 'JEIAddedEvents.registerCategories': Cannot invoke "mezz.jei.api.gui.drawable.IDrawable.getWidth()" because "background" is null
[04:04:31] [ERROR] ! java.lang.NullPointerException: Cannot invoke "mezz.jei.api.gui.drawable.IDrawable.getWidth()" because "background" is null
[04:04:31] [ERROR] ! at pie.ilikepiefoo.compat.jei.builder.RecipeCategoryBuilder.background(RecipeCategoryBuilder.java:81)
[04:04:31] [ERROR] ! at pie.ilikepiefoo.compat.jei.builder.RecipeCategoryWrapperBuilder.<init>(RecipeCategoryWrapperBuilder.java:27)
[04:04:31] [ERROR] ! at pie.ilikepiefoo.compat.jei.events.RegisterCategoriesEventJS.wrap(RegisterCategoriesEventJS.java:28)
It looks like AnvilRecipeCategory.background
is considered deprecated now, it calls IRecipeCategory.getBackground:
Seems like it is complaining here:
Basically, I think you can no longer depend on calls to IRecipeCategory.getBackground
I reopened the relevant ticket again on the kubejs discord too. Using my original workaround of this:
e.custom('kubejs:nutrient_infusion', (category) => {
category
.title('Nutrient Infusion')
.background(
guiHelper.createBlankDrawable(
anvilRecipeCategory.getWidth(),
anvilRecipeCategory.getHeight()
)
)
.icon(
doubleItemIcon('minecraft:anvil', 'minecraft:enchanted_golden_apple')
)
.isRecipeHandled(() => true)
.handleLookup((builder, recipe, focuses) => {
// TODO currently broken: anvilRecipeCategory.createRecipeExtras needs
// to be called in order to draw the arrow and experience costs.
anvilRecipeCategory.setRecipe(builder, recipe, focuses)
})
.setDrawHandler((recipe, slots, graphics, mouseX, mouseY) => {
anvilRecipeCategory.draw(recipe, slots, graphics, mouseX, mouseY)
})
})
Where I call all the handlers and defer the draw/handler methods to the AnvilRecipeCategory
no longer works because there is now a createRecipeExtras method which is called to draw the arrows and experience cost in the recipe category. I don't see an easy way to call it since I can't get access to a IRecipeExtrasBuilder
instance.