From 39dc8c4fb58b23ee09e6c9eda831aee8e9ac4d76 Mon Sep 17 00:00:00 2001 From: Micah Date: Wed, 17 Mar 2021 23:52:14 -0700 Subject: [PATCH] Forgot to push this, it should be in the builds for 2.0.0 already --- .../micalobia/full_slabs/FullSlabsClient.java | 24 ++++++++++++++++++- .../full_slabs/util/LinkedSlabs.java | 9 ------- src/main/resources/fabric.mod.json | 3 ++- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/src/main/java/dev/micalobia/full_slabs/FullSlabsClient.java b/src/main/java/dev/micalobia/full_slabs/FullSlabsClient.java index f8f380b..cee7c8d 100644 --- a/src/main/java/dev/micalobia/full_slabs/FullSlabsClient.java +++ b/src/main/java/dev/micalobia/full_slabs/FullSlabsClient.java @@ -1,6 +1,7 @@ package dev.micalobia.full_slabs; import dev.micalobia.full_slabs.block.Blocks; +import dev.micalobia.full_slabs.block.VerticalSlabBlock; import dev.micalobia.full_slabs.client.render.model.SlabModelProvider; import dev.micalobia.full_slabs.util.LinkedSlabs; import net.fabricmc.api.ClientModInitializer; @@ -8,15 +9,36 @@ import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.blockrenderlayer.v1.BlockRenderLayerMap; import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry; +import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback; +import net.minecraft.block.Block; import net.minecraft.client.render.RenderLayer; +import net.minecraft.client.render.RenderLayers; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.Registry; @Environment(EnvType.CLIENT) public class FullSlabsClient implements ClientModInitializer { + private static BlockRenderLayerMap map; + + private static void syncRenderLayer(int i, Identifier identifier, Block block) { + syncRenderLayer(block); + } + + private static void syncRenderLayer(Block block) { + if(!(block instanceof VerticalSlabBlock)) return; + RenderLayer layer = RenderLayers.getBlockLayer(LinkedSlabs.horizontal(block).getDefaultState()); + map.putBlock(block, RenderLayer.getTranslucent()); // TODO: Figure out why using layer doesn't work unless i'm running from intellij + } + public void onInitializeClient() { ModelLoadingRegistry.INSTANCE.registerVariantProvider(vm -> new SlabModelProvider()); ModelLoadingRegistry.INSTANCE.registerResourceProvider(rm -> new SlabModelProvider()); - LinkedSlabs.correctRenderLayers(); + map = BlockRenderLayerMap.INSTANCE; + Registry.BLOCK.forEach(FullSlabsClient::syncRenderLayer); + RegistryEntryAddedCallback.event(Registry.BLOCK).register(FullSlabsClient::syncRenderLayer); BlockRenderLayerMap map = BlockRenderLayerMap.INSTANCE; map.putBlock(Blocks.FULL_SLAB_BLOCK, RenderLayer.getTranslucent()); } + + } diff --git a/src/main/java/dev/micalobia/full_slabs/util/LinkedSlabs.java b/src/main/java/dev/micalobia/full_slabs/util/LinkedSlabs.java index d8e9eeb..d7c20b7 100644 --- a/src/main/java/dev/micalobia/full_slabs/util/LinkedSlabs.java +++ b/src/main/java/dev/micalobia/full_slabs/util/LinkedSlabs.java @@ -46,15 +46,6 @@ public static boolean contains(Block... slabs) { return true; } - @Environment(EnvType.CLIENT) - public static void correctRenderLayers() { - BlockRenderLayerMap map = BlockRenderLayerMap.INSTANCE; - for(SlabBlock slab : vertical.keySet()) { - RenderLayer layer = RenderLayers.getBlockLayer(slab.getDefaultState()); - map.putBlock(vertical(slab), layer); - } - } - @NotNull public static SlabBlock horizontal(Block slab) { if(!contains(slab)) diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index ee1b5c8..b5f4a5e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -33,6 +33,7 @@ "depends": { "fabricloader": ">=0.7.4", "fabric": "*", - "minecraft": "1.16.x" + "minecraft": "1.16.x", + "micalibria": ">=1.0.2" } }