Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package friedrichlp.tsc.asm.mixins.world;
- import java.util.ArrayList;
- import java.util.List;
- import org.spongepowered.asm.mixin.Mixin;
- import org.spongepowered.asm.mixin.Overwrite;
- import friedrichlp.tsc.TSC;
- import net.minecraft.world.World;
- import net.minecraft.world.chunk.storage.AnvilChunkLoader;
- import net.minecraft.world.gen.ChunkProviderServer;
- import net.minecraftforge.common.chunkio.ChunkIOExecutor;
- @Mixin(ChunkIOExecutor.class)
- public class MixinChunkIOExecutor {
- private static List<MixinChunkIOExecutorQueueEntry> chunksToLoad = new ArrayList<MixinChunkIOExecutorQueueEntry>();
- private static long ticks;
- @Overwrite
- public static void queueChunkLoad(World world, AnvilChunkLoader loader, ChunkProviderServer provider, int x, int z, Runnable runnable) {
- MixinChunkIOExecutorQueueEntry e = new MixinChunkIOExecutorQueueEntry(world, loader, provider, x, z);
- e.callbacks.add(runnable);
- chunksToLoad.add(e);
- }
- @Overwrite
- public static void dropQueuedChunkLoad(World world, int x, int z, Runnable runnable) {
- MixinChunkIOExecutorQueueEntry entry = null;
- for (MixinChunkIOExecutorQueueEntry e : chunksToLoad) {
- if (e.x == x && e.z == z) {
- e.callbacks.remove(runnable);
- if (e.callbacks.isEmpty()) {
- entry = e;
- }
- break;
- }
- }
- if (entry != null) {
- chunksToLoad.remove(entry);
- }
- }
- @Overwrite
- public static void tick () {
- if (ticks % 5 == 0) {
- try {
- TSC.WORKER_THREADS_EXECUTOR.invokeAll(chunksToLoad);
- } catch (InterruptedException ex) {
- ex.printStackTrace();
- }
- List<MixinChunkIOExecutorQueueEntry> toRemove = new ArrayList<MixinChunkIOExecutorQueueEntry>();
- chunksToLoad.forEach(e -> {
- if (e.run) {
- e.finish();
- toRemove.add(e);
- }
- });
- chunksToLoad.removeAll(toRemove);
- }
- ticks++;
- }
- }
Add Comment
Please, Sign In to add comment