Update light mixins

ClientboundLevelChunkWithLightPacket now also causes the LightUpdater to
notify its listeners
This commit is contained in:
PepperCode1 2023-08-23 11:06:34 -07:00
parent ecc3c2d925
commit 4c94abc2e8
2 changed files with 33 additions and 16 deletions

View file

@ -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());
}
}

View file

@ -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);
});
}