TerraformersMC / Campanion

A camping companion mod that adds items and utilities to improve your life away from home
GNU Lesser General Public License v3.0
81 stars 31 forks source link

Dependency on Indigo internal classes breaks with Canvas (or any other renderer) #100

Closed grondag closed 3 years ago

grondag commented 3 years ago

RopeBridgePostBlockEntityRenderer depends directly on Indigo's block render context which isn't available when another renderer is present.

The resulting crash looks like this:

java.lang.ClassCastException: class grondag.canvas.apiimpl.mesh.MeshImpl cannot be cast to class net.fabricmc.fabric.impl.client.indigo.renderer.mesh.MeshImpl (grondag.canvas.apiimpl.mesh.MeshImpl and net.fabricmc.fabric.impl.client.indigo.renderer.mesh.MeshImpl are in unnamed module of loader net.fabricmc.loader.launch.knot.KnotClassLoader @5ddeb7cb)
    at net.fabricmc.fabric.impl.client.indigo.renderer.render.AbstractMeshConsumer.accept(AbstractMeshConsumer.java:69)
    at net.fabricmc.fabric.impl.client.indigo.renderer.render.AbstractMeshConsumer.accept(AbstractMeshConsumer.java:40)
    at com.terraformersmc.campanion.client.model.block.BridgePlanksBakedModel$StaticPlanksModel.emitBlockQuads(BridgePlanksBakedModel.java:122)
    at net.fabricmc.fabric.impl.client.indigo.renderer.render.BlockRenderContext.render(BlockRenderContext.java:112)
    at com.terraformersmc.campanion.client.renderer.blockentity.RopeBridgePostBlockEntityRenderer.lambda$render$0(RopeBridgePostBlockEntityRenderer.java:42)
    at java.base/java.util.HashMap.forEach(HashMap.java:1425)
    at com.terraformersmc.campanion.client.renderer.blockentity.RopeBridgePostBlockEntityRenderer.render(RopeBridgePostBlockEntityRenderer.java:36)
    at com.terraformersmc.campanion.client.renderer.blockentity.RopeBridgePostBlockEntityRenderer.method_3569(RopeBridgePostBlockEntityRenderer.java:23)
    at net.minecraft.class_824.method_23079(class_824.java:107)
    at net.minecraft.class_824.method_23081(class_824.java:96)
    at net.minecraft.class_824.method_3554(class_824.java:128)
    at net.minecraft.class_824.method_3555(class_824.java:96)
    at grondag.canvas.render.CanvasWorldRenderer.renderWorld(CanvasWorldRenderer.java:604)
    at grondag.canvas.render.CanvasWorldRenderer.method_22710(CanvasWorldRenderer.java:1165)
    at net.minecraft.class_757.method_3188(class_757.java:727)
    at net.minecraft.class_757.method_3192(class_757.java:546)
    at net.minecraft.class_310.method_1523(class_310.java:1048)
    at net.minecraft.class_310.method_1514(class_310.java:681)
    at net.minecraft.client.main.Main.main(Main.java:215)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at net.fabricmc.loader.game.MinecraftGameProvider.launch(MinecraftGameProvider.java:224)
    at net.fabricmc.loader.launch.knot.Knot.init(Knot.java:141)
    at net.fabricmc.loader.launch.knot.KnotClient.main(KnotClient.java:27)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at org.multimc.onesix.OneSixLauncher.launchWithMainClass(OneSixLauncher.java:196)
    at org.multimc.onesix.OneSixLauncher.launch(OneSixLauncher.java:231)
    at org.multimc.EntryPoint.listen(EntryPoint.java:143)
    at org.multimc.EntryPoint.main(EntryPoint.java:34)

There is currently no supported way to get access to a RenderContext in a block entity renderer. Probably the best way to fix this now is to pass your FabricBakedModel instances to BlockModelRenderer.renderBlockAsEntity(). Both Indigo and Canvas Intercept those calls and pass the model to a BlockRenderContext.

If that is not viable or you have questions please ping me on Discord and I'll try to help.

Referencing the Canvas issue here: https://github.com/grondag/canvas/issues/128