SuperMartijn642 / Rechiseled

12 stars 13 forks source link

Fix HWYLA compatibility #105

Open wallabra opened 3 weeks ago

wallabra commented 3 weeks ago

NOTE: This is a tentative fix implementation that has not yet been tested and is prone to change.

Using Rechiseled with HWYLA on 1.12.2 caused crashes, because HWYLA would call getPickBlock, which ends up calling net.minecraft.block.BlockPlanks.damageDropped which tries to get the block state's BlockPlanks.EnumType, which of course will not exist for Rechiseled blocks because they (unlike vanilla plank blocks) do not store the wood type in the block state.

This is the actual error message I was getting:

java.lang.IllegalArgumentException: Cannot get property PropertyEnum{name=variant, clazz=class net.minecraft.block.BlockPlanks$EnumType, values=[oak, spruce, birch, jungle, acacia, dark_oak]} as it does not exist in BlockStateContainer{block=rechiseled:acacia_planks_mosaic, properties=[]}
    at net.minecraft.block.state.BlockStateContainer$StateImplementation.getValue(BlockStateContainer.java:201) ~[awu$a.class:?]
    at net.minecraft.block.BlockPlanks.damageDropped(SourceFile:26) ~[asr.class:?]
    at com.supermartijn642.core.block.BaseBlock.damageDropped(BaseBlock.java:99) ~[BaseBlock.class:?]
    at net.minecraft.block.Block.getItem(Block.java:832) ~[aow.class:?]
    at net.minecraft.block.Block.getPickBlock(Block.java:1590) ~[aow.class:?]
    at com.supermartijn642.core.block.BaseBlock.getPickBlock(BaseBlock.java:192) ~[BaseBlock.class:?]
    at mcp.mobius.waila.api.impl.DataAccessorCommon.set(DataAccessorCommon.java:61) ~[DataAccessorCommon.class:?]
    at mcp.mobius.waila.api.impl.DataAccessorCommon.set(DataAccessorCommon.java:44) ~[DataAccessorCommon.class:?]
    at mcp.mobius.waila.overlay.WailaTickHandler.tickClient(WailaTickHandler.java:76) ~[WailaTickHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_352_WailaTickHandler_tickClient_ClientTickEvent.invoke(.dynamic) ~[?:?]
    at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?]
    at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:182) [EventBus.class:?]
    at net.minecraftforge.fml.common.FMLCommonHandler.onPreClientTick(FMLCommonHandler.java:344) [FMLCommonHandler.class:?]
    at net.minecraft.client.Minecraft.runTick(Minecraft.java:1708) [bib.class:?]
    at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1098) [bib.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:4614) [bib.class:?]
    at net.minecraft.client.main.Main.main(SourceFile:123) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_402]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_402]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_402]
    at java.lang.reflect.Method.invoke(Method.java:503) ~[?:1.8.0_402]

This seeks to fix that, not by altering which block state is stored in the save data, but simply by - only when appopriate! - adding the BlockPlanks.VARIANT (EnumType) property in the IBlockState created by a RechiseledBlock.

Currently in draft mode because I'm having trouble building this, but I'm happy if you are able to look into this issue yourself (and maybe look at the code I wrote, I'm not very experienced at this, Minecraft isn't the kind of modding I'm used to).

wallabra commented 3 weeks ago

While this compiles just fine so far, the same error appears, which leads me to believe the BlockState being built is not the one being accessed in the getPickBlock call tree. I'll have to take a look at this tomorrow.