<commit_before>package me.nallar.tickthreading.minecraft.patched;

import java.util.Iterator;

import me.nallar.tickthreading.Log;
import me.nallar.tickthreading.minecraft.ThreadManager;
import me.nallar.tickthreading.minecraft.TickThreading;
import net.minecraft.block.Block;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.profiler.Profiler;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraft.world.storage.ISaveHandler;

public abstract class PatchWorldServer extends WorldServer implements Runnable {
	private Iterator chunkCoordIterator;
	private ThreadManager threadManager;

	public PatchWorldServer(MinecraftServer par1MinecraftServer, ISaveHandler par2ISaveHandler, String par3Str, int par4, WorldSettings par5WorldSettings, Profiler par6Profiler) {
		super(par1MinecraftServer, par2ISaveHandler, par3Str, par4, par5WorldSettings, par6Profiler);
	}

	public void construct() {
		threadManager = new ThreadManager(TickThreading.instance.getThreadCount(), "Chunk Updates for " + Log.name(this));
	}

	public long startTime = 0;

	@Override
	protected void tickBlocksAndAmbiance() {
		TickThreading tickThreading = TickThreading.instance;
		boolean concurrentTicks = tickThreading.enableChunkTickThreading && !mcServer.theProfiler.profilingEnabled;

		if (concurrentTicks) {
			threadManager.waitForCompletion();
		}

		doneChunks.retainAll(activeChunkSet);
		if (doneChunks.size() == activeChunkSet.size()) {
			doneChunks.clear();
		}

		chunkCoordIterator = this.activeChunkSet.iterator();

		startTime = System.nanoTime();

		if (concurrentTicks) {
			for (int i = 0; i < threadManager.size(); i++) {
				threadManager.run(this);
			}
		} else {
			run();
		}
	}

	@Override
	public void run() {
		double tpsFactor = MinecraftServer.getTPS() / 20;
		while (true) {
			ChunkCoordIntPair var4;
			synchronized (chunkCoordIterator) {
				if (!chunkCoordIterator.hasNext()) {
					break;
				}
				var4 = (ChunkCoordIntPair) chunkCoordIterator.next();
			}

			if (Math.random() > tpsFactor) {
				continue;
			}

			if (!this.chunkExists(var4.chunkXPos, var4.chunkZPos)) {
				continue;
			}
			int xPos = var4.chunkXPos * 16;
			int zPos = var4.chunkZPos * 16;
			Chunk chunk = this.getChunkFromChunkCoords(var4.chunkXPos, var4.chunkZPos);
			this.moodSoundAndLightCheck(xPos, zPos, chunk);
			//Limits and evenly distributes the lighting update time
			if (System.nanoTime() - startTime <= 4000000 && doneChunks.add(var4)) {
				chunk.updateSkylight();
			}
			int var8;
			int var9;
			int var10;
			int var11;

			if (provider.canDoLightning(chunk) && this.rand.nextInt(100000) == 0 && this.isRaining() && this.isThundering()) {
				this.updateLCG = this.updateLCG * 3 + 1013904223;
				var8 = this.updateLCG >> 2;<commit_msg>Always .updateSkylight() to avoid work maintaining the list of done chunks, don't make unnecessary random calls.<commit_after>package me.nallar.tickthreading.minecraft.patched;

import java.util.Iterator;

import me.nallar.tickthreading.Log;
import me.nallar.tickthreading.minecraft.ThreadManager;
import me.nallar.tickthreading.minecraft.TickThreading;
import net.minecraft.block.Block;
import net.minecraft.entity.effect.EntityLightningBolt;
import net.minecraft.profiler.Profiler;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.WorldServer;
import net.minecraft.world.WorldSettings;
import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
import net.minecraft.world.storage.ISaveHandler;

public abstract class PatchWorldServer extends WorldServer implements Runnable {
	private Iterator chunkCoordIterator;
	private ThreadManager threadManager;

	public PatchWorldServer(MinecraftServer par1MinecraftServer, ISaveHandler par2ISaveHandler, String par3Str, int par4, WorldSettings par5WorldSettings, Profiler par6Profiler) {
		super(par1MinecraftServer, par2ISaveHandler, par3Str, par4, par5WorldSettings, par6Profiler);
	}

	public void construct() {
		threadManager = new ThreadManager(TickThreading.instance.getThreadCount(), "Chunk Updates for " + Log.name(this));
	}

	public long startTime = 0;

	@Override
	protected void tickBlocksAndAmbiance() {
		TickThreading tickThreading = TickThreading.instance;
		boolean concurrentTicks = tickThreading.enableChunkTickThreading && !mcServer.theProfiler.profilingEnabled;

		if (concurrentTicks) {
			threadManager.waitForCompletion();
		}

		chunkCoordIterator = this.activeChunkSet.iterator();

		startTime = System.nanoTime();

		if (concurrentTicks) {
			for (int i = 0; i < threadManager.size(); i++) {
				threadManager.run(this);
			}
		} else {
			run();
		}
	}

	@Override
	public void run() {
		double tpsFactor = MinecraftServer.getTPS() / 20;
		while (true) {
			ChunkCoordIntPair var4;
			synchronized (chunkCoordIterator) {
				if (!chunkCoordIterator.hasNext()) {
					break;
				}
				var4 = (ChunkCoordIntPair) chunkCoordIterator.next();
			}

			if (tpsFactor < 1 && this.rand.nextFloat() > tpsFactor) {
				continue;
			}

			if (!this.chunkExists(var4.chunkXPos, var4.chunkZPos)) {
				continue;
			}
			int xPos = var4.chunkXPos * 16;
			int zPos = var4.chunkZPos * 16;
			Chunk chunk = this.getChunkFromChunkCoords(var4.chunkXPos, var4.chunkZPos);
			this.moodSoundAndLightCheck(xPos, zPos, chunk);
			chunk.updateSkylight();
			int var8;
			int var9;
			int var10;
			int var11;

			if (provider.canDoLightning(chunk) && this.rand.nextInt(100000) == 0 && this.isRaining() && this.isThundering()) {
				this.updateLCG = this.updateLCG * 3 + 1013904223;
				var8 = this.updateLCG >> 2;
{'fraction_non_alphanumeric': 0.10717271359304464, 'fraction_numerical': 0.019561946162849023, 'mean_word_length': 4.841796875, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2278976', 'n_tokens_mistral': 2163, 'n_tokens_neox': 1936, 'n_words': 382}