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; package com.jozufozu.flywheel.mixin.light;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; 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.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 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.core.SectionPos;
import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.LightLayer;
import net.minecraft.world.level.chunk.ChunkSource; 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) @Mixin(ClientChunkCache.class)
public abstract class LightUpdateMixin extends ChunkSource { public abstract class LightUpdateMixin extends ChunkSource {
@Shadow
@Final
ClientLevel level;
/** /**
* JUSTIFICATION: This method is called after a lighting tick once per subchunk where a * 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, * the rendering system that it needs to redraw a chunk. It does all that work asynchronously,
* and we should too. * and we should too.
*/ */
@Inject(at = @At("HEAD"), method = "onLightUpdate") @Inject(method = "onLightUpdate(Lnet/minecraft/world/level/LightLayer;Lnet/minecraft/core/SectionPos;)V", at = @At("HEAD"))
private void onLightUpdate(LightLayer type, SectionPos pos, CallbackInfo ci) { private void flywheel$onLightUpdate(LightLayer layer, SectionPos pos, CallbackInfo ci) {
ClientChunkCache thi = ((ClientChunkCache) (Object) this); LightUpdater.get(level)
ClientLevel world = (ClientLevel) thi.getLevel(); .onLightUpdate(layer, pos.asLong());
LightUpdater.get(world)
.onLightUpdate(type, pos.asLong());
} }
} }

View file

@ -1,6 +1,7 @@
package com.jozufozu.flywheel.mixin.light; package com.jozufozu.flywheel.mixin.light;
import org.spongepowered.asm.mixin.Mixin; 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.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 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.backend.RenderWork;
import com.jozufozu.flywheel.light.LightUpdater; import com.jozufozu.flywheel.light.LightUpdater;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel; import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.multiplayer.ClientPacketListener; import net.minecraft.client.multiplayer.ClientPacketListener;
import net.minecraft.network.protocol.game.ClientboundLevelChunkWithLightPacket;
import net.minecraft.network.protocol.game.ClientboundLightUpdatePacket; import net.minecraft.network.protocol.game.ClientboundLightUpdatePacket;
@Mixin(ClientPacketListener.class) @Mixin(ClientPacketListener.class)
public class NetworkLightUpdateMixin { public class NetworkLightUpdateMixin {
@Shadow
private ClientLevel level;
@Inject(at = @At("TAIL"), method = "handleLightUpdatePacket") @Inject(method = "handleLevelChunkWithLight(Lnet/minecraft/network/protocol/game/ClientboundLevelChunkWithLightPacket;)V", at = @At("TAIL"))
private void onLightPacket(ClientboundLightUpdatePacket packet, CallbackInfo ci) { private void flywheel$onLevelChunkWithLight(ClientboundLevelChunkWithLightPacket packet, CallbackInfo ci) {
RenderWork.enqueue(() -> { RenderWork.enqueue(() -> {
ClientLevel world = Minecraft.getInstance().level; ClientLevel level = this.level;
if (world == null) return; if (level == null) return;
int chunkX = packet.getX(); int chunkX = packet.getX();
int chunkZ = packet.getZ(); 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); .onLightPacket(chunkX, chunkZ);
}); });
} }