From b17ff6daf03e0be2b919a2cab3846ac6b0b6cd45 Mon Sep 17 00:00:00 2001 From: Jonathan Coates Date: Sat, 3 Apr 2021 14:08:58 +0100 Subject: [PATCH] Fix a couple of JEI issues - Don't treat turtles/pocket computers with no upgrades as an "any" turtle. Otherwise getting the recipe of a crafty turtle shows the recipe of a normal turtle too. - Fix "get usage" of upgrade items not returning their recipes. - Fix NPEs inside JEI (closes #719) --- .../shared/integration/jei/JEIComputerCraft.java | 12 ++++++------ .../shared/integration/jei/RecipeResolver.java | 9 +-------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/main/java/dan200/computercraft/shared/integration/jei/JEIComputerCraft.java b/src/main/java/dan200/computercraft/shared/integration/jei/JEIComputerCraft.java index a6ea2fc91..cb4ca8e81 100644 --- a/src/main/java/dan200/computercraft/shared/integration/jei/JEIComputerCraft.java +++ b/src/main/java/dan200/computercraft/shared/integration/jei/JEIComputerCraft.java @@ -114,10 +114,10 @@ public class JEIComputerCraft implements IModPlugin */ private static final ISubtypeInterpreter turtleSubtype = stack -> { Item item = stack.getItem(); - if( !(item instanceof ITurtleItem) ) return ""; + if( !(item instanceof ITurtleItem) ) return ISubtypeInterpreter.NONE; ITurtleItem turtle = (ITurtleItem) item; - StringBuilder name = new StringBuilder(); + StringBuilder name = new StringBuilder("turtle:"); // Add left and right upgrades to the identifier ITurtleUpgrade left = turtle.getUpgrade( stack, TurtleSide.LEFT ); @@ -134,9 +134,9 @@ public class JEIComputerCraft implements IModPlugin */ private static final ISubtypeInterpreter pocketSubtype = stack -> { Item item = stack.getItem(); - if( !(item instanceof ItemPocketComputer) ) return ""; + if( !(item instanceof ItemPocketComputer) ) return ISubtypeInterpreter.NONE; - StringBuilder name = new StringBuilder(); + StringBuilder name = new StringBuilder("pocket:"); // Add the upgrade to the identifier IPocketUpgrade upgrade = ItemPocketComputer.getUpgrade( stack ); @@ -150,11 +150,11 @@ public class JEIComputerCraft implements IModPlugin */ private static final ISubtypeInterpreter diskSubtype = stack -> { Item item = stack.getItem(); - if( !(item instanceof ItemDisk) ) return ""; + if( !(item instanceof ItemDisk) ) return ISubtypeInterpreter.NONE; ItemDisk disk = (ItemDisk) item; int colour = disk.getColour( stack ); - return colour == -1 ? "" : String.format( "%06x", colour ); + return colour == -1 ? ISubtypeInterpreter.NONE : String.format( "%06x", colour ); }; } diff --git a/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java b/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java index a3a4810d6..2050a83e7 100644 --- a/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java +++ b/src/main/java/dan200/computercraft/shared/integration/jei/RecipeResolver.java @@ -200,7 +200,7 @@ class RecipeResolver implements IRecipeManagerPlugin for( UpgradeInfo upgrade : upgrades ) { ItemStack craftingStack = upgrade.stack; - if( !craftingStack.isEmpty() && craftingStack.getItem() == stack.getItem() && upgrade.upgrade.isItemSuitable( stack ) ) + if( craftingStack.isEmpty() || craftingStack.getItem() != stack.getItem() || !upgrade.upgrade.isItemSuitable( stack ) ) { continue; } @@ -319,13 +319,6 @@ class RecipeResolver implements IRecipeManagerPlugin super( ID, null, width, height, input, output ); } - @Nonnull - @Override - public ResourceLocation getId() - { - return null; - } - @Nonnull @Override public IRecipeSerializer getSerializer()