Workaround a bug in MC where light is not updated (fixes #209)

MC stores server light data and only applies it during the next frame.
Therefore, if there is no frame between receiving the chunk and block changes in
it (like when jumping in replays), then the light update from the block change
gets lost.
This commit is contained in:
Jonas Herzig
2020-06-28 17:28:22 +02:00
parent 0ba651d19c
commit 058346d247

View File

@@ -66,11 +66,14 @@ import de.johni0702.minecraft.gui.versions.callbacks.PreTickCallback;
//#endif
//#if MC>=11400
import com.replaymod.core.versions.MCVer;
import net.minecraft.network.packet.s2c.play.ChunkDataS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerActionResponseS2CPacket;
import net.minecraft.network.packet.s2c.play.OpenContainerS2CPacket;
import net.minecraft.network.packet.s2c.play.OpenWrittenBookS2CPacket;
import net.minecraft.entity.EntityType;
import net.minecraft.text.TranslatableText;
import net.minecraft.world.chunk.light.LightingProvider;
//#else
//$$ import net.minecraft.client.resources.I18n;
//$$ import net.minecraft.entity.Entity;
@@ -453,6 +456,24 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
//#endif
}
}
//#if MC>=11400
if (p instanceof ChunkDataS2CPacket) {
Runnable doLightUpdates = () -> {
if (mc.world != null) {
LightingProvider provider = mc.world.getChunkManager().getLightingProvider();
while (provider.hasUpdates()) {
provider.doLightUpdates(Integer.MAX_VALUE, true, true);
}
}
};
if (MCVer.isOnMainThread()) {
doLightUpdates.run();
} else {
MCVer.scheduleOnMainThread(doLightUpdates);
}
}
//#endif
}
} catch (Exception e) {
// We'd rather not have a failure parsing one packet screw up the whole replay process