FriedrichLP

Untitled

Mar 26th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. package friedrichlp.tsc.asm.mixins.world;
  2.  
  3. import java.io.IOException;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import java.util.concurrent.Callable;
  7.  
  8. import net.minecraft.nbt.NBTTagCompound;
  9. import net.minecraft.util.math.ChunkPos;
  10. import net.minecraft.world.World;
  11. import net.minecraft.world.chunk.Chunk;
  12. import net.minecraft.world.chunk.storage.AnvilChunkLoader;
  13. import net.minecraft.world.gen.ChunkProviderServer;
  14. import net.minecraftforge.common.MinecraftForge;
  15. import net.minecraftforge.event.world.ChunkDataEvent;
  16.  
  17. public class MixinChunkIOExecutorQueueEntry implements Callable<Void> {
  18. public World w;
  19. public AnvilChunkLoader loader;
  20. public ChunkProviderServer provider;
  21. public int x;
  22. public int z;
  23. public List<Runnable> callbacks = new ArrayList<Runnable>();
  24. public boolean run;
  25.  
  26. public Chunk c;
  27. public NBTTagCompound nbt;
  28.  
  29. public MixinChunkIOExecutorQueueEntry (World w, AnvilChunkLoader loader, ChunkProviderServer provider, int x, int z) {
  30. this.w = w;
  31. this.loader = loader;
  32. this.provider = provider;
  33. this.x = x;
  34. this.z = z;
  35. }
  36.  
  37. public void runCallbacks () {
  38. this.callbacks.forEach(Runnable::run);
  39. }
  40.  
  41. public void finish () {
  42. if (this.c == null) {
  43. this.runCallbacks();
  44. return;
  45. }
  46.  
  47. // Load Entities
  48. this.loader.loadEntities(this.w, this.nbt.getCompoundTag("Level"), this.c);
  49.  
  50. MinecraftForge.EVENT_BUS.post(new ChunkDataEvent.Load(this.c, this.nbt)); // Don't call ChunkDataEvent.Load async
  51.  
  52. this.c.setLastSaveTime(provider.world.getTotalWorldTime());
  53. this.provider.chunkGenerator.recreateStructures(this.c, this.x, this.z);
  54.  
  55. provider.id2ChunkMap.put(ChunkPos.asLong(this.x, this.z), this.c);
  56. this.c.onLoad();
  57. this.c.populate(provider, provider.chunkGenerator);
  58.  
  59. this.runCallbacks();
  60. }
  61.  
  62. @Override
  63. public Void call() throws Exception {
  64. try {
  65. Object[] data = null;
  66. try {
  67. data = this.loader.loadChunk__Async(this.w, this.x, this.z);
  68. } catch (IOException e) {
  69. throw new RuntimeException(e); // Allow exception to bubble up to afterExecute
  70. }
  71.  
  72. if (data != null) {
  73. this.nbt = (NBTTagCompound)data[1];
  74. this.c = (Chunk)data[0];
  75. }
  76. } finally {
  77. this.run = true;
  78. }
  79.  
  80. return null;
  81. }
  82. }
Add Comment
Please, Sign In to add comment