|
2 | 2 |
|
3 | 3 | import com.fastasyncworldedit.bukkit.adapter.BukkitGetBlocks;
|
4 | 4 | import com.fastasyncworldedit.bukkit.adapter.DelegateSemaphore;
|
| 5 | +import com.fastasyncworldedit.bukkit.adapter.NativeEntityFunctionSet; |
5 | 6 | import com.fastasyncworldedit.core.Fawe;
|
6 | 7 | import com.fastasyncworldedit.core.FaweCache;
|
7 | 8 | import com.fastasyncworldedit.core.configuration.Settings;
|
|
17 | 18 | import com.fastasyncworldedit.core.util.NbtUtils;
|
18 | 19 | import com.fastasyncworldedit.core.util.collection.AdaptedMap;
|
19 | 20 | import com.sk89q.worldedit.bukkit.BukkitAdapter;
|
| 21 | +import com.sk89q.worldedit.bukkit.BukkitEntity; |
20 | 22 | import com.sk89q.worldedit.bukkit.WorldEditPlugin;
|
21 | 23 | import com.sk89q.worldedit.internal.Constants;
|
22 | 24 | import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
@@ -148,11 +150,13 @@ public PaperweightGetBlocks(ServerLevel serverLevel, int chunkX, int chunkZ) {
|
148 | 150 | this.chunkPos = new IntPair(chunkX, chunkZ);
|
149 | 151 | }
|
150 | 152 |
|
151 |
| - public int getChunkX() { |
| 153 | + @Override |
| 154 | + public int getX() { |
152 | 155 | return chunkX;
|
153 | 156 | }
|
154 | 157 |
|
155 |
| - public int getChunkZ() { |
| 158 | + @Override |
| 159 | + public int getZ() { |
156 | 160 | return chunkZ;
|
157 | 161 | }
|
158 | 162 |
|
@@ -371,50 +375,24 @@ public int[] getHeightMap(HeightMapType type) {
|
371 | 375 |
|
372 | 376 | @Override
|
373 | 377 | public Collection<FaweCompoundTag> entities() {
|
374 |
| - ensureLoaded(serverLevel, chunkX, chunkZ); |
375 |
| - List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk()); |
| 378 | + List<Entity> entities = PaperweightPlatformAdapter.getEntities(ensureLoaded(serverLevel, chunkX, chunkZ)); |
376 | 379 | if (entities.isEmpty()) {
|
377 | 380 | return Collections.emptyList();
|
378 | 381 | }
|
379 |
| - int size = entities.size(); |
380 |
| - return new AbstractCollection<>() { |
381 |
| - @Override |
382 |
| - public int size() { |
383 |
| - return size; |
384 |
| - } |
385 |
| - |
386 |
| - @Override |
387 |
| - public boolean isEmpty() { |
388 |
| - return false; |
389 |
| - } |
390 |
| - |
391 |
| - @Override |
392 |
| - public boolean contains(Object get) { |
393 |
| - if (!(get instanceof FaweCompoundTag getTag)) { |
394 |
| - return false; |
395 |
| - } |
396 |
| - UUID getUUID = NbtUtils.uuid(getTag); |
397 |
| - for (Entity entity : entities) { |
398 |
| - UUID uuid = entity.getUUID(); |
399 |
| - if (uuid.equals(getUUID)) { |
400 |
| - return true; |
401 |
| - } |
402 |
| - } |
403 |
| - return false; |
404 |
| - } |
405 |
| - |
406 |
| - @Nonnull |
407 |
| - @Override |
408 |
| - public Iterator<FaweCompoundTag> iterator() { |
409 |
| - Iterable<FaweCompoundTag> result = entities.stream().map(input -> { |
410 |
| - CompoundTag tag = new CompoundTag(); |
411 |
| - input.save(tag); |
412 |
| - return FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(tag)); |
413 |
| - })::iterator; |
414 |
| - return result.iterator(); |
415 |
| - } |
416 |
| - }; |
| 382 | + return new NativeEntityFunctionSet<>(entities, Entity::getUUID, e -> { |
| 383 | + net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag(); |
| 384 | + e.save(tag); |
| 385 | + return FaweCompoundTag.of(() -> (LinCompoundTag) adapter.toNativeLin(tag)); |
| 386 | + }); |
| 387 | + } |
417 | 388 |
|
| 389 | + @Override |
| 390 | + public Set<com.sk89q.worldedit.entity.Entity> getFullEntities() { |
| 391 | + List<Entity> entities = PaperweightPlatformAdapter.getEntities(ensureLoaded(serverLevel, chunkX, chunkZ)); |
| 392 | + if (entities.isEmpty()) { |
| 393 | + return Collections.emptySet(); |
| 394 | + } |
| 395 | + return new NativeEntityFunctionSet<>(entities, Entity::getUUID, e -> new BukkitEntity(e.getBukkitEntity())); |
418 | 396 | }
|
419 | 397 |
|
420 | 398 | private void removeEntity(Entity entity) {
|
|
0 commit comments