Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package friedrichlp.tsc.asm.mixins.world;
- import java.io.IOException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.concurrent.Callable;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraft.util.math.ChunkPos;
- import net.minecraft.world.World;
- import net.minecraft.world.chunk.Chunk;
- import net.minecraft.world.chunk.storage.AnvilChunkLoader;
- import net.minecraft.world.gen.ChunkProviderServer;
- import net.minecraftforge.common.MinecraftForge;
- import net.minecraftforge.event.world.ChunkDataEvent;
- public class MixinChunkIOExecutorQueueEntry implements Callable<Void> {
- public World w;
- public AnvilChunkLoader loader;
- public ChunkProviderServer provider;
- public int x;
- public int z;
- public List<Runnable> callbacks = new ArrayList<Runnable>();
- public boolean run;
- public Chunk c;
- public NBTTagCompound nbt;
- public MixinChunkIOExecutorQueueEntry (World w, AnvilChunkLoader loader, ChunkProviderServer provider, int x, int z) {
- this.w = w;
- this.loader = loader;
- this.provider = provider;
- this.x = x;
- this.z = z;
- }
- public void runCallbacks () {
- this.callbacks.forEach(Runnable::run);
- }
- public void finish () {
- if (this.c == null) {
- this.runCallbacks();
- return;
- }
- // Load Entities
- this.loader.loadEntities(this.w, this.nbt.getCompoundTag("Level"), this.c);
- MinecraftForge.EVENT_BUS.post(new ChunkDataEvent.Load(this.c, this.nbt)); // Don't call ChunkDataEvent.Load async
- this.c.setLastSaveTime(provider.world.getTotalWorldTime());
- this.provider.chunkGenerator.recreateStructures(this.c, this.x, this.z);
- provider.id2ChunkMap.put(ChunkPos.asLong(this.x, this.z), this.c);
- this.c.onLoad();
- this.c.populate(provider, provider.chunkGenerator);
- this.runCallbacks();
- }
- @Override
- public Void call() throws Exception {
- try {
- Object[] data = null;
- try {
- data = this.loader.loadChunk__Async(this.w, this.x, this.z);
- } catch (IOException e) {
- throw new RuntimeException(e); // Allow exception to bubble up to afterExecute
- }
- if (data != null) {
- this.nbt = (NBTTagCompound)data[1];
- this.c = (Chunk)data[0];
- }
- } finally {
- this.run = true;
- }
- return null;
- }
- }
Add Comment
Please, Sign In to add comment