Skip to content

Commit

Permalink
Add for 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
dordsor21 committed Dec 26, 2024
1 parent 1a02f2d commit e66d77b
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.fastasyncworldedit.bukkit.adapter.BukkitGetBlocks;
import com.fastasyncworldedit.bukkit.adapter.DelegateSemaphore;
import com.fastasyncworldedit.bukkit.adapter.NativeEntityFunctionSet;
import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Settings;
Expand All @@ -17,6 +18,7 @@
import com.fastasyncworldedit.core.util.NbtUtils;
import com.fastasyncworldedit.core.util.collection.AdaptedMap;
import com.sk89q.worldedit.bukkit.BukkitAdapter;
import com.sk89q.worldedit.bukkit.BukkitEntity;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
Expand Down Expand Up @@ -148,11 +150,13 @@ public PaperweightGetBlocks(ServerLevel serverLevel, int chunkX, int chunkZ) {
this.chunkPos = new IntPair(chunkX, chunkZ);
}

public int getChunkX() {
@Override
public int getX() {
return chunkX;
}

public int getChunkZ() {
@Override
public int getZ() {
return chunkZ;
}

Expand Down Expand Up @@ -371,50 +375,24 @@ public int[] getHeightMap(HeightMapType type) {

@Override
public Collection<FaweCompoundTag> entities() {
ensureLoaded(serverLevel, chunkX, chunkZ);
List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk());
List<Entity> entities = PaperweightPlatformAdapter.getEntities(ensureLoaded(serverLevel, chunkX, chunkZ));
if (entities.isEmpty()) {
return Collections.emptyList();
}
int size = entities.size();
return new AbstractCollection<>() {
@Override
public int size() {
return size;
}

@Override
public boolean isEmpty() {
return false;
}

@Override
public boolean contains(Object get) {
if (!(get instanceof FaweCompoundTag getTag)) {
return false;
}
UUID getUUID = NbtUtils.uuid(getTag);
for (Entity entity : entities) {
UUID uuid = entity.getUUID();
if (uuid.equals(getUUID)) {
return true;
}
}
return false;
}

@Nonnull
@Override
public Iterator<FaweCompoundTag> iterator() {
Iterable<FaweCompoundTag> result = entities.stream().map(input -> {
CompoundTag tag = new CompoundTag();
input.save(tag);
return FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(tag));
})::iterator;
return result.iterator();
}
};
return new NativeEntityFunctionSet<>(entities, Entity::getUUID, e -> {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
e.save(tag);
return FaweCompoundTag.of(() -> (LinCompoundTag) adapter.toNativeLin(tag));
});
}

@Override
public Set<com.sk89q.worldedit.entity.Entity> getFullEntities() {
List<Entity> entities = PaperweightPlatformAdapter.getEntities(ensureLoaded(serverLevel, chunkX, chunkZ));
if (entities.isEmpty()) {
return Collections.emptySet();
}
return new NativeEntityFunctionSet<>(entities, Entity::getUUID, e -> new BukkitEntity(e.getBukkitEntity()));
}

private void removeEntity(Entity entity) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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 Holder<Biome>[][] biomes = null;
Expand All @@ -57,6 +59,8 @@ protected PaperweightGetBlocks_Copy(LevelChunk levelChunk) {
this.minHeight = serverLevel.getMinY();
this.maxHeight = serverLevel.getMaxY() - 1; // Minecraft max limit is exclusive.
this.blocks = new char[getSectionCount()][];
this.chunkX = levelChunk.locX;
this.chunkZ = levelChunk.locZ;
}

protected void storeTile(BlockEntity blockEntity) {
Expand Down Expand Up @@ -87,6 +91,11 @@ public Collection<FaweCompoundTag> entities() {
return this.entities;
}

@Override
public Set<com.sk89q.worldedit.entity.Entity> getFullEntities() {
throw new UnsupportedOperationException("Cannot get full entities from GET copy.");
}

@Override
public @Nullable FaweCompoundTag entity(final UUID uuid) {
for (FaweCompoundTag tag : entities) {
Expand Down Expand Up @@ -139,6 +148,16 @@ public int getMinSectionPosition() {
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> biome = biomes[(y >> 4) - getMinSectionPosition()][(y & 12) << 2 | (z & 12) | (x & 12) >> 2];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public Extent construct(final Extent child) {

@Override
public ProcessorScope getScope() {
return ProcessorScope.READING_SET_BLOCKS;
return ProcessorScope.READING_BLOCKS;
}

private boolean wasAdjacentToWater(char[] get, char[] set, int i, int x, int y, int z) {
Expand Down

0 comments on commit e66d77b

Please sign in to comment.