
UnsupportedOperationException when appendHoverText is called for a ValueTypeVariableFacade (With Solution)
leon-mandler opened this issue ยท 4 comments
Issue type:
- ๐ Bug
Short description:
When a specific type of Variable Card with a crafting recipe inside it is hovered over, the client crashed because of an UnsupportedOperationException.
Steps to reproduce the problem:
- Create a Variable Card and set it to the recipe of for example the AE2 Item Conduit
- Move the mouse over that Variable Card -> the client crashes
Expected behaviour:
The client does not crash
Versions:
- This mod: 1.25.5
- Minecraft: 1.21.1
- Mod loader version: NeoForge 21.1.115
Log file:
Closed by mistake
Solution:
I was able to fix this, by changing one line in org.cyclops.integrateddynamics.core.evaluate.variable.ValueObjectTypeItemStack in the method getItemStackDisplayNameUsSafe(ItemStack itemStack):
Before:
public static MutableComponent getItemStackDisplayNameUsSafe(ItemStack itemStack) throws NoSuchMethodException {
return !itemStack.isEmpty()
? (((MutableComponent) itemStack.getHoverName()).append((itemStack.getCount() > 1 ? " (" + itemStack.getCount() + ")" : "")))
: Component.literal("");
}
Casting the Immutable Component returned by getHoverName() to MutableComponent , still throws an exeption from ImmutableCollections when the append() method is called on it.
My quick fix:
public static MutableComponent getItemStackDisplayNameUsSafe(ItemStack itemStack) throws NoSuchMethodException {
return !itemStack.isEmpty()
? (itemStack.getHoverName().copy().append((itemStack.getCount() > 1 ? " (" + itemStack.getCount() + ")" : "")))
: Component.literal("");
}
Here a mutable MutableComponent copy of the Component is created using the Component.copy() method instead of just casting to MutableComponent.
I can not be completely sure that this is a solution that preservers the functionality from before, as I did not explore the possible effects, but it solved the crashed for me, but so far it seems perfectly functional for me and I hope it can help.
The following mods are all not at the latest version according to your log:
- Cyclops Core
- Integrated Dynamics
- Integrated Terminals
- Integrated Tunnels
- Integrated Crafting
Does this issue also happen in the latest version without any other unrelated mods installed (besides Common Capabilities)?