FriedrichLP

Untitled

Mar 26th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. package friedrichlp.tsc.asm.mixins.world;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import org.spongepowered.asm.mixin.Mixin;
  7. import org.spongepowered.asm.mixin.Overwrite;
  8.  
  9. import friedrichlp.tsc.TSC;
  10. import net.minecraft.world.World;
  11. import net.minecraft.world.chunk.storage.AnvilChunkLoader;
  12. import net.minecraft.world.gen.ChunkProviderServer;
  13. import net.minecraftforge.common.chunkio.ChunkIOExecutor;
  14.  
  15. @Mixin(ChunkIOExecutor.class)
  16. public class MixinChunkIOExecutor {
  17. private static List<MixinChunkIOExecutorQueueEntry> chunksToLoad = new ArrayList<MixinChunkIOExecutorQueueEntry>();
  18. private static long ticks;
  19.  
  20. @Overwrite
  21. public static void queueChunkLoad(World world, AnvilChunkLoader loader, ChunkProviderServer provider, int x, int z, Runnable runnable) {
  22. MixinChunkIOExecutorQueueEntry e = new MixinChunkIOExecutorQueueEntry(world, loader, provider, x, z);
  23. e.callbacks.add(runnable);
  24.  
  25. chunksToLoad.add(e);
  26. }
  27.  
  28. @Overwrite
  29. public static void dropQueuedChunkLoad(World world, int x, int z, Runnable runnable) {
  30. MixinChunkIOExecutorQueueEntry entry = null;
  31.  
  32. for (MixinChunkIOExecutorQueueEntry e : chunksToLoad) {
  33. if (e.x == x && e.z == z) {
  34. e.callbacks.remove(runnable);
  35.  
  36. if (e.callbacks.isEmpty()) {
  37. entry = e;
  38. }
  39.  
  40. break;
  41. }
  42. }
  43.  
  44. if (entry != null) {
  45. chunksToLoad.remove(entry);
  46. }
  47. }
  48.  
  49. @Overwrite
  50. public static void tick () {
  51. if (ticks % 5 == 0) {
  52. try {
  53. TSC.WORKER_THREADS_EXECUTOR.invokeAll(chunksToLoad);
  54. } catch (InterruptedException ex) {
  55. ex.printStackTrace();
  56. }
  57.  
  58. List<MixinChunkIOExecutorQueueEntry> toRemove = new ArrayList<MixinChunkIOExecutorQueueEntry>();
  59. chunksToLoad.forEach(e -> {
  60. if (e.run) {
  61. e.finish();
  62. toRemove.add(e);
  63. }
  64. });
  65.  
  66. chunksToLoad.removeAll(toRemove);
  67. }
  68.  
  69. ticks++;
  70. }
  71. }
Add Comment
Please, Sign In to add comment