Skip to content

Commit

Permalink
Fix custom ShaderInstance class crash
Browse files Browse the repository at this point in the history
  • Loading branch information
BluSpring committed Jan 9, 2025
1 parent 2a44999 commit 0090005
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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<Pair<ShaderInstance, Consumer<ShaderInstance>>> list) {
ModLoader.get().postEvent(new RegisterShadersEvent(resourceProvider, list));
}
}
24 changes: 0 additions & 24 deletions src/main/kotlin/xyz/bluspring/kilt/client/KiltClient.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -207,25 +202,6 @@ class KiltClient : ClientModInitializer {
}
}

CoreShaderRegistrationCallback.EVENT.register {
for (mod in Kilt.loader.mods) {
ModLoadingContext.kiltActiveModId = mod.modId

val shaderList = mutableListOf<Pair<ShaderInstance, Consumer<ShaderInstance>>>()
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)
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/kilt_forge_injects.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 0090005

Please sign in to comment.