diff --git a/src/main/java/xyz/bluspring/kilt/forgeinjects/client/renderer/GameRendererInject.java b/src/main/java/xyz/bluspring/kilt/forgeinjects/client/renderer/GameRendererInject.java new file mode 100644 index 00000000..9bd939af --- /dev/null +++ b/src/main/java/xyz/bluspring/kilt/forgeinjects/client/renderer/GameRendererInject.java @@ -0,0 +1,29 @@ +package xyz.bluspring.kilt.forgeinjects.client.renderer; + +import com.llamalad7.mixinextras.sugar.Local; +import com.mojang.datafixers.util.Pair; +import net.minecraft.client.renderer.GameRenderer; +import net.minecraft.client.renderer.ShaderInstance; +import net.minecraft.server.packs.resources.ResourceProvider; +import net.minecraftforge.client.event.RegisterShadersEvent; +import net.minecraftforge.fml.ModLoader; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.Slice; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import java.util.List; +import java.util.function.Consumer; + +@Mixin(GameRenderer.class) +public abstract class GameRendererInject { + @Inject( + method = "reloadShaders", + at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z", remap = false, shift = At.Shift.AFTER), + slice = @Slice(from = @At(value = "NEW", target = "(Lnet/minecraft/server/packs/resources/ResourceProvider;Ljava/lang/String;Lcom/mojang/blaze3d/vertex/VertexFormat;)Lnet/minecraft/client/renderer/ShaderInstance;", ordinal = 0)) + ) + private void registerShaders(ResourceProvider resourceProvider, CallbackInfo ci, @Local(ordinal = 1) List>> list) { + ModLoader.get().postEvent(new RegisterShadersEvent(resourceProvider, list)); + } +} diff --git a/src/main/kotlin/xyz/bluspring/kilt/client/KiltClient.kt b/src/main/kotlin/xyz/bluspring/kilt/client/KiltClient.kt index 57cce7d8..d2b06d32 100644 --- a/src/main/kotlin/xyz/bluspring/kilt/client/KiltClient.kt +++ b/src/main/kotlin/xyz/bluspring/kilt/client/KiltClient.kt @@ -1,7 +1,6 @@ package xyz.bluspring.kilt.client import com.google.common.collect.ImmutableMap -import com.mojang.datafixers.util.Pair import dev.architectury.event.EventResult import dev.architectury.event.events.client.ClientGuiEvent import io.github.fabricators_of_create.porting_lib.event.client.ClientWorldEvents @@ -12,7 +11,6 @@ import io.github.fabricators_of_create.porting_lib.models.geometry.RegisterGeome import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback -import net.fabricmc.fabric.api.client.rendering.v1.CoreShaderRegistrationCallback import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderContext import net.fabricmc.fabric.api.client.rendering.v1.WorldRenderEvents import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents @@ -23,8 +21,6 @@ import net.minecraft.client.gui.components.Renderable import net.minecraft.client.gui.components.events.GuiEventListener import net.minecraft.client.gui.narration.NarratableEntry import net.minecraft.client.gui.screens.Screen -import net.minecraft.client.renderer.ShaderInstance -import net.minecraft.resources.ResourceLocation import net.minecraft.world.phys.BlockHitResult import net.minecraft.world.phys.EntityHitResult import net.minecraft.world.phys.HitResult @@ -38,7 +34,6 @@ import net.minecraftforge.event.TickEvent.ClientTickEvent import net.minecraftforge.event.level.LevelEvent import net.minecraftforge.fml.LogicalSide import net.minecraftforge.fml.ModLoader -import net.minecraftforge.fml.ModLoadingContext import xyz.bluspring.kilt.Kilt import xyz.bluspring.kilt.injections.client.MinecraftInjection import xyz.bluspring.kilt.mixin.GeometryLoaderManagerAccessor @@ -207,25 +202,6 @@ class KiltClient : ClientModInitializer { } } - CoreShaderRegistrationCallback.EVENT.register { - for (mod in Kilt.loader.mods) { - ModLoadingContext.kiltActiveModId = mod.modId - - val shaderList = mutableListOf>>() - val event = RegisterShadersEvent(Minecraft.getInstance().resourceManager, shaderList) - mod.eventBus.post(event) - - for (pair in shaderList) { - val shader = pair.first - val consumer = pair.second - - it.register(ResourceLocation.tryParse(shader.name)!!, shader.vertexFormat, consumer) - } - - ModLoadingContext.kiltActiveModId = null - } - } - RenderHandCallback.EVENT.register { event -> val forgeEvent = RenderHandEvent(event.hand, event.poseStack, event.multiBufferSource, event.packedLight, event.partialTicks, event.pitch, event.swingProgress, event.equipProgress, event.itemStack) MinecraftForge.EVENT_BUS.post(forgeEvent) diff --git a/src/main/resources/kilt_forge_injects.mixins.json b/src/main/resources/kilt_forge_injects.mixins.json index 167b5bfa..1a7e9532 100644 --- a/src/main/resources/kilt_forge_injects.mixins.json +++ b/src/main/resources/kilt_forge_injects.mixins.json @@ -283,6 +283,7 @@ "client.player.RemotePlayerInject", "client.renderer.DimensionSpecialEffectsInject", "client.renderer.FogRendererInject", + "client.renderer.GameRendererInject", "client.renderer.ItemBlockRenderTypesInject", "client.renderer.ItemInHandRendererInject", "client.renderer.ItemModelShaperInject",