mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 01:37:37 +00:00
Work towards 1.16 compatibility
This commit will allow the branch to build properly but the plugin will not function properly due to the lack of a proper adapter implementation. Proceeding will require the implementation of the SideEffects system from upstream (865c3a24d2 (diff-8fd33296e427c87d0296ad7f3ccc050a)
).
This commit is contained in:
parent
aab10adb79
commit
f2bc8d86fc
@ -38,6 +38,8 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
|
||||
public final static Field fieldPalette;
|
||||
public final static Field fieldSize;
|
||||
|
||||
public final static Field fieldBitsPerEntry;
|
||||
|
||||
public final static Field fieldFluidCount;
|
||||
public final static Field fieldTickingBlockCount;
|
||||
public final static Field fieldNonEmptyBlockCount;
|
||||
@ -61,6 +63,9 @@ public final class BukkitAdapter_1_16_1 extends NMSAdapter {
|
||||
fieldPalette = DataPaletteBlock.class.getDeclaredField("h");
|
||||
fieldPalette.setAccessible(true);
|
||||
|
||||
fieldBitsPerEntry = DataBits.class.getDeclaredField("c");
|
||||
fieldBitsPerEntry.setAccessible(true);
|
||||
|
||||
fieldFluidCount = ChunkSection.class.getDeclaredField("e");
|
||||
fieldFluidCount.setAccessible(true);
|
||||
fieldTickingBlockCount = ChunkSection.class.getDeclaredField("tickingBlockCount");
|
||||
|
@ -465,7 +465,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
|
||||
tag.set("x", NBTTagInt.a(x));
|
||||
tag.set("y", NBTTagInt.a(y));
|
||||
tag.set("z", NBTTagInt.a(z));
|
||||
tileEntity.load(tag);
|
||||
tileEntity.load(tileEntity.getBlock(), tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -550,7 +550,7 @@ public class BukkitGetBlocks_1_16_1 extends CharGetBlocks {
|
||||
final DataBits bits = (DataBits) BukkitAdapter_1_16_1.fieldBits.get(blocks);
|
||||
final DataPalette<IBlockData> palette = (DataPalette<IBlockData>) BukkitAdapter_1_16_1.fieldPalette.get(blocks);
|
||||
|
||||
final int bitsPerEntry = bits.c();
|
||||
final int bitsPerEntry = (int) BukkitAdapter_1_16_1.fieldBitsPerEntry.get(bits);
|
||||
final long[] blockStates = bits.a();
|
||||
|
||||
new BitArray(bitsPerEntry, 4096, blockStates).toRaw(data);
|
||||
|
@ -34,6 +34,7 @@ import com.sk89q.worldedit.bukkit.adapter.AdapterLoadException;
|
||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
|
||||
import com.sk89q.worldedit.bukkit.adapter.BukkitImplLoader;
|
||||
import com.sk89q.worldedit.bukkit.adapter.impl.FAWE_Spigot_v1_15_R2;
|
||||
import com.sk89q.worldedit.bukkit.adapter.impl.FAWE_Spigot_v1_16_R1;
|
||||
import com.sk89q.worldedit.event.platform.CommandEvent;
|
||||
import com.sk89q.worldedit.event.platform.CommandSuggestionEvent;
|
||||
import com.sk89q.worldedit.event.platform.PlatformReadyEvent;
|
||||
@ -371,6 +372,7 @@ public class WorldEditPlugin extends JavaPlugin { //implements TabCompleter
|
||||
try {
|
||||
adapterLoader.addClass(FAWE_Spigot_v1_14_R4.class);
|
||||
adapterLoader.addClass(FAWE_Spigot_v1_15_R2.class);
|
||||
adapterLoader.addClass(FAWE_Spigot_v1_16_R1.class);
|
||||
} catch (Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
|
@ -27,6 +27,9 @@ import com.boydti.fawe.beta.IQueueExtent;
|
||||
import com.boydti.fawe.beta.implementation.packet.ChunkPacket;
|
||||
import com.boydti.fawe.beta.implementation.queue.SingleThreadQueueExtent;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_16_1.BlockMaterial_1_16_1;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_16_1.BukkitAdapter_1_16_1;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_16_1.BukkitGetBlocks_1_16_1;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_16_1.MapChunkUtil_1_16_1;
|
||||
import com.boydti.fawe.bukkit.adapter.mc1_16_1.nbt.LazyCompoundTag_1_16_1;
|
||||
import com.google.common.io.Files;
|
||||
import com.sk89q.jnbt.CompoundTag;
|
||||
@ -49,18 +52,18 @@ import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.*;
|
||||
import com.sk89q.worldedit.world.entity.EntityType;
|
||||
import com.sk89q.worldedit.world.registry.BlockMaterial;
|
||||
import net.minecraft.server.v1_15_R1.*;
|
||||
import net.minecraft.server.v1_16_R1.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World.Environment;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftChunk;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftChunk;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.block.CraftBlock;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
|
||||
@ -192,7 +195,7 @@ public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements I
|
||||
tag.set("x", NBTTagInt.a(x));
|
||||
tag.set("y", NBTTagInt.a(y));
|
||||
tag.set("z", NBTTagInt.a(z));
|
||||
tileEntity.load(tag); // readTagIntoTileEntity - load data
|
||||
tileEntity.load(tileEntity.getBlock(), tag); // readTagIntoTileEntity - load data
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -368,78 +371,80 @@ public final class FAWE_Spigot_v1_16_R1 extends CachedBukkitAdapter implements I
|
||||
|
||||
@Override
|
||||
public boolean regenerate(org.bukkit.World world, Region region, EditSession editSession) {
|
||||
WorldServer originalWorld = ((CraftWorld) world).getHandle();
|
||||
ChunkProviderServer provider = originalWorld.getChunkProvider();
|
||||
if (!(provider instanceof ChunkProviderServer)) {
|
||||
return false;
|
||||
}
|
||||
// WorldServer originalWorld = ((CraftWorld) world).getHandle();
|
||||
// ChunkProviderServer provider = originalWorld.getChunkProvider();
|
||||
// if (!(provider instanceof ChunkProviderServer)) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// File saveFolder = Files.createTempDir();
|
||||
// // register this just in case something goes wrong
|
||||
// // normally it should be deleted at the end of this method
|
||||
// saveFolder.deleteOnExit();
|
||||
// try {
|
||||
// MinecraftServer server = originalWorld.getServer().getServer();
|
||||
// Convertable.ConversionSession originalDataManager = server.convertable;
|
||||
//// Convertable.ConversionSession saveHandler = new Convertable.ConversionSession(world.getName(), world.);
|
||||
// WorldData newWorldData = new WorldData(originalWorld.worldData.a((NBTTagCompound) null),
|
||||
// server.dataConverterManager, getDataVersion(), null);
|
||||
// newWorldData.setName(UUID.randomUUID().toString());
|
||||
//
|
||||
// ChunkGenerator gen = world.getGenerator();
|
||||
// Environment env = world.getEnvironment();
|
||||
// try (WorldServer freshWorld = new WorldServer(server,
|
||||
// server.executorService, originalDataManager,
|
||||
// newWorldData,
|
||||
// originalWorld.worldProvider.getDimensionManager(),
|
||||
// originalWorld.getMethodProfiler(),
|
||||
// server.worldLoadListenerFactory.create(11),
|
||||
// env,
|
||||
// gen){
|
||||
// @Override
|
||||
// public boolean addEntityChunk(Entity entity) {
|
||||
// //Fixes #320; Prevent adding entities so we aren't attempting to spawn them asynchronously
|
||||
// return false;
|
||||
// }
|
||||
// }) {
|
||||
//
|
||||
// // Pre-gen all the chunks
|
||||
// // We need to also pull one more chunk in every direction
|
||||
// Fawe.get().getQueueHandler().startSet(true);
|
||||
// try {
|
||||
// IQueueExtent<IQueueChunk> extent = new SingleThreadQueueExtent();
|
||||
// extent.init(null, (x, z) -> new BukkitGetBlocks_1_16_1(freshWorld, x, z) {
|
||||
// @Override
|
||||
// public Chunk ensureLoaded(World nmsWorld, int X, int Z) {
|
||||
// Chunk cached = nmsWorld.getChunkIfLoaded(X, Z);
|
||||
// if (cached != null) return cached;
|
||||
// Future<Chunk> future = Fawe.get().getQueueHandler().sync((Supplier<Chunk>) () -> freshWorld.getChunkAt(X, Z));
|
||||
// while (!future.isDone()) {
|
||||
// // this feels so dirty
|
||||
// freshWorld.getChunkProvider().runTasks();
|
||||
// }
|
||||
// try {
|
||||
// return future.get();
|
||||
// } catch (InterruptedException | ExecutionException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
// }, null);
|
||||
// for (BlockVector3 vec : region) {
|
||||
// editSession.setBlock(vec, extent.getFullBlock(vec));
|
||||
// }
|
||||
// } finally {
|
||||
// Fawe.get().getQueueHandler().endSet(true);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// } catch (MaxChangedBlocksException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// } finally {
|
||||
// saveFolder.delete();
|
||||
// }
|
||||
// return true;
|
||||
|
||||
File saveFolder = Files.createTempDir();
|
||||
// register this just in case something goes wrong
|
||||
// normally it should be deleted at the end of this method
|
||||
saveFolder.deleteOnExit();
|
||||
try {
|
||||
MinecraftServer server = originalWorld.getServer().getServer();
|
||||
WorldNBTStorage originalDataManager = originalWorld.getDataManager();
|
||||
WorldNBTStorage saveHandler = new WorldNBTStorage(saveFolder, originalDataManager.getDirectory().getName(), server, originalDataManager.getDataFixer());
|
||||
WorldData newWorldData = new WorldData(originalWorld.worldData.a((NBTTagCompound) null),
|
||||
server.dataConverterManager, getDataVersion(), null);
|
||||
newWorldData.setName(UUID.randomUUID().toString());
|
||||
|
||||
ChunkGenerator gen = world.getGenerator();
|
||||
Environment env = world.getEnvironment();
|
||||
try (WorldServer freshWorld = new WorldServer(server,
|
||||
server.executorService, saveHandler,
|
||||
newWorldData,
|
||||
originalWorld.worldProvider.getDimensionManager(),
|
||||
originalWorld.getMethodProfiler(),
|
||||
server.worldLoadListenerFactory.create(11),
|
||||
env,
|
||||
gen){
|
||||
@Override
|
||||
public boolean addEntityChunk(Entity entity) {
|
||||
//Fixes #320; Prevent adding entities so we aren't attempting to spawn them asynchronously
|
||||
return false;
|
||||
}
|
||||
}) {
|
||||
|
||||
// Pre-gen all the chunks
|
||||
// We need to also pull one more chunk in every direction
|
||||
Fawe.get().getQueueHandler().startSet(true);
|
||||
try {
|
||||
IQueueExtent<IQueueChunk> extent = new SingleThreadQueueExtent();
|
||||
extent.init(null, (x, z) -> new BukkitGetBlocks_1_16_1(freshWorld, x, z) {
|
||||
@Override
|
||||
public Chunk ensureLoaded(World nmsWorld, int X, int Z) {
|
||||
Chunk cached = nmsWorld.getChunkIfLoaded(X, Z);
|
||||
if (cached != null) return cached;
|
||||
Future<Chunk> future = Fawe.get().getQueueHandler().sync((Supplier<Chunk>) () -> freshWorld.getChunkAt(X, Z));
|
||||
while (!future.isDone()) {
|
||||
// this feels so dirty
|
||||
freshWorld.getChunkProvider().runTasks();
|
||||
}
|
||||
try {
|
||||
return future.get();
|
||||
} catch (InterruptedException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
for (BlockVector3 vec : region) {
|
||||
editSession.setBlock(vec, extent.getFullBlock(vec));
|
||||
}
|
||||
} finally {
|
||||
Fawe.get().getQueueHandler().endSet(true);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} catch (MaxChangedBlocksException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
saveFolder.delete();
|
||||
}
|
||||
return true;
|
||||
return false; //TODO: rework or remove for 1.16
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user