diff --git a/src/main/java/com/jozufozu/flywheel/mixin/light/LightUpdateMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/light/LightUpdateMixin.java index b4b97fe20..d11c29ede 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/light/LightUpdateMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/light/LightUpdateMixin.java @@ -1,6 +1,8 @@ package com.jozufozu.flywheel.mixin.light; +import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -12,12 +14,12 @@ import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.core.SectionPos; import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.chunk.ChunkSource; -import net.minecraftforge.api.distmarker.Dist; -import net.minecraftforge.api.distmarker.OnlyIn; -@OnlyIn(Dist.CLIENT) @Mixin(ClientChunkCache.class) public abstract class LightUpdateMixin extends ChunkSource { + @Shadow + @Final + ClientLevel level; /** * JUSTIFICATION: This method is called after a lighting tick once per subchunk where a @@ -25,12 +27,9 @@ public abstract class LightUpdateMixin extends ChunkSource { * the rendering system that it needs to redraw a chunk. It does all that work asynchronously, * and we should too. */ - @Inject(at = @At("HEAD"), method = "onLightUpdate") - private void onLightUpdate(LightLayer type, SectionPos pos, CallbackInfo ci) { - ClientChunkCache thi = ((ClientChunkCache) (Object) this); - ClientLevel world = (ClientLevel) thi.getLevel(); - - LightUpdater.get(world) - .onLightUpdate(type, pos.asLong()); + @Inject(method = "onLightUpdate(Lnet/minecraft/world/level/LightLayer;Lnet/minecraft/core/SectionPos;)V", at = @At("HEAD")) + private void flywheel$onLightUpdate(LightLayer layer, SectionPos pos, CallbackInfo ci) { + LightUpdater.get(level) + .onLightUpdate(layer, pos.asLong()); } } diff --git a/src/main/java/com/jozufozu/flywheel/mixin/light/NetworkLightUpdateMixin.java b/src/main/java/com/jozufozu/flywheel/mixin/light/NetworkLightUpdateMixin.java index d38d18fdc..2c1867fa8 100644 --- a/src/main/java/com/jozufozu/flywheel/mixin/light/NetworkLightUpdateMixin.java +++ b/src/main/java/com/jozufozu/flywheel/mixin/light/NetworkLightUpdateMixin.java @@ -1,6 +1,7 @@ package com.jozufozu.flywheel.mixin.light; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @@ -8,25 +9,42 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import com.jozufozu.flywheel.backend.RenderWork; import com.jozufozu.flywheel.light.LightUpdater; -import net.minecraft.client.Minecraft; import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientPacketListener; +import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket; import net.minecraft.network.protocol.game.ClientboundLightUpdatePacket; @Mixin(ClientPacketListener.class) public class NetworkLightUpdateMixin { + @Shadow + private ClientLevel level; - @Inject(at = @At("TAIL"), method = "handleLightUpdatePacket") - private void onLightPacket(ClientboundLightUpdatePacket packet, CallbackInfo ci) { + @Inject(method = "handleLevelChunkWithLight(Lnet/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket;)V", at = @At("TAIL")) + private void flywheel$onLevelChunkWithLight(ClientboundLevelChunkWithLightPacket packet, CallbackInfo ci) { RenderWork.enqueue(() -> { - ClientLevel world = Minecraft.getInstance().level; + ClientLevel level = this.level; - if (world == null) return; + if (level == null) return; int chunkX = packet.getX(); int chunkZ = packet.getZ(); - LightUpdater.get(world) + LightUpdater.get(level) + .onLightPacket(chunkX, chunkZ); + }); + } + + @Inject(method = "handleLightUpdatePacket(Lnet/minecraft/network/protocol/game/ClientboundLightUpdatePacket;)V", at = @At("TAIL")) + private void flywheel$onLightUpdatePacket(ClientboundLightUpdatePacket packet, CallbackInfo ci) { + RenderWork.enqueue(() -> { + ClientLevel level = this.level; + + if (level == null) return; + + int chunkX = packet.getX(); + int chunkZ = packet.getZ(); + + LightUpdater.get(level) .onLightPacket(chunkX, chunkZ); }); }