From ed30e5bb8dacb0ed17e66c7aefaf9401c091025e Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sat, 14 Oct 2023 20:46:11 +0100 Subject: [PATCH] Update new adapter classes --- .../fawe/v1_20_R2/PaperweightGetBlocks.java | 52 ++++++++++++++++++- .../v1_20_R2/PaperweightGetBlocks_Copy.java | 19 +++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java index d21510ff6..c4055e196 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java +++ b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks.java @@ -19,6 +19,7 @@ import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.StringTag; import com.sk89q.jnbt.Tag; import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldedit.bukkit.BukkitEntity; import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2.nbt.PaperweightLazyCompoundTag; import com.sk89q.worldedit.internal.Constants; @@ -111,11 +112,13 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc this.biomeHolderIdMap = biomeRegistry.asHolderIdMap(); } - public int getChunkX() { + @Override + public int getX() { return chunkX; } - public int getChunkZ() { + @Override + public int getZ() { return chunkZ; } @@ -355,6 +358,51 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc }; } + @Override + public Set getFullEntities() { + List entities = PaperweightPlatformAdapter.getEntities(ensureLoaded(serverLevel, chunkX, chunkZ)); + if (entities.isEmpty()) { + return Collections.emptySet(); + } + int size = entities.size(); + return new AbstractSet<>() { + @Override + public int size() { + return size; + } + + @Override + public boolean isEmpty() { + return false; + } + + @Override + public boolean contains(Object get) { + if (!(get instanceof com.sk89q.worldedit.entity.Entity e)) { + return false; + } + UUID getUUID = e.getState().getNbtData().getUUID(); + for (Entity entity : entities) { + UUID uuid = entity.getUUID(); + if (uuid.equals(getUUID)) { + return true; + } + } + return false; + } + + @Nonnull + @Override + public Iterator iterator() { + Iterable result = entities + .stream() + .map(input -> new BukkitEntity(input.getBukkitEntity())) + .collect(Collectors.toList()); + return result.iterator(); + } + }; + } + private void removeEntity(Entity entity) { entity.discard(); } diff --git a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks_Copy.java b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks_Copy.java index 428161a48..a74f6e7d7 100644 --- a/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks_Copy.java +++ b/worldedit-bukkit/adapters/adapter-1_20_2/src/main/java/com/sk89q/worldedit/bukkit/adapter/impl/fawe/v1_20_R2/PaperweightGetBlocks_Copy.java @@ -42,6 +42,8 @@ public class PaperweightGetBlocks_Copy implements IChunkGet { private final char[][] blocks; private final int minHeight; private final int maxHeight; + private final int chunkX; + private final int chunkZ; final ServerLevel serverLevel; final LevelChunk levelChunk; private PalettedContainer>[] biomes = null; @@ -52,6 +54,8 @@ public class PaperweightGetBlocks_Copy implements IChunkGet { this.minHeight = serverLevel.getMinBuildHeight(); this.maxHeight = serverLevel.getMaxBuildHeight() - 1; // Minecraft max limit is exclusive. this.blocks = new char[getSectionCount()][]; + this.chunkX = levelChunk.locX; + this.chunkZ = levelChunk.locZ; } protected void storeTile(BlockEntity blockEntity) { @@ -89,6 +93,11 @@ public class PaperweightGetBlocks_Copy implements IChunkGet { return this.entities; } + @Override + public Set getFullEntities() { + throw new UnsupportedOperationException("Cannot get full entities from GET copy."); + } + @Override public CompoundTag getEntity(UUID uuid) { for (CompoundTag tag : entities) { @@ -140,6 +149,16 @@ public class PaperweightGetBlocks_Copy implements IChunkGet { return minHeight >> 4; } + @Override + public int getX() { + return chunkX; + } + + @Override + public int getZ() { + return chunkZ; + } + @Override public BiomeType getBiomeType(int x, int y, int z) { Holder biome = biomes[(y >> 4) - getMinSectionPosition()].get(x >> 2, (y & 15) >> 2, z >> 2);