From 2638e79aa2f6133c56d67193524dfd3336745e60 Mon Sep 17 00:00:00 2001 From: Jozufozu Date: Tue, 18 Jan 2022 13:44:28 -0800 Subject: [PATCH] Add accessor to BlockEntityRenderer map. --- .../BlockEntityRenderDispatcherAccessor.java | 16 ++++++++++++++++ .../java/com/jozufozu/flywheel/util/FlwUtil.java | 16 ++++++++++++++++ src/main/resources/flywheel.mixins.json | 1 + 3 files changed, 33 insertions(+) create mode 100644 src/main/java/com/jozufozu/flywheel/mixin/BlockEntityRenderDispatcherAccessor.java diff --git a/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityRenderDispatcherAccessor.java b/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityRenderDispatcherAccessor.java new file mode 100644 index 000000000..7f7830218 --- /dev/null +++ b/src/main/java/com/jozufozu/flywheel/mixin/BlockEntityRenderDispatcherAccessor.java @@ -0,0 +1,16 @@ +package com.jozufozu.flywheel.mixin; + +import java.util.Map; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.world.level.block.entity.BlockEntityType; + +@Mixin(BlockEntityRenderDispatcher.class) +public interface BlockEntityRenderDispatcherAccessor { + @Accessor("renderers") + Map, BlockEntityRenderer> flywheel$getRenderers(); +} diff --git a/src/main/java/com/jozufozu/flywheel/util/FlwUtil.java b/src/main/java/com/jozufozu/flywheel/util/FlwUtil.java index bcb2177d6..1d23634f6 100644 --- a/src/main/java/com/jozufozu/flywheel/util/FlwUtil.java +++ b/src/main/java/com/jozufozu/flywheel/util/FlwUtil.java @@ -1,9 +1,25 @@ package com.jozufozu.flywheel.util; import java.util.Arrays; +import java.util.Map; + +import com.jozufozu.flywheel.mixin.BlockEntityRenderDispatcherAccessor; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.world.level.block.entity.BlockEntityType; public class FlwUtil { + /** + * Get the (effectively global) map of BlockEntityTypes to Renderers. + * @return An immutable map of BlockEntityTypes to BlockEntityRenderers. + */ + public static Map, BlockEntityRenderer> getBlockEntityRenderers() { + Minecraft mc = Minecraft.getInstance(); + return ((BlockEntityRenderDispatcherAccessor) mc.getBlockEntityRenderDispatcher()).flywheel$getRenderers(); + } + public static String repeatChar(char c, int n) { char[] arr = new char[n]; diff --git a/src/main/resources/flywheel.mixins.json b/src/main/resources/flywheel.mixins.json index bbf0648db..19f34505b 100644 --- a/src/main/resources/flywheel.mixins.json +++ b/src/main/resources/flywheel.mixins.json @@ -5,6 +5,7 @@ "compatibilityLevel": "JAVA_17", "refmap": "flywheel.refmap.json", "client": [ + "BlockEntityRenderDispatcherAccessor", "BlockEntityTypeMixin", "BufferBuilderMixin", "BufferUploaderMixin",