Avoid deprecated CompoundTag in API (#2883)

* Avoid deprecated CompoundTag in API

* use javax annotations
This commit is contained in:
Hannes Greule 2024-09-14 10:47:37 +02:00 committed by GitHub
parent 19370a3549
commit 1e8778b528
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
68 changed files with 1096 additions and 612 deletions

View File

@ -1,10 +1,8 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2; package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2;
import com.google.common.base.Suppliers; import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.util.ReflectionUtil; import com.sk89q.util.ReflectionUtil;
import com.sk89q.worldedit.bukkit.adapter.Refraction; import com.sk89q.worldedit.bukkit.adapter.Refraction;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.EmptyBlockGetter; import net.minecraft.world.level.EmptyBlockGetter;
@ -17,6 +15,8 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.level.material.PushReaction;
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
import javax.annotation.Nullable;
public class PaperweightBlockMaterial implements BlockMaterial { public class PaperweightBlockMaterial implements BlockMaterial {
private final Block block; private final Block block;
@ -25,7 +25,7 @@ public class PaperweightBlockMaterial implements BlockMaterial {
private final CraftBlockData craftBlockData; private final CraftBlockData craftBlockData;
private final org.bukkit.Material craftMaterial; private final org.bukkit.Material craftMaterial;
private final int opacity; private final int opacity;
private final CompoundTag tile; private final FaweCompoundTag tile;
public PaperweightBlockMaterial(Block block) { public PaperweightBlockMaterial(Block block) {
this(block, block.defaultBlockState()); this(block, block.defaultBlockState());
@ -48,7 +48,7 @@ public class PaperweightBlockMaterial implements BlockMaterial {
); );
tile = tileEntity == null tile = tileEntity == null
? null ? null
: new PaperweightLazyCompoundTag(Suppliers.memoize(tileEntity::saveWithId)); : PaperweightGetBlocks.NMS_TO_TILE.apply(tileEntity);
} }
public Block getBlock() { public Block getBlock() {
@ -173,7 +173,7 @@ public class PaperweightBlockMaterial implements BlockMaterial {
} }
@Override @Override
public CompoundTag getDefaultTile() { public @Nullable FaweCompoundTag defaultTile() {
return tile; return tile;
} }

View File

@ -5,6 +5,7 @@ import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.entity.LazyBaseEntity; import com.fastasyncworldedit.core.entity.LazyBaseEntity;
import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory; import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBatchProcessor; import com.fastasyncworldedit.core.queue.IBatchProcessor;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket; import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
@ -97,6 +98,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.OptionalInt; import java.util.OptionalInt;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -129,6 +131,12 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
this.parent = new com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R2.PaperweightAdapter(); this.parent = new com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R2.PaperweightAdapter();
} }
public Function<BlockEntity, FaweCompoundTag> blockEntityToCompoundTag() {
return blockEntity -> FaweCompoundTag.of(
() -> (LinCompoundTag) toNativeLin(blockEntity.saveWithId())
);
}
@Nullable @Nullable
private static String getEntityId(Entity entity) { private static String getEntityId(Entity entity) {
ResourceLocation resourceLocation = net.minecraft.world.entity.EntityType.getKey(entity.getType()); ResourceLocation resourceLocation = net.minecraft.world.entity.EntityType.getKey(entity.getType());

View File

@ -7,20 +7,16 @@ import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Settings; import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.math.BitArrayUnstretched; import com.fastasyncworldedit.core.math.BitArrayUnstretched;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.queue.implementation.QueueHandler; import com.fastasyncworldedit.core.queue.implementation.QueueHandler;
import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks; import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.NbtUtils;
import com.fastasyncworldedit.core.util.collection.AdaptedMap; import com.fastasyncworldedit.core.util.collection.AdaptedMap;
import com.google.common.base.Suppliers;
import com.sk89q.jnbt.CompoundTag;
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.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; 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; import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -34,6 +30,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.IdMap; import net.minecraft.core.IdMap;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos; import net.minecraft.core.SectionPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag; import net.minecraft.nbt.IntTag;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
@ -61,11 +58,19 @@ import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld; import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlock; import org.bukkit.craftbukkit.v1_20_R2.block.CraftBlock;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinDoubleTag;
import org.enginehub.linbus.tree.LinFloatTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTagType;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.AbstractSet; import javax.annotation.Nullable;
import java.util.AbstractCollection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -82,7 +87,6 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
import static net.minecraft.core.registries.Registries.BIOME; import static net.minecraft.core.registries.Registries.BIOME;
@ -91,8 +95,9 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
private static final Function<BlockPos, BlockVector3> posNms2We = v -> BlockVector3.at(v.getX(), v.getY(), v.getZ()); private static final Function<BlockPos, BlockVector3> posNms2We = v -> BlockVector3.at(v.getX(), v.getY(), v.getZ());
private static final Function<BlockEntity, CompoundTag> nmsTile2We = public static final Function<BlockEntity, FaweCompoundTag> NMS_TO_TILE = ((PaperweightFaweAdapter) WorldEditPlugin
tileEntity -> new PaperweightLazyCompoundTag(Suppliers.memoize(tileEntity::saveWithId)); .getInstance()
.getBukkitImplAdapter()).blockEntityToCompoundTag();
private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin
.getInstance() .getInstance()
.getBukkitImplAdapter()); .getBukkitImplAdapter());
@ -256,23 +261,24 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public CompoundTag getTile(int x, int y, int z) { public FaweCompoundTag tile(final int x, final int y, final int z) {
BlockEntity blockEntity = getChunk().getBlockEntity(new BlockPos((x & 15) + ( BlockEntity blockEntity = getChunk().getBlockEntity(new BlockPos((x & 15) + (
chunkX << 4), y, (z & 15) + ( chunkX << 4), y, (z & 15) + (
chunkZ << 4))); chunkZ << 4)));
if (blockEntity == null) { if (blockEntity == null) {
return null; return null;
} }
return new PaperweightLazyCompoundTag(Suppliers.memoize(blockEntity::saveWithId)); return NMS_TO_TILE.apply(blockEntity);
} }
@Override @Override
public Map<BlockVector3, CompoundTag> getTiles() { public Map<BlockVector3, FaweCompoundTag> tiles() {
Map<BlockPos, BlockEntity> nmsTiles = getChunk().getBlockEntities(); Map<BlockPos, BlockEntity> nmsTiles = getChunk().getBlockEntities();
if (nmsTiles.isEmpty()) { if (nmsTiles.isEmpty()) {
return Collections.emptyMap(); return Collections.emptyMap();
} }
return AdaptedMap.immutable(nmsTiles, posNms2We, nmsTile2We); return AdaptedMap.immutable(nmsTiles, posNms2We, NMS_TO_TILE);
} }
@Override @Override
@ -335,7 +341,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public CompoundTag getEntity(UUID uuid) { public @Nullable FaweCompoundTag entity(final UUID uuid) {
ensureLoaded(serverLevel, chunkX, chunkZ); ensureLoaded(serverLevel, chunkX, chunkZ);
List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk()); List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk());
Entity entity = null; Entity entity = null;
@ -347,10 +353,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
if (entity != null) { if (entity != null) {
org.bukkit.entity.Entity bukkitEnt = entity.getBukkitEntity(); org.bukkit.entity.Entity bukkitEnt = entity.getBukkitEntity();
return BukkitAdapter.adapt(bukkitEnt).getState().getNbtData(); return FaweCompoundTag.of(BukkitAdapter.adapt(bukkitEnt).getState().getNbt());
} }
for (CompoundTag tag : getEntities()) { for (FaweCompoundTag tag : entities()) {
if (uuid.equals(tag.getUUID())) { if (uuid.equals(NbtUtils.uuid(tag))) {
return tag; return tag;
} }
} }
@ -358,14 +364,14 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
ensureLoaded(serverLevel, chunkX, chunkZ); ensureLoaded(serverLevel, chunkX, chunkZ);
List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk()); List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk());
if (entities.isEmpty()) { if (entities.isEmpty()) {
return Collections.emptySet(); return Collections.emptyList();
} }
int size = entities.size(); int size = entities.size();
return new AbstractSet<>() { return new AbstractCollection<>() {
@Override @Override
public int size() { public int size() {
return size; return size;
@ -378,10 +384,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
@Override @Override
public boolean contains(Object get) { public boolean contains(Object get) {
if (!(get instanceof CompoundTag getTag)) { if (!(get instanceof FaweCompoundTag getTag)) {
return false; return false;
} }
UUID getUUID = getTag.getUUID(); UUID getUUID = NbtUtils.uuid(getTag);
for (Entity entity : entities) { for (Entity entity : entities) {
UUID uuid = entity.getUUID(); UUID uuid = entity.getUUID();
if (uuid.equals(getUUID)) { if (uuid.equals(getUUID)) {
@ -393,12 +399,12 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
@Nonnull @Nonnull
@Override @Override
public Iterator<CompoundTag> iterator() { public Iterator<FaweCompoundTag> iterator() {
Iterable<CompoundTag> result = entities.stream().map(input -> { Iterable<FaweCompoundTag> result = entities.stream().map(input -> {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag(); CompoundTag tag = new CompoundTag();
input.save(tag); input.save(tag);
return (CompoundTag) adapter.toNative(tag); return FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(tag));
}).collect(Collectors.toList()); })::iterator;
return result.iterator(); return result.iterator();
} }
}; };
@ -728,43 +734,42 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
}; };
} }
Set<CompoundTag> entities = set.getEntities(); Collection<FaweCompoundTag> entities = set.entities();
if (entities != null && !entities.isEmpty()) { if (entities != null && !entities.isEmpty()) {
if (syncTasks == null) { if (syncTasks == null) {
syncTasks = new Runnable[2]; syncTasks = new Runnable[2];
} }
syncTasks[1] = () -> { syncTasks[1] = () -> {
Iterator<CompoundTag> iterator = entities.iterator(); Iterator<FaweCompoundTag> iterator = entities.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next(); final FaweCompoundTag nativeTag = iterator.next();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue(); final LinCompoundTag linTag = nativeTag.linTag();
final StringTag idTag = (StringTag) entityTagMap.get("Id"); final LinStringTag idTag = linTag.findTag("Id", LinTagType.stringTag());
final ListTag posTag = (ListTag) entityTagMap.get("Pos"); final LinListTag<LinDoubleTag> posTag = linTag.findListTag("Pos", LinTagType.doubleTag());
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation"); final LinListTag<LinFloatTag> rotTag = linTag.findListTag("Rotation", LinTagType.floatTag());
if (idTag == null || posTag == null || rotTag == null) { if (idTag == null || posTag == null || rotTag == null) {
LOGGER.error("Unknown entity tag: {}", nativeTag); LOGGER.error("Unknown entity tag: {}", nativeTag);
continue; continue;
} }
final double x = posTag.getDouble(0); final double x = posTag.get(0).valueAsDouble();
final double y = posTag.getDouble(1); final double y = posTag.get(1).valueAsDouble();
final double z = posTag.getDouble(2); final double z = posTag.get(2).valueAsDouble();
final float yaw = rotTag.getFloat(0); final float yaw = rotTag.get(0).valueAsFloat();
final float pitch = rotTag.getFloat(1); final float pitch = rotTag.get(1).valueAsFloat();
final String id = idTag.getValue(); final String id = idTag.value();
EntityType<?> type = EntityType.byString(id).orElse(null); EntityType<?> type = EntityType.byString(id).orElse(null);
if (type != null) { if (type != null) {
Entity entity = type.create(nmsWorld); Entity entity = type.create(nmsWorld);
if (entity != null) { if (entity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative( final CompoundTag tag = (CompoundTag) adapter.fromNativeLin(linTag);
nativeTag);
for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name); tag.remove(name);
} }
entity.load(tag); entity.load(tag);
entity.absMoveTo(x, y, z, yaw, pitch); entity.absMoveTo(x, y, z, yaw, pitch);
entity.setUUID(nativeTag.getUUID()); entity.setUUID(NbtUtils.uuid(nativeTag));
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) { if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn( LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`", "Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
@ -784,15 +789,15 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
// set tiles // set tiles
Map<BlockVector3, CompoundTag> tiles = set.getTiles(); Map<BlockVector3, FaweCompoundTag> tiles = set.tiles();
if (tiles != null && !tiles.isEmpty()) { if (tiles != null && !tiles.isEmpty()) {
if (syncTasks == null) { if (syncTasks == null) {
syncTasks = new Runnable[1]; syncTasks = new Runnable[1];
} }
syncTasks[0] = () -> { syncTasks[0] = () -> {
for (final Map.Entry<BlockVector3, CompoundTag> entry : tiles.entrySet()) { for (final Map.Entry<BlockVector3, FaweCompoundTag> entry : tiles.entrySet()) {
final CompoundTag nativeTag = entry.getValue(); final FaweCompoundTag nativeTag = entry.getValue();
final BlockVector3 blockHash = entry.getKey(); final BlockVector3 blockHash = entry.getKey();
final int x = blockHash.x() + bx; final int x = blockHash.x() + bx;
final int y = blockHash.y(); final int y = blockHash.y();
@ -806,8 +811,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
tileEntity = nmsWorld.getBlockEntity(pos); tileEntity = nmsWorld.getBlockEntity(pos);
} }
if (tileEntity != null) { if (tileEntity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative( final CompoundTag tag = (CompoundTag) adapter.fromNativeLin(nativeTag.linTag());
nativeTag);
tag.put("x", IntTag.valueOf(x)); tag.put("x", IntTag.valueOf(x));
tag.put("y", IntTag.valueOf(y)); tag.put("y", IntTag.valueOf(y));
tag.put("z", IntTag.valueOf(z)); tag.put("z", IntTag.valueOf(z));

View File

@ -1,14 +1,13 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2; package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBlocks; import com.fastasyncworldedit.core.queue.IBlocks;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.google.common.base.Suppliers; import com.fastasyncworldedit.core.util.NbtUtils;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R2.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -17,6 +16,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
@ -25,9 +25,11 @@ import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.PalettedContainer; import net.minecraft.world.level.chunk.PalettedContainer;
import net.minecraft.world.level.chunk.PalettedContainerRO; import net.minecraft.world.level.chunk.PalettedContainerRO;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
@ -39,8 +41,8 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
private final Map<BlockVector3, CompoundTag> tiles = new HashMap<>(); private final Map<BlockVector3, FaweCompoundTag> tiles = new HashMap<>();
private final Set<CompoundTag> entities = new HashSet<>(); private final Set<FaweCompoundTag> entities = new HashSet<>();
private final char[][] blocks; private final char[][] blocks;
private final int minHeight; private final int minHeight;
private final int maxHeight; private final int maxHeight;
@ -57,44 +59,35 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
} }
protected void storeTile(BlockEntity blockEntity) { protected void storeTile(BlockEntity blockEntity) {
@SuppressWarnings("unchecked")
BukkitImplAdapter<Tag> adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
tiles.put( tiles.put(
BlockVector3.at( BlockVector3.at(
blockEntity.getBlockPos().getX(), blockEntity.getBlockPos().getX(),
blockEntity.getBlockPos().getY(), blockEntity.getBlockPos().getY(),
blockEntity.getBlockPos().getZ() blockEntity.getBlockPos().getZ()
), ),
new PaperweightLazyCompoundTag(Suppliers.memoize(blockEntity::saveWithId)) FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(blockEntity.saveWithId()))
); );
} }
@Override
public Map<BlockVector3, CompoundTag> getTiles() {
return tiles;
}
@Override
@Nullable
public CompoundTag getTile(int x, int y, int z) {
return tiles.get(BlockVector3.at(x, y, z));
}
@SuppressWarnings({"unchecked", "rawtypes"})
protected void storeEntity(Entity entity) { protected void storeEntity(Entity entity) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); @SuppressWarnings("unchecked")
BukkitImplAdapter<Tag> adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag(); net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag();
entity.save(compoundTag); entity.save(compoundTag);
entities.add((CompoundTag) adapter.toNative(compoundTag)); entities.add(FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(compoundTag)));
} }
@Override @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
return this.entities; return this.entities;
} }
@Override @Override
public CompoundTag getEntity(UUID uuid) { public @Nullable FaweCompoundTag entity(final UUID uuid) {
for (CompoundTag tag : entities) { for (FaweCompoundTag tag : entities) {
if (uuid.equals(tag.getUUID())) { if (uuid.equals(NbtUtils.uuid(tag))) {
return tag; return tag;
} }
} }
@ -205,7 +198,7 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
@Override @Override
public BaseBlock getFullBlock(int x, int y, int z) { public BaseBlock getFullBlock(int x, int y, int z) {
BlockState state = BlockTypesCache.states[get(x, y, z)]; BlockState state = BlockTypesCache.states[get(x, y, z)];
return state.toBaseBlock(this, x, y, z); return state.toBaseBlock((IBlocks) this, x, y, z);
} }
@Override @Override
@ -235,6 +228,16 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
return BlockTypesCache.states[get(x, y, z)]; return BlockTypesCache.states[get(x, y, z)];
} }
@Override
public Map<BlockVector3, FaweCompoundTag> tiles() {
return tiles;
}
@Override
public @Nullable FaweCompoundTag tile(final int x, final int y, final int z) {
return tiles.get(BlockVector3.at(x, y, z));
}
@Override @Override
public int getSkyLight(int x, int y, int z) { public int getSkyLight(int x, int y, int z) {
return 0; return 0;

View File

@ -1,8 +1,6 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R3; package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R3;
import com.google.common.base.Suppliers; import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R3.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.level.EmptyBlockGetter; import net.minecraft.world.level.EmptyBlockGetter;
@ -14,6 +12,8 @@ import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.level.material.PushReaction;
import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData; import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData;
import javax.annotation.Nullable;
public class PaperweightBlockMaterial implements BlockMaterial { public class PaperweightBlockMaterial implements BlockMaterial {
private final Block block; private final Block block;
@ -21,7 +21,7 @@ public class PaperweightBlockMaterial implements BlockMaterial {
private final CraftBlockData craftBlockData; private final CraftBlockData craftBlockData;
private final org.bukkit.Material craftMaterial; private final org.bukkit.Material craftMaterial;
private final int opacity; private final int opacity;
private final CompoundTag tile; private final FaweCompoundTag tile;
public PaperweightBlockMaterial(Block block) { public PaperweightBlockMaterial(Block block) {
this(block, block.defaultBlockState()); this(block, block.defaultBlockState());
@ -39,7 +39,7 @@ public class PaperweightBlockMaterial implements BlockMaterial {
); );
tile = tileEntity == null tile = tileEntity == null
? null ? null
: new PaperweightLazyCompoundTag(Suppliers.memoize(tileEntity::saveWithId)); : PaperweightGetBlocks.NMS_TO_TILE.apply(tileEntity);
} }
public Block getBlock() { public Block getBlock() {
@ -163,7 +163,7 @@ public class PaperweightBlockMaterial implements BlockMaterial {
} }
@Override @Override
public CompoundTag getDefaultTile() { public @Nullable FaweCompoundTag defaultTile() {
return tile; return tile;
} }

View File

@ -5,6 +5,7 @@ import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.entity.LazyBaseEntity; import com.fastasyncworldedit.core.entity.LazyBaseEntity;
import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory; import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBatchProcessor; import com.fastasyncworldedit.core.queue.IBatchProcessor;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket; import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
@ -97,6 +98,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.OptionalInt; import java.util.OptionalInt;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -129,6 +131,12 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
this.parent = new com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R3.PaperweightAdapter(); this.parent = new com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R3.PaperweightAdapter();
} }
public Function<BlockEntity, FaweCompoundTag> blockEntityToCompoundTag() {
return blockEntity -> FaweCompoundTag.of(
() -> (LinCompoundTag) toNativeLin(blockEntity.saveWithId())
);
}
@Nullable @Nullable
private static String getEntityId(Entity entity) { private static String getEntityId(Entity entity) {
ResourceLocation resourceLocation = net.minecraft.world.entity.EntityType.getKey(entity.getType()); ResourceLocation resourceLocation = net.minecraft.world.entity.EntityType.getKey(entity.getType());

View File

@ -7,20 +7,16 @@ import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Settings; import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.math.BitArrayUnstretched; import com.fastasyncworldedit.core.math.BitArrayUnstretched;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.queue.implementation.QueueHandler; import com.fastasyncworldedit.core.queue.implementation.QueueHandler;
import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks; import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.NbtUtils;
import com.fastasyncworldedit.core.util.collection.AdaptedMap; import com.fastasyncworldedit.core.util.collection.AdaptedMap;
import com.google.common.base.Suppliers;
import com.sk89q.jnbt.CompoundTag;
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.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R3.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -34,6 +30,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.IdMap; import net.minecraft.core.IdMap;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos; import net.minecraft.core.SectionPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag; import net.minecraft.nbt.IntTag;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.sounds.SoundEvents; import net.minecraft.sounds.SoundEvents;
@ -61,11 +58,19 @@ import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld; import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlock; import org.bukkit.craftbukkit.v1_20_R3.block.CraftBlock;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinDoubleTag;
import org.enginehub.linbus.tree.LinFloatTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTagType;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.AbstractSet; import javax.annotation.Nullable;
import java.util.AbstractCollection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -82,7 +87,6 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
import static net.minecraft.core.registries.Registries.BIOME; import static net.minecraft.core.registries.Registries.BIOME;
@ -91,8 +95,9 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
private static final Function<BlockPos, BlockVector3> posNms2We = v -> BlockVector3.at(v.getX(), v.getY(), v.getZ()); private static final Function<BlockPos, BlockVector3> posNms2We = v -> BlockVector3.at(v.getX(), v.getY(), v.getZ());
private static final Function<BlockEntity, CompoundTag> nmsTile2We = public static final Function<BlockEntity, FaweCompoundTag> NMS_TO_TILE = ((PaperweightFaweAdapter) WorldEditPlugin
tileEntity -> new PaperweightLazyCompoundTag(Suppliers.memoize(tileEntity::saveWithId)); .getInstance()
.getBukkitImplAdapter()).blockEntityToCompoundTag();
private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin
.getInstance() .getInstance()
.getBukkitImplAdapter()); .getBukkitImplAdapter());
@ -108,6 +113,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private final Registry<Biome> biomeRegistry; private final Registry<Biome> biomeRegistry;
private final IdMap<Holder<Biome>> biomeHolderIdMap; private final IdMap<Holder<Biome>> biomeHolderIdMap;
private final ConcurrentHashMap<Integer, PaperweightGetBlocks_Copy> copies = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Integer, PaperweightGetBlocks_Copy> copies = new ConcurrentHashMap<>();
private final Object sendLock = new Object();
private LevelChunkSection[] sections; private LevelChunkSection[] sections;
private LevelChunk levelChunk; private LevelChunk levelChunk;
private DataLayer[] blockLight; private DataLayer[] blockLight;
@ -255,23 +261,24 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public CompoundTag getTile(int x, int y, int z) { public FaweCompoundTag tile(final int x, final int y, final int z) {
BlockEntity blockEntity = getChunk().getBlockEntity(new BlockPos((x & 15) + ( BlockEntity blockEntity = getChunk().getBlockEntity(new BlockPos((x & 15) + (
chunkX << 4), y, (z & 15) + ( chunkX << 4), y, (z & 15) + (
chunkZ << 4))); chunkZ << 4)));
if (blockEntity == null) { if (blockEntity == null) {
return null; return null;
} }
return new PaperweightLazyCompoundTag(Suppliers.memoize(blockEntity::saveWithId)); return NMS_TO_TILE.apply(blockEntity);
} }
@Override @Override
public Map<BlockVector3, CompoundTag> getTiles() { public Map<BlockVector3, FaweCompoundTag> tiles() {
Map<BlockPos, BlockEntity> nmsTiles = getChunk().getBlockEntities(); Map<BlockPos, BlockEntity> nmsTiles = getChunk().getBlockEntities();
if (nmsTiles.isEmpty()) { if (nmsTiles.isEmpty()) {
return Collections.emptyMap(); return Collections.emptyMap();
} }
return AdaptedMap.immutable(nmsTiles, posNms2We, nmsTile2We); return AdaptedMap.immutable(nmsTiles, posNms2We, NMS_TO_TILE);
} }
@Override @Override
@ -334,7 +341,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public CompoundTag getEntity(UUID uuid) { public @Nullable FaweCompoundTag entity(final UUID uuid) {
ensureLoaded(serverLevel, chunkX, chunkZ); ensureLoaded(serverLevel, chunkX, chunkZ);
List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk()); List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk());
Entity entity = null; Entity entity = null;
@ -346,10 +353,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
if (entity != null) { if (entity != null) {
org.bukkit.entity.Entity bukkitEnt = entity.getBukkitEntity(); org.bukkit.entity.Entity bukkitEnt = entity.getBukkitEntity();
return BukkitAdapter.adapt(bukkitEnt).getState().getNbtData(); return FaweCompoundTag.of(BukkitAdapter.adapt(bukkitEnt).getState().getNbt());
} }
for (CompoundTag tag : getEntities()) { for (FaweCompoundTag tag : entities()) {
if (uuid.equals(tag.getUUID())) { if (uuid.equals(NbtUtils.uuid(tag))) {
return tag; return tag;
} }
} }
@ -357,14 +364,14 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
ensureLoaded(serverLevel, chunkX, chunkZ); ensureLoaded(serverLevel, chunkX, chunkZ);
List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk()); List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk());
if (entities.isEmpty()) { if (entities.isEmpty()) {
return Collections.emptySet(); return Collections.emptyList();
} }
int size = entities.size(); int size = entities.size();
return new AbstractSet<>() { return new AbstractCollection<>() {
@Override @Override
public int size() { public int size() {
return size; return size;
@ -377,10 +384,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
@Override @Override
public boolean contains(Object get) { public boolean contains(Object get) {
if (!(get instanceof CompoundTag getTag)) { if (!(get instanceof FaweCompoundTag getTag)) {
return false; return false;
} }
UUID getUUID = getTag.getUUID(); UUID getUUID = NbtUtils.uuid(getTag);
for (Entity entity : entities) { for (Entity entity : entities) {
UUID uuid = entity.getUUID(); UUID uuid = entity.getUUID();
if (uuid.equals(getUUID)) { if (uuid.equals(getUUID)) {
@ -392,12 +399,12 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
@Nonnull @Nonnull
@Override @Override
public Iterator<CompoundTag> iterator() { public Iterator<FaweCompoundTag> iterator() {
Iterable<CompoundTag> result = entities.stream().map(input -> { Iterable<FaweCompoundTag> result = entities.stream().map(input -> {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag(); net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
input.save(tag); input.save(tag);
return (CompoundTag) adapter.toNative(tag); return FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(tag));
}).collect(Collectors.toList()); })::iterator;
return result.iterator(); return result.iterator();
} }
}; };
@ -727,43 +734,42 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
}; };
} }
Set<CompoundTag> entities = set.getEntities(); Collection<FaweCompoundTag> entities = set.entities();
if (entities != null && !entities.isEmpty()) { if (entities != null && !entities.isEmpty()) {
if (syncTasks == null) { if (syncTasks == null) {
syncTasks = new Runnable[2]; syncTasks = new Runnable[2];
} }
syncTasks[1] = () -> { syncTasks[1] = () -> {
Iterator<CompoundTag> iterator = entities.iterator(); Iterator<FaweCompoundTag> iterator = entities.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next(); final FaweCompoundTag nativeTag = iterator.next();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue(); final LinCompoundTag linTag = nativeTag.linTag();
final StringTag idTag = (StringTag) entityTagMap.get("Id"); final LinStringTag idTag = linTag.findTag("Id", LinTagType.stringTag());
final ListTag posTag = (ListTag) entityTagMap.get("Pos"); final LinListTag<LinDoubleTag> posTag = linTag.findListTag("Pos", LinTagType.doubleTag());
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation"); final LinListTag<LinFloatTag> rotTag = linTag.findListTag("Rotation", LinTagType.floatTag());
if (idTag == null || posTag == null || rotTag == null) { if (idTag == null || posTag == null || rotTag == null) {
LOGGER.error("Unknown entity tag: {}", nativeTag); LOGGER.error("Unknown entity tag: {}", nativeTag);
continue; continue;
} }
final double x = posTag.getDouble(0); final double x = posTag.get(0).valueAsDouble();
final double y = posTag.getDouble(1); final double y = posTag.get(1).valueAsDouble();
final double z = posTag.getDouble(2); final double z = posTag.get(2).valueAsDouble();
final float yaw = rotTag.getFloat(0); final float yaw = rotTag.get(0).valueAsFloat();
final float pitch = rotTag.getFloat(1); final float pitch = rotTag.get(1).valueAsFloat();
final String id = idTag.getValue(); final String id = idTag.value();
EntityType<?> type = EntityType.byString(id).orElse(null); EntityType<?> type = EntityType.byString(id).orElse(null);
if (type != null) { if (type != null) {
Entity entity = type.create(nmsWorld); Entity entity = type.create(nmsWorld);
if (entity != null) { if (entity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative( final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(linTag);
nativeTag);
for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name); tag.remove(name);
} }
entity.load(tag); entity.load(tag);
entity.absMoveTo(x, y, z, yaw, pitch); entity.absMoveTo(x, y, z, yaw, pitch);
entity.setUUID(nativeTag.getUUID()); entity.setUUID(NbtUtils.uuid(nativeTag));
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) { if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn( LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`", "Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
@ -783,15 +789,15 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
// set tiles // set tiles
Map<BlockVector3, CompoundTag> tiles = set.getTiles(); Map<BlockVector3, FaweCompoundTag> tiles = set.tiles();
if (tiles != null && !tiles.isEmpty()) { if (tiles != null && !tiles.isEmpty()) {
if (syncTasks == null) { if (syncTasks == null) {
syncTasks = new Runnable[1]; syncTasks = new Runnable[1];
} }
syncTasks[0] = () -> { syncTasks[0] = () -> {
for (final Map.Entry<BlockVector3, CompoundTag> entry : tiles.entrySet()) { for (final Map.Entry<BlockVector3, FaweCompoundTag> entry : tiles.entrySet()) {
final CompoundTag nativeTag = entry.getValue(); final FaweCompoundTag nativeTag = entry.getValue();
final BlockVector3 blockHash = entry.getKey(); final BlockVector3 blockHash = entry.getKey();
final int x = blockHash.x() + bx; final int x = blockHash.x() + bx;
final int y = blockHash.y(); final int y = blockHash.y();
@ -805,8 +811,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
tileEntity = nmsWorld.getBlockEntity(pos); tileEntity = nmsWorld.getBlockEntity(pos);
} }
if (tileEntity != null) { if (tileEntity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative( final net.minecraft.nbt.CompoundTag tag = (CompoundTag) adapter.fromNativeLin(nativeTag.linTag());
nativeTag);
tag.put("x", IntTag.valueOf(x)); tag.put("x", IntTag.valueOf(x));
tag.put("y", IntTag.valueOf(y)); tag.put("y", IntTag.valueOf(y));
tag.put("z", IntTag.valueOf(z)); tag.put("z", IntTag.valueOf(z));

View File

@ -1,14 +1,13 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R3; package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R3;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBlocks; import com.fastasyncworldedit.core.queue.IBlocks;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.google.common.base.Suppliers; import com.fastasyncworldedit.core.util.NbtUtils;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R3.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -17,6 +16,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.nbt.Tag;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.world.level.biome.Biome; import net.minecraft.world.level.biome.Biome;
@ -25,9 +25,11 @@ import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.PalettedContainer; import net.minecraft.world.level.chunk.PalettedContainer;
import net.minecraft.world.level.chunk.PalettedContainerRO; import net.minecraft.world.level.chunk.PalettedContainerRO;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
@ -39,8 +41,8 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
private final Map<BlockVector3, CompoundTag> tiles = new HashMap<>(); private final Map<BlockVector3, FaweCompoundTag> tiles = new HashMap<>();
private final Set<CompoundTag> entities = new HashSet<>(); private final Set<FaweCompoundTag> entities = new HashSet<>();
private final char[][] blocks; private final char[][] blocks;
private final int minHeight; private final int minHeight;
private final int maxHeight; private final int maxHeight;
@ -57,44 +59,35 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
} }
protected void storeTile(BlockEntity blockEntity) { protected void storeTile(BlockEntity blockEntity) {
@SuppressWarnings("unchecked")
BukkitImplAdapter<Tag> adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
tiles.put( tiles.put(
BlockVector3.at( BlockVector3.at(
blockEntity.getBlockPos().getX(), blockEntity.getBlockPos().getX(),
blockEntity.getBlockPos().getY(), blockEntity.getBlockPos().getY(),
blockEntity.getBlockPos().getZ() blockEntity.getBlockPos().getZ()
), ),
new PaperweightLazyCompoundTag(Suppliers.memoize(blockEntity::saveWithId)) FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(blockEntity.saveWithId()))
); );
} }
@Override
public Map<BlockVector3, CompoundTag> getTiles() {
return tiles;
}
@Override
@Nullable
public CompoundTag getTile(int x, int y, int z) {
return tiles.get(BlockVector3.at(x, y, z));
}
@SuppressWarnings({"unchecked", "rawtypes"})
protected void storeEntity(Entity entity) { protected void storeEntity(Entity entity) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); @SuppressWarnings("unchecked")
BukkitImplAdapter<Tag> adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag(); net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag();
entity.save(compoundTag); entity.save(compoundTag);
entities.add((CompoundTag) adapter.toNative(compoundTag)); entities.add(FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(compoundTag)));
} }
@Override @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
return this.entities; return this.entities;
} }
@Override @Override
public CompoundTag getEntity(UUID uuid) { public @Nullable FaweCompoundTag entity(final UUID uuid) {
for (CompoundTag tag : entities) { for (FaweCompoundTag tag : entities) {
if (uuid.equals(tag.getUUID())) { if (uuid.equals(NbtUtils.uuid(tag))) {
return tag; return tag;
} }
} }
@ -205,7 +198,7 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
@Override @Override
public BaseBlock getFullBlock(int x, int y, int z) { public BaseBlock getFullBlock(int x, int y, int z) {
BlockState state = BlockTypesCache.states[get(x, y, z)]; BlockState state = BlockTypesCache.states[get(x, y, z)];
return state.toBaseBlock(this, x, y, z); return state.toBaseBlock((IBlocks) this, x, y, z);
} }
@Override @Override
@ -235,6 +228,16 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
return BlockTypesCache.states[get(x, y, z)]; return BlockTypesCache.states[get(x, y, z)];
} }
@Override
public Map<BlockVector3, FaweCompoundTag> tiles() {
return tiles;
}
@Override
public @Nullable FaweCompoundTag tile(final int x, final int y, final int z) {
return tiles.get(BlockVector3.at(x, y, z));
}
@Override @Override
public int getSkyLight(int x, int y, int z) { public int getSkyLight(int x, int y, int z) {
return 0; return 0;

View File

@ -1,11 +1,8 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R4; package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R4;
import com.google.common.base.Suppliers; import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R4.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.world.level.EmptyBlockGetter; import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.EntityBlock;
@ -15,6 +12,8 @@ import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.level.material.PushReaction;
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import javax.annotation.Nullable;
public class PaperweightBlockMaterial implements BlockMaterial { public class PaperweightBlockMaterial implements BlockMaterial {
private final Block block; private final Block block;
@ -22,7 +21,7 @@ public class PaperweightBlockMaterial implements BlockMaterial {
private final CraftBlockData craftBlockData; private final CraftBlockData craftBlockData;
private final org.bukkit.Material craftMaterial; private final org.bukkit.Material craftMaterial;
private final int opacity; private final int opacity;
private final CompoundTag tile; private final FaweCompoundTag tile;
public PaperweightBlockMaterial(Block block) { public PaperweightBlockMaterial(Block block) {
this(block, block.defaultBlockState()); this(block, block.defaultBlockState());
@ -38,9 +37,9 @@ public class PaperweightBlockMaterial implements BlockMaterial {
BlockPos.ZERO, BlockPos.ZERO,
blockState blockState
); );
tile = tileEntity == null ? null : new PaperweightLazyCompoundTag( tile = tileEntity == null
Suppliers.memoize(() -> tileEntity.saveWithId(DedicatedServer.getServer().registryAccess())) ? null
); : PaperweightGetBlocks.NMS_TO_TILE.apply(tileEntity);
} }
public Block getBlock() { public Block getBlock() {
@ -164,7 +163,7 @@ public class PaperweightBlockMaterial implements BlockMaterial {
} }
@Override @Override
public CompoundTag getDefaultTile() { public @Nullable FaweCompoundTag defaultTile() {
return tile; return tile;
} }

View File

@ -5,6 +5,7 @@ import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.entity.LazyBaseEntity; import com.fastasyncworldedit.core.entity.LazyBaseEntity;
import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory; import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBatchProcessor; import com.fastasyncworldedit.core.queue.IBatchProcessor;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket; import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
@ -103,6 +104,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.OptionalInt; import java.util.OptionalInt;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -138,6 +140,12 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
this.parent = new com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R4.PaperweightAdapter(); this.parent = new com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_20_R4.PaperweightAdapter();
} }
public Function<BlockEntity, FaweCompoundTag> blockEntityToCompoundTag() {
return blockEntity -> FaweCompoundTag.of(
() -> (LinCompoundTag) toNativeLin(blockEntity.saveWithId(DedicatedServer.getServer().registryAccess()))
);
}
@Nullable @Nullable
private static String getEntityId(Entity entity) { private static String getEntityId(Entity entity) {
ResourceLocation resourceLocation = net.minecraft.world.entity.EntityType.getKey(entity.getType()); ResourceLocation resourceLocation = net.minecraft.world.entity.EntityType.getKey(entity.getType());

View File

@ -7,20 +7,16 @@ import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Settings; import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.math.BitArrayUnstretched; import com.fastasyncworldedit.core.math.BitArrayUnstretched;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.queue.implementation.QueueHandler; import com.fastasyncworldedit.core.queue.implementation.QueueHandler;
import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks; import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.NbtUtils;
import com.fastasyncworldedit.core.util.collection.AdaptedMap; import com.fastasyncworldedit.core.util.collection.AdaptedMap;
import com.google.common.base.Suppliers;
import com.sk89q.jnbt.CompoundTag;
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.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R4.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -34,6 +30,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.IdMap; import net.minecraft.core.IdMap;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos; import net.minecraft.core.SectionPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag; import net.minecraft.nbt.IntTag;
import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -62,11 +59,19 @@ import org.bukkit.World;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinDoubleTag;
import org.enginehub.linbus.tree.LinFloatTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTagType;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.AbstractSet; import javax.annotation.Nullable;
import java.util.AbstractCollection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -83,7 +88,6 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
import static net.minecraft.core.registries.Registries.BIOME; import static net.minecraft.core.registries.Registries.BIOME;
@ -92,9 +96,9 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
private static final Function<BlockPos, BlockVector3> posNms2We = v -> BlockVector3.at(v.getX(), v.getY(), v.getZ()); private static final Function<BlockPos, BlockVector3> posNms2We = v -> BlockVector3.at(v.getX(), v.getY(), v.getZ());
private static final Function<BlockEntity, CompoundTag> nmsTile2We = tileEntity -> new PaperweightLazyCompoundTag( public static final Function<BlockEntity, FaweCompoundTag> NMS_TO_TILE = ((PaperweightFaweAdapter) WorldEditPlugin
Suppliers.memoize(() -> tileEntity.saveWithId(DedicatedServer.getServer().registryAccess())) .getInstance()
); .getBukkitImplAdapter()).blockEntityToCompoundTag();
private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin
.getInstance() .getInstance()
.getBukkitImplAdapter()); .getBukkitImplAdapter());
@ -258,23 +262,24 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public CompoundTag getTile(int x, int y, int z) { public FaweCompoundTag tile(final int x, final int y, final int z) {
BlockEntity blockEntity = getChunk().getBlockEntity(new BlockPos((x & 15) + ( BlockEntity blockEntity = getChunk().getBlockEntity(new BlockPos((x & 15) + (
chunkX << 4), y, (z & 15) + ( chunkX << 4), y, (z & 15) + (
chunkZ << 4))); chunkZ << 4)));
if (blockEntity == null) { if (blockEntity == null) {
return null; return null;
} }
return new PaperweightLazyCompoundTag(Suppliers.memoize(() -> blockEntity.saveWithId(DedicatedServer.getServer().registryAccess()))); return NMS_TO_TILE.apply(blockEntity);
} }
@Override @Override
public Map<BlockVector3, CompoundTag> getTiles() { public Map<BlockVector3, FaweCompoundTag> tiles() {
Map<BlockPos, BlockEntity> nmsTiles = getChunk().getBlockEntities(); Map<BlockPos, BlockEntity> nmsTiles = getChunk().getBlockEntities();
if (nmsTiles.isEmpty()) { if (nmsTiles.isEmpty()) {
return Collections.emptyMap(); return Collections.emptyMap();
} }
return AdaptedMap.immutable(nmsTiles, posNms2We, nmsTile2We); return AdaptedMap.immutable(nmsTiles, posNms2We, NMS_TO_TILE);
} }
@Override @Override
@ -337,7 +342,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public CompoundTag getEntity(UUID uuid) { public @Nullable FaweCompoundTag entity(final UUID uuid) {
ensureLoaded(serverLevel, chunkX, chunkZ); ensureLoaded(serverLevel, chunkX, chunkZ);
List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk()); List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk());
Entity entity = null; Entity entity = null;
@ -349,10 +354,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
if (entity != null) { if (entity != null) {
org.bukkit.entity.Entity bukkitEnt = entity.getBukkitEntity(); org.bukkit.entity.Entity bukkitEnt = entity.getBukkitEntity();
return BukkitAdapter.adapt(bukkitEnt).getState().getNbtData(); return FaweCompoundTag.of(BukkitAdapter.adapt(bukkitEnt).getState().getNbt());
} }
for (CompoundTag tag : getEntities()) { for (FaweCompoundTag tag : entities()) {
if (uuid.equals(tag.getUUID())) { if (uuid.equals(NbtUtils.uuid(tag))) {
return tag; return tag;
} }
} }
@ -360,14 +365,14 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
ensureLoaded(serverLevel, chunkX, chunkZ); ensureLoaded(serverLevel, chunkX, chunkZ);
List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk()); List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk());
if (entities.isEmpty()) { if (entities.isEmpty()) {
return Collections.emptySet(); return Collections.emptyList();
} }
int size = entities.size(); int size = entities.size();
return new AbstractSet<>() { return new AbstractCollection<>() {
@Override @Override
public int size() { public int size() {
return size; return size;
@ -380,10 +385,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
@Override @Override
public boolean contains(Object get) { public boolean contains(Object get) {
if (!(get instanceof CompoundTag getTag)) { if (!(get instanceof FaweCompoundTag getTag)) {
return false; return false;
} }
UUID getUUID = getTag.getUUID(); UUID getUUID = NbtUtils.uuid(getTag);
for (Entity entity : entities) { for (Entity entity : entities) {
UUID uuid = entity.getUUID(); UUID uuid = entity.getUUID();
if (uuid.equals(getUUID)) { if (uuid.equals(getUUID)) {
@ -395,12 +400,12 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
@Nonnull @Nonnull
@Override @Override
public Iterator<CompoundTag> iterator() { public Iterator<FaweCompoundTag> iterator() {
Iterable<CompoundTag> result = entities.stream().map(input -> { Iterable<FaweCompoundTag> result = entities.stream().map(input -> {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag(); net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag();
input.save(tag); input.save(tag);
return (CompoundTag) adapter.toNative(tag); return FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(tag));
}).collect(Collectors.toList()); })::iterator;
return result.iterator(); return result.iterator();
} }
}; };
@ -728,43 +733,42 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
}; };
} }
Set<CompoundTag> entities = set.getEntities(); Collection<FaweCompoundTag> entities = set.entities();
if (entities != null && !entities.isEmpty()) { if (entities != null && !entities.isEmpty()) {
if (syncTasks == null) { if (syncTasks == null) {
syncTasks = new Runnable[2]; syncTasks = new Runnable[2];
} }
syncTasks[1] = () -> { syncTasks[1] = () -> {
Iterator<CompoundTag> iterator = entities.iterator(); Iterator<FaweCompoundTag> iterator = entities.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next(); final FaweCompoundTag nativeTag = iterator.next();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue(); final LinCompoundTag linTag = nativeTag.linTag();
final StringTag idTag = (StringTag) entityTagMap.get("Id"); final LinStringTag idTag = linTag.findTag("Id", LinTagType.stringTag());
final ListTag posTag = (ListTag) entityTagMap.get("Pos"); final LinListTag<LinDoubleTag> posTag = linTag.findListTag("Pos", LinTagType.doubleTag());
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation"); final LinListTag<LinFloatTag> rotTag = linTag.findListTag("Rotation", LinTagType.floatTag());
if (idTag == null || posTag == null || rotTag == null) { if (idTag == null || posTag == null || rotTag == null) {
LOGGER.error("Unknown entity tag: {}", nativeTag); LOGGER.error("Unknown entity tag: {}", nativeTag);
continue; continue;
} }
final double x = posTag.getDouble(0); final double x = posTag.get(0).valueAsDouble();
final double y = posTag.getDouble(1); final double y = posTag.get(1).valueAsDouble();
final double z = posTag.getDouble(2); final double z = posTag.get(2).valueAsDouble();
final float yaw = rotTag.getFloat(0); final float yaw = rotTag.get(0).valueAsFloat();
final float pitch = rotTag.getFloat(1); final float pitch = rotTag.get(1).valueAsFloat();
final String id = idTag.getValue(); final String id = idTag.value();
EntityType<?> type = EntityType.byString(id).orElse(null); EntityType<?> type = EntityType.byString(id).orElse(null);
if (type != null) { if (type != null) {
Entity entity = type.create(nmsWorld); Entity entity = type.create(nmsWorld);
if (entity != null) { if (entity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative( final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNativeLin(linTag);
nativeTag);
for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name); tag.remove(name);
} }
entity.load(tag); entity.load(tag);
entity.absMoveTo(x, y, z, yaw, pitch); entity.absMoveTo(x, y, z, yaw, pitch);
entity.setUUID(nativeTag.getUUID()); entity.setUUID(NbtUtils.uuid(nativeTag));
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) { if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn( LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`", "Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
@ -784,15 +788,15 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
// set tiles // set tiles
Map<BlockVector3, CompoundTag> tiles = set.getTiles(); Map<BlockVector3, FaweCompoundTag> tiles = set.tiles();
if (tiles != null && !tiles.isEmpty()) { if (tiles != null && !tiles.isEmpty()) {
if (syncTasks == null) { if (syncTasks == null) {
syncTasks = new Runnable[1]; syncTasks = new Runnable[1];
} }
syncTasks[0] = () -> { syncTasks[0] = () -> {
for (final Map.Entry<BlockVector3, CompoundTag> entry : tiles.entrySet()) { for (final Map.Entry<BlockVector3, FaweCompoundTag> entry : tiles.entrySet()) {
final CompoundTag nativeTag = entry.getValue(); final FaweCompoundTag nativeTag = entry.getValue();
final BlockVector3 blockHash = entry.getKey(); final BlockVector3 blockHash = entry.getKey();
final int x = blockHash.x() + bx; final int x = blockHash.x() + bx;
final int y = blockHash.y(); final int y = blockHash.y();
@ -806,8 +810,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
tileEntity = nmsWorld.getBlockEntity(pos); tileEntity = nmsWorld.getBlockEntity(pos);
} }
if (tileEntity != null) { if (tileEntity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative( final net.minecraft.nbt.CompoundTag tag = (CompoundTag) adapter.fromNativeLin(nativeTag.linTag());
nativeTag);
tag.put("x", IntTag.valueOf(x)); tag.put("x", IntTag.valueOf(x));
tag.put("y", IntTag.valueOf(y)); tag.put("y", IntTag.valueOf(y));
tag.put("z", IntTag.valueOf(z)); tag.put("z", IntTag.valueOf(z));

View File

@ -1,14 +1,13 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R4; package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R4;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBlocks; import com.fastasyncworldedit.core.queue.IBlocks;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.google.common.base.Suppliers; import com.fastasyncworldedit.core.util.NbtUtils;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R4.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -17,6 +16,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.nbt.Tag;
import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@ -26,9 +26,11 @@ import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.PalettedContainer; import net.minecraft.world.level.chunk.PalettedContainer;
import net.minecraft.world.level.chunk.PalettedContainerRO; import net.minecraft.world.level.chunk.PalettedContainerRO;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
@ -40,8 +42,8 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
private final Map<BlockVector3, CompoundTag> tiles = new HashMap<>(); private final Map<BlockVector3, FaweCompoundTag> tiles = new HashMap<>();
private final Set<CompoundTag> entities = new HashSet<>(); private final Set<FaweCompoundTag> entities = new HashSet<>();
private final char[][] blocks; private final char[][] blocks;
private final int minHeight; private final int minHeight;
private final int maxHeight; private final int maxHeight;
@ -58,44 +60,37 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
} }
protected void storeTile(BlockEntity blockEntity) { protected void storeTile(BlockEntity blockEntity) {
@SuppressWarnings("unchecked")
BukkitImplAdapter<Tag> adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
tiles.put( tiles.put(
BlockVector3.at( BlockVector3.at(
blockEntity.getBlockPos().getX(), blockEntity.getBlockPos().getX(),
blockEntity.getBlockPos().getY(), blockEntity.getBlockPos().getY(),
blockEntity.getBlockPos().getZ() blockEntity.getBlockPos().getZ()
), ),
new PaperweightLazyCompoundTag(Suppliers.memoize(() -> blockEntity.saveWithId(DedicatedServer.getServer().registryAccess()))) FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(blockEntity.saveWithId(DedicatedServer
.getServer()
.registryAccess())))
); );
} }
@Override
public Map<BlockVector3, CompoundTag> getTiles() {
return tiles;
}
@Override
@Nullable
public CompoundTag getTile(int x, int y, int z) {
return tiles.get(BlockVector3.at(x, y, z));
}
@SuppressWarnings({"unchecked", "rawtypes"})
protected void storeEntity(Entity entity) { protected void storeEntity(Entity entity) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); @SuppressWarnings("unchecked")
BukkitImplAdapter<Tag> adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag(); net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag();
entity.save(compoundTag); entity.save(compoundTag);
entities.add((CompoundTag) adapter.toNative(compoundTag)); entities.add(FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(compoundTag)));
} }
@Override @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
return this.entities; return this.entities;
} }
@Override @Override
public CompoundTag getEntity(UUID uuid) { public @Nullable FaweCompoundTag entity(final UUID uuid) {
for (CompoundTag tag : entities) { for (FaweCompoundTag tag : entities) {
if (uuid.equals(tag.getUUID())) { if (uuid.equals(NbtUtils.uuid(tag))) {
return tag; return tag;
} }
} }
@ -206,7 +201,7 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
@Override @Override
public BaseBlock getFullBlock(int x, int y, int z) { public BaseBlock getFullBlock(int x, int y, int z) {
BlockState state = BlockTypesCache.states[get(x, y, z)]; BlockState state = BlockTypesCache.states[get(x, y, z)];
return state.toBaseBlock(this, x, y, z); return state.toBaseBlock((IBlocks) this, x, y, z);
} }
@Override @Override
@ -236,6 +231,16 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
return BlockTypesCache.states[get(x, y, z)]; return BlockTypesCache.states[get(x, y, z)];
} }
@Override
public Map<BlockVector3, FaweCompoundTag> tiles() {
return tiles;
}
@Override
public @Nullable FaweCompoundTag tile(final int x, final int y, final int z) {
return tiles.get(BlockVector3.at(x, y, z));
}
@Override @Override
public int getSkyLight(int x, int y, int z) { public int getSkyLight(int x, int y, int z) {
return 0; return 0;

View File

@ -1,11 +1,8 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_21_R1; package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_21_R1;
import com.google.common.base.Suppliers; import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_21_R1.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.world.level.EmptyBlockGetter; import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.EntityBlock;
@ -15,6 +12,8 @@ import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.PushReaction; import net.minecraft.world.level.material.PushReaction;
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import javax.annotation.Nullable;
public class PaperweightBlockMaterial implements BlockMaterial { public class PaperweightBlockMaterial implements BlockMaterial {
private final Block block; private final Block block;
@ -22,7 +21,7 @@ public class PaperweightBlockMaterial implements BlockMaterial {
private final CraftBlockData craftBlockData; private final CraftBlockData craftBlockData;
private final org.bukkit.Material craftMaterial; private final org.bukkit.Material craftMaterial;
private final int opacity; private final int opacity;
private final CompoundTag tile; private final FaweCompoundTag tile;
public PaperweightBlockMaterial(Block block) { public PaperweightBlockMaterial(Block block) {
this(block, block.defaultBlockState()); this(block, block.defaultBlockState());
@ -38,9 +37,9 @@ public class PaperweightBlockMaterial implements BlockMaterial {
BlockPos.ZERO, BlockPos.ZERO,
blockState blockState
); );
tile = tileEntity == null ? null : new PaperweightLazyCompoundTag( tile = tileEntity == null
Suppliers.memoize(() -> tileEntity.saveWithId(DedicatedServer.getServer().registryAccess())) ? null
); : PaperweightGetBlocks.NMS_TO_TILE.apply(tileEntity);
} }
public Block getBlock() { public Block getBlock() {
@ -164,7 +163,7 @@ public class PaperweightBlockMaterial implements BlockMaterial {
} }
@Override @Override
public CompoundTag getDefaultTile() { public @Nullable FaweCompoundTag defaultTile() {
return tile; return tile;
} }

View File

@ -5,6 +5,7 @@ import com.fastasyncworldedit.bukkit.adapter.NMSRelighterFactory;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.entity.LazyBaseEntity; import com.fastasyncworldedit.core.entity.LazyBaseEntity;
import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory; import com.fastasyncworldedit.core.extent.processor.lighting.RelighterFactory;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBatchProcessor; import com.fastasyncworldedit.core.queue.IBatchProcessor;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket; import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
@ -102,6 +103,7 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.OptionalInt; import java.util.OptionalInt;
import java.util.Set; import java.util.Set;
import java.util.function.Function;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@ -137,6 +139,12 @@ public final class PaperweightFaweAdapter extends FaweAdapter<net.minecraft.nbt.
this.parent = new com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_21_R1.PaperweightAdapter(); this.parent = new com.sk89q.worldedit.bukkit.adapter.ext.fawe.v1_21_R1.PaperweightAdapter();
} }
public Function<BlockEntity, FaweCompoundTag> blockEntityToCompoundTag() {
return blockEntity -> FaweCompoundTag.of(
() -> (LinCompoundTag) toNativeLin(blockEntity.saveWithId(DedicatedServer.getServer().registryAccess()))
);
}
@Nullable @Nullable
private static String getEntityId(Entity entity) { private static String getEntityId(Entity entity) {
ResourceLocation resourceLocation = net.minecraft.world.entity.EntityType.getKey(entity.getType()); ResourceLocation resourceLocation = net.minecraft.world.entity.EntityType.getKey(entity.getType());

View File

@ -7,20 +7,16 @@ import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Settings; import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.math.BitArrayUnstretched; import com.fastasyncworldedit.core.math.BitArrayUnstretched;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.queue.implementation.QueueHandler; import com.fastasyncworldedit.core.queue.implementation.QueueHandler;
import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks; import com.fastasyncworldedit.core.queue.implementation.blocks.CharGetBlocks;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.fastasyncworldedit.core.util.NbtUtils;
import com.fastasyncworldedit.core.util.collection.AdaptedMap; import com.fastasyncworldedit.core.util.collection.AdaptedMap;
import com.google.common.base.Suppliers;
import com.sk89q.jnbt.CompoundTag;
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.BukkitAdapter;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_21_R1.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.internal.Constants; import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -34,6 +30,7 @@ import net.minecraft.core.Holder;
import net.minecraft.core.IdMap; import net.minecraft.core.IdMap;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos; import net.minecraft.core.SectionPos;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.IntTag; import net.minecraft.nbt.IntTag;
import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -62,11 +59,19 @@ import org.bukkit.World;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBlock; import org.bukkit.craftbukkit.block.CraftBlock;
import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.entity.CreatureSpawnEvent;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinDoubleTag;
import org.enginehub.linbus.tree.LinFloatTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTagType;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import java.util.AbstractSet; import javax.annotation.Nullable;
import java.util.AbstractCollection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@ -83,7 +88,6 @@ import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors;
import static net.minecraft.core.registries.Registries.BIOME; import static net.minecraft.core.registries.Registries.BIOME;
@ -92,9 +96,9 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
private static final Function<BlockPos, BlockVector3> posNms2We = v -> BlockVector3.at(v.getX(), v.getY(), v.getZ()); private static final Function<BlockPos, BlockVector3> posNms2We = v -> BlockVector3.at(v.getX(), v.getY(), v.getZ());
private static final Function<BlockEntity, CompoundTag> nmsTile2We = tileEntity -> new PaperweightLazyCompoundTag( public static final Function<BlockEntity, FaweCompoundTag> NMS_TO_TILE = ((PaperweightFaweAdapter) WorldEditPlugin
Suppliers.memoize(() -> tileEntity.saveWithId(DedicatedServer.getServer().registryAccess())) .getInstance()
); .getBukkitImplAdapter()).blockEntityToCompoundTag();
private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin private final PaperweightFaweAdapter adapter = ((PaperweightFaweAdapter) WorldEditPlugin
.getInstance() .getInstance()
.getBukkitImplAdapter()); .getBukkitImplAdapter());
@ -258,23 +262,24 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public CompoundTag getTile(int x, int y, int z) { public FaweCompoundTag tile(final int x, final int y, final int z) {
BlockEntity blockEntity = getChunk().getBlockEntity(new BlockPos((x & 15) + ( BlockEntity blockEntity = getChunk().getBlockEntity(new BlockPos((x & 15) + (
chunkX << 4), y, (z & 15) + ( chunkX << 4), y, (z & 15) + (
chunkZ << 4))); chunkZ << 4)));
if (blockEntity == null) { if (blockEntity == null) {
return null; return null;
} }
return new PaperweightLazyCompoundTag(Suppliers.memoize(() -> blockEntity.saveWithId(DedicatedServer.getServer().registryAccess()))); return NMS_TO_TILE.apply(blockEntity);
} }
@Override @Override
public Map<BlockVector3, CompoundTag> getTiles() { public Map<BlockVector3, FaweCompoundTag> tiles() {
Map<BlockPos, BlockEntity> nmsTiles = getChunk().getBlockEntities(); Map<BlockPos, BlockEntity> nmsTiles = getChunk().getBlockEntities();
if (nmsTiles.isEmpty()) { if (nmsTiles.isEmpty()) {
return Collections.emptyMap(); return Collections.emptyMap();
} }
return AdaptedMap.immutable(nmsTiles, posNms2We, nmsTile2We); return AdaptedMap.immutable(nmsTiles, posNms2We, NMS_TO_TILE);
} }
@Override @Override
@ -337,7 +342,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public CompoundTag getEntity(UUID uuid) { public @Nullable FaweCompoundTag entity(final UUID uuid) {
ensureLoaded(serverLevel, chunkX, chunkZ); ensureLoaded(serverLevel, chunkX, chunkZ);
List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk()); List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk());
Entity entity = null; Entity entity = null;
@ -349,10 +354,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
if (entity != null) { if (entity != null) {
org.bukkit.entity.Entity bukkitEnt = entity.getBukkitEntity(); org.bukkit.entity.Entity bukkitEnt = entity.getBukkitEntity();
return BukkitAdapter.adapt(bukkitEnt).getState().getNbtData(); return FaweCompoundTag.of(BukkitAdapter.adapt(bukkitEnt).getState().getNbt());
} }
for (CompoundTag tag : getEntities()) { for (FaweCompoundTag tag : entities()) {
if (uuid.equals(tag.getUUID())) { if (uuid.equals(NbtUtils.uuid(tag))) {
return tag; return tag;
} }
} }
@ -360,14 +365,14 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
@Override @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
ensureLoaded(serverLevel, chunkX, chunkZ); ensureLoaded(serverLevel, chunkX, chunkZ);
List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk()); List<Entity> entities = PaperweightPlatformAdapter.getEntities(getChunk());
if (entities.isEmpty()) { if (entities.isEmpty()) {
return Collections.emptySet(); return Collections.emptyList();
} }
int size = entities.size(); int size = entities.size();
return new AbstractSet<>() { return new AbstractCollection<>() {
@Override @Override
public int size() { public int size() {
return size; return size;
@ -380,10 +385,10 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
@Override @Override
public boolean contains(Object get) { public boolean contains(Object get) {
if (!(get instanceof CompoundTag getTag)) { if (!(get instanceof FaweCompoundTag getTag)) {
return false; return false;
} }
UUID getUUID = getTag.getUUID(); UUID getUUID = NbtUtils.uuid(getTag);
for (Entity entity : entities) { for (Entity entity : entities) {
UUID uuid = entity.getUUID(); UUID uuid = entity.getUUID();
if (uuid.equals(getUUID)) { if (uuid.equals(getUUID)) {
@ -395,15 +400,16 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
@Nonnull @Nonnull
@Override @Override
public Iterator<CompoundTag> iterator() { public Iterator<FaweCompoundTag> iterator() {
Iterable<CompoundTag> result = entities.stream().map(input -> { Iterable<FaweCompoundTag> result = entities.stream().map(input -> {
net.minecraft.nbt.CompoundTag tag = new net.minecraft.nbt.CompoundTag(); CompoundTag tag = new CompoundTag();
input.save(tag); input.save(tag);
return (CompoundTag) adapter.toNative(tag); return FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(tag));
}).collect(Collectors.toList()); })::iterator;
return result.iterator(); return result.iterator();
} }
}; };
} }
private void removeEntity(Entity entity) { private void removeEntity(Entity entity) {
@ -722,43 +728,42 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
}; };
} }
Set<CompoundTag> entities = set.getEntities(); Collection<FaweCompoundTag> entities = set.entities();
if (entities != null && !entities.isEmpty()) { if (entities != null && !entities.isEmpty()) {
if (syncTasks == null) { if (syncTasks == null) {
syncTasks = new Runnable[2]; syncTasks = new Runnable[2];
} }
syncTasks[1] = () -> { syncTasks[1] = () -> {
Iterator<CompoundTag> iterator = entities.iterator(); Iterator<FaweCompoundTag> iterator = entities.iterator();
while (iterator.hasNext()) { while (iterator.hasNext()) {
final CompoundTag nativeTag = iterator.next(); final FaweCompoundTag nativeTag = iterator.next();
final Map<String, Tag<?, ?>> entityTagMap = nativeTag.getValue(); final LinCompoundTag linTag = nativeTag.linTag();
final StringTag idTag = (StringTag) entityTagMap.get("Id"); final LinStringTag idTag = linTag.findTag("Id", LinTagType.stringTag());
final ListTag posTag = (ListTag) entityTagMap.get("Pos"); final LinListTag<LinDoubleTag> posTag = linTag.findListTag("Pos", LinTagType.doubleTag());
final ListTag rotTag = (ListTag) entityTagMap.get("Rotation"); final LinListTag<LinFloatTag> rotTag = linTag.findListTag("Rotation", LinTagType.floatTag());
if (idTag == null || posTag == null || rotTag == null) { if (idTag == null || posTag == null || rotTag == null) {
LOGGER.error("Unknown entity tag: {}", nativeTag); LOGGER.error("Unknown entity tag: {}", nativeTag);
continue; continue;
} }
final double x = posTag.getDouble(0); final double x = posTag.get(0).valueAsDouble();
final double y = posTag.getDouble(1); final double y = posTag.get(1).valueAsDouble();
final double z = posTag.getDouble(2); final double z = posTag.get(2).valueAsDouble();
final float yaw = rotTag.getFloat(0); final float yaw = rotTag.get(0).valueAsFloat();
final float pitch = rotTag.getFloat(1); final float pitch = rotTag.get(1).valueAsFloat();
final String id = idTag.getValue(); final String id = idTag.value();
EntityType<?> type = EntityType.byString(id).orElse(null); EntityType<?> type = EntityType.byString(id).orElse(null);
if (type != null) { if (type != null) {
Entity entity = type.create(nmsWorld); Entity entity = type.create(nmsWorld);
if (entity != null) { if (entity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative( final CompoundTag tag = (CompoundTag) adapter.fromNativeLin(linTag);
nativeTag);
for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) { for (final String name : Constants.NO_COPY_ENTITY_NBT_FIELDS) {
tag.remove(name); tag.remove(name);
} }
entity.load(tag); entity.load(tag);
entity.absMoveTo(x, y, z, yaw, pitch); entity.absMoveTo(x, y, z, yaw, pitch);
entity.setUUID(nativeTag.getUUID()); entity.setUUID(NbtUtils.uuid(nativeTag));
if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) { if (!nmsWorld.addFreshEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM)) {
LOGGER.warn( LOGGER.warn(
"Error creating entity of type `{}` in world `{}` at location `{},{},{}`", "Error creating entity of type `{}` in world `{}` at location `{},{},{}`",
@ -778,15 +783,15 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
} }
// set tiles // set tiles
Map<BlockVector3, CompoundTag> tiles = set.getTiles(); Map<BlockVector3, FaweCompoundTag> tiles = set.tiles();
if (tiles != null && !tiles.isEmpty()) { if (tiles != null && !tiles.isEmpty()) {
if (syncTasks == null) { if (syncTasks == null) {
syncTasks = new Runnable[1]; syncTasks = new Runnable[1];
} }
syncTasks[0] = () -> { syncTasks[0] = () -> {
for (final Map.Entry<BlockVector3, CompoundTag> entry : tiles.entrySet()) { for (final Map.Entry<BlockVector3, FaweCompoundTag> entry : tiles.entrySet()) {
final CompoundTag nativeTag = entry.getValue(); final FaweCompoundTag nativeTag = entry.getValue();
final BlockVector3 blockHash = entry.getKey(); final BlockVector3 blockHash = entry.getKey();
final int x = blockHash.x() + bx; final int x = blockHash.x() + bx;
final int y = blockHash.y(); final int y = blockHash.y();
@ -800,8 +805,7 @@ public class PaperweightGetBlocks extends CharGetBlocks implements BukkitGetBloc
tileEntity = nmsWorld.getBlockEntity(pos); tileEntity = nmsWorld.getBlockEntity(pos);
} }
if (tileEntity != null) { if (tileEntity != null) {
final net.minecraft.nbt.CompoundTag tag = (net.minecraft.nbt.CompoundTag) adapter.fromNative( final CompoundTag tag = (CompoundTag) adapter.fromNativeLin(nativeTag.linTag());
nativeTag);
tag.put("x", IntTag.valueOf(x)); tag.put("x", IntTag.valueOf(x));
tag.put("y", IntTag.valueOf(y)); tag.put("y", IntTag.valueOf(y));
tag.put("z", IntTag.valueOf(z)); tag.put("z", IntTag.valueOf(z));

View File

@ -1,14 +1,13 @@
package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_21_R1; package com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_21_R1;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBlocks; import com.fastasyncworldedit.core.queue.IBlocks;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.google.common.base.Suppliers; import com.fastasyncworldedit.core.util.NbtUtils;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.bukkit.WorldEditPlugin; import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter; import com.sk89q.worldedit.bukkit.adapter.BukkitImplAdapter;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_21_R1.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -17,6 +16,7 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import io.papermc.lib.PaperLib; import io.papermc.lib.PaperLib;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.nbt.Tag;
import net.minecraft.server.dedicated.DedicatedServer; import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.Entity;
@ -26,9 +26,11 @@ import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.level.chunk.PalettedContainer; import net.minecraft.world.level.chunk.PalettedContainer;
import net.minecraft.world.level.chunk.PalettedContainerRO; import net.minecraft.world.level.chunk.PalettedContainerRO;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Map; import java.util.Map;
@ -40,8 +42,8 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
private static final Logger LOGGER = LogManagerCompat.getLogger(); private static final Logger LOGGER = LogManagerCompat.getLogger();
private final Map<BlockVector3, CompoundTag> tiles = new HashMap<>(); private final Map<BlockVector3, FaweCompoundTag> tiles = new HashMap<>();
private final Set<CompoundTag> entities = new HashSet<>(); private final Set<FaweCompoundTag> entities = new HashSet<>();
private final char[][] blocks; private final char[][] blocks;
private final int minHeight; private final int minHeight;
private final int maxHeight; private final int maxHeight;
@ -58,44 +60,37 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
} }
protected void storeTile(BlockEntity blockEntity) { protected void storeTile(BlockEntity blockEntity) {
@SuppressWarnings("unchecked")
BukkitImplAdapter<Tag> adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
tiles.put( tiles.put(
BlockVector3.at( BlockVector3.at(
blockEntity.getBlockPos().getX(), blockEntity.getBlockPos().getX(),
blockEntity.getBlockPos().getY(), blockEntity.getBlockPos().getY(),
blockEntity.getBlockPos().getZ() blockEntity.getBlockPos().getZ()
), ),
new PaperweightLazyCompoundTag(Suppliers.memoize(() -> blockEntity.saveWithId(DedicatedServer.getServer().registryAccess()))) FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(blockEntity.saveWithId(DedicatedServer
.getServer()
.registryAccess())))
); );
} }
@Override
public Map<BlockVector3, CompoundTag> getTiles() {
return tiles;
}
@Override
@Nullable
public CompoundTag getTile(int x, int y, int z) {
return tiles.get(BlockVector3.at(x, y, z));
}
@SuppressWarnings({"unchecked", "rawtypes"})
protected void storeEntity(Entity entity) { protected void storeEntity(Entity entity) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter(); @SuppressWarnings("unchecked")
BukkitImplAdapter<Tag> adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag(); net.minecraft.nbt.CompoundTag compoundTag = new net.minecraft.nbt.CompoundTag();
entity.save(compoundTag); entity.save(compoundTag);
entities.add((CompoundTag) adapter.toNative(compoundTag)); entities.add(FaweCompoundTag.of((LinCompoundTag) adapter.toNativeLin(compoundTag)));
} }
@Override @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
return this.entities; return this.entities;
} }
@Override @Override
public CompoundTag getEntity(UUID uuid) { public @Nullable FaweCompoundTag entity(final UUID uuid) {
for (CompoundTag tag : entities) { for (FaweCompoundTag tag : entities) {
if (uuid.equals(tag.getUUID())) { if (uuid.equals(NbtUtils.uuid(tag))) {
return tag; return tag;
} }
} }
@ -206,7 +201,7 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
@Override @Override
public BaseBlock getFullBlock(int x, int y, int z) { public BaseBlock getFullBlock(int x, int y, int z) {
BlockState state = BlockTypesCache.states[get(x, y, z)]; BlockState state = BlockTypesCache.states[get(x, y, z)];
return state.toBaseBlock(this, x, y, z); return state.toBaseBlock((IBlocks) this, x, y, z);
} }
@Override @Override
@ -236,6 +231,16 @@ public class PaperweightGetBlocks_Copy implements IChunkGet {
return BlockTypesCache.states[get(x, y, z)]; return BlockTypesCache.states[get(x, y, z)];
} }
@Override
public Map<BlockVector3, FaweCompoundTag> tiles() {
return tiles;
}
@Override
public @Nullable FaweCompoundTag tile(final int x, final int y, final int z) {
return tiles.get(BlockVector3.at(x, y, z));
}
@Override @Override
public int getSkyLight(int x, int y, int z) { public int getSkyLight(int x, int y, int z) {
return 0; return 0;

View File

@ -24,12 +24,12 @@ import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Settings; import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.internal.exception.FaweException; import com.fastasyncworldedit.core.internal.exception.FaweException;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket; import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
import com.fastasyncworldedit.core.util.TaskManager; import com.fastasyncworldedit.core.util.TaskManager;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseItem; import com.sk89q.worldedit.blocks.BaseItem;
@ -665,7 +665,7 @@ public class BukkitWorld extends AbstractWorld {
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { public boolean tile(int x, int y, int z, FaweCompoundTag tile) throws WorldEditException {
return false; return false;
} }

View File

@ -165,9 +165,11 @@ public class BukkitImplLoader {
* @throws AdapterLoadException thrown if no adapter could be found * @throws AdapterLoadException thrown if no adapter could be found
*/ */
public BukkitImplAdapter loadAdapter() throws AdapterLoadException { public BukkitImplAdapter loadAdapter() throws AdapterLoadException {
// FAWE - do not initialize classes on lookup
final ClassLoader classLoader = this.getClass().getClassLoader();
for (String className : adapterCandidates) { for (String className : adapterCandidates) {
try { try {
Class<?> cls = Class.forName(className); Class<?> cls = Class.forName(className, false, classLoader);
if (cls.isSynthetic()) { if (cls.isSynthetic()) {
continue; continue;
} }

View File

@ -19,10 +19,10 @@
package com.sk89q.worldedit.cli.schematic; package com.sk89q.worldedit.cli.schematic;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket; import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
@ -193,7 +193,7 @@ public class ClipboardWorld extends AbstractWorld implements Clipboard, CLIWorld
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { public boolean tile(int x, int y, int z, FaweCompoundTag tile) throws WorldEditException {
return false; return false;
} }

View File

@ -2,6 +2,7 @@ package com.fastasyncworldedit.core.extent;
import com.fastasyncworldedit.core.history.changeset.AbstractChangeSet; import com.fastasyncworldedit.core.history.changeset.AbstractChangeSet;
import com.fastasyncworldedit.core.math.MutableBlockVector3; import com.fastasyncworldedit.core.math.MutableBlockVector3;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
@ -74,7 +75,7 @@ public class HistoryExtent extends AbstractDelegateExtent {
public Entity createEntity(Location location, BaseEntity state) { public Entity createEntity(Location location, BaseEntity state) {
final Entity entity = super.createEntity(location, state); final Entity entity = super.createEntity(location, state);
if (state != null) { if (state != null) {
this.changeSet.addEntityCreate(state.getNbtData()); this.changeSet.addEntityCreate(FaweCompoundTag.of(state.getNbt()));
} }
return entity; return entity;
} }
@ -84,7 +85,7 @@ public class HistoryExtent extends AbstractDelegateExtent {
public Entity createEntity(Location location, BaseEntity state, UUID uuid) { public Entity createEntity(Location location, BaseEntity state, UUID uuid) {
final Entity entity = super.createEntity(location, state, uuid); final Entity entity = super.createEntity(location, state, uuid);
if (state != null) { if (state != null) {
this.changeSet.addEntityCreate(state.getNbtData()); this.changeSet.addEntityCreate(FaweCompoundTag.of(state.getNbt()));
} }
return entity; return entity;
} }
@ -154,11 +155,10 @@ public class HistoryExtent extends AbstractDelegateExtent {
@Override @Override
public boolean remove() { public boolean remove() {
final Location location = this.entity.getLocation();
final BaseEntity state = this.entity.getState(); final BaseEntity state = this.entity.getState();
final boolean success = this.entity.remove(); final boolean success = this.entity.remove();
if (state != null && success) { if (state != null && success) {
HistoryExtent.this.changeSet.addEntityRemove(state.getNbtData()); HistoryExtent.this.changeSet.addEntityRemove(FaweCompoundTag.of(state.getNbt()));
} }
return success; return success;
} }

View File

@ -2,9 +2,11 @@ package com.fastasyncworldedit.core.extent.clipboard;
import com.fastasyncworldedit.core.jnbt.streamer.IntValueReader; import com.fastasyncworldedit.core.jnbt.streamer.IntValueReader;
import com.fastasyncworldedit.core.math.IntTriple; import com.fastasyncworldedit.core.math.IntTriple;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -175,6 +177,12 @@ public class CPUOptimizedClipboard extends LinearClipboard {
return true; return true;
} }
@Override
public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tile) throws WorldEditException {
// TODO replace
return setTile(x, y, z, new CompoundTag(tile.linTag()));
}
private boolean setTile(int index, CompoundTag tag) { private boolean setTile(int index, CompoundTag tag) {
final Map<String, Tag<?, ?>> values = new HashMap<>(tag.getValue()); final Map<String, Tag<?, ?>> values = new HashMap<>(tag.getValue());
values.remove("x"); values.remove("x");

View File

@ -6,15 +6,17 @@ import com.fastasyncworldedit.core.internal.exception.FaweClipboardVersionMismat
import com.fastasyncworldedit.core.internal.io.ByteBufferInputStream; import com.fastasyncworldedit.core.internal.io.ByteBufferInputStream;
import com.fastasyncworldedit.core.jnbt.streamer.IntValueReader; import com.fastasyncworldedit.core.jnbt.streamer.IntValueReader;
import com.fastasyncworldedit.core.math.IntTriple; import com.fastasyncworldedit.core.math.IntTriple;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.util.MainUtil; import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.NbtUtils;
import com.fastasyncworldedit.core.util.ReflectionUtils; import com.fastasyncworldedit.core.util.ReflectionUtils;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.DoubleTag; import com.sk89q.jnbt.DoubleTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.ListTag; import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.NBTInputStream; import com.sk89q.jnbt.NBTInputStream;
import com.sk89q.jnbt.NBTOutputStream; import com.sk89q.jnbt.NBTOutputStream;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard; import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
@ -65,6 +67,7 @@ public class DiskOptimizedClipboard extends LinearClipboard {
private static final Map<String, LockHolder> LOCK_HOLDER_CACHE = new ConcurrentHashMap<>(); private static final Map<String, LockHolder> LOCK_HOLDER_CACHE = new ConcurrentHashMap<>();
private final HashMap<IntTriple, CompoundTag> nbtMap; private final HashMap<IntTriple, CompoundTag> nbtMap;
private final HashMap<IntTriple, FaweCompoundTag> nbtMap2;
private final File file; private final File file;
private final int headerSize; private final int headerSize;
@ -124,6 +127,7 @@ public class DiskOptimizedClipboard extends LinearClipboard {
canHaveBiomes = false; canHaveBiomes = false;
} }
nbtMap = new HashMap<>(); nbtMap = new HashMap<>();
nbtMap2 = new HashMap<>();
try { try {
this.file = file; this.file = file;
try { try {
@ -180,6 +184,7 @@ public class DiskOptimizedClipboard extends LinearClipboard {
super(readSize(file, versionOverride), BlockVector3.ZERO); super(readSize(file, versionOverride), BlockVector3.ZERO);
headerSize = getHeaderSizeOverrideFromVersion(versionOverride); headerSize = getHeaderSizeOverrideFromVersion(versionOverride);
nbtMap = new HashMap<>(); nbtMap = new HashMap<>();
nbtMap2 = new HashMap<>();
try { try {
this.file = file; this.file = file;
this.braf = new RandomAccessFile(file, "rw"); this.braf = new RandomAccessFile(file, "rw");
@ -709,12 +714,8 @@ public class DiskOptimizedClipboard extends LinearClipboard {
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tag) { public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tile) throws WorldEditException {
final Map<String, Tag<?, ?>> values = new HashMap<>(tag.getValue()); nbtMap2.put(new IntTriple(x, y, z), NbtUtils.withPosition(tile, x, y, z));
values.put("x", new IntTag(x));
values.put("y", new IntTag(y));
values.put("z", new IntTag(z));
nbtMap.put(new IntTriple(x, y, z), new CompoundTag(values));
return true; return true;
} }

View File

@ -1,7 +1,7 @@
package com.fastasyncworldedit.core.extent.clipboard; package com.fastasyncworldedit.core.extent.clipboard;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.sk89q.jnbt.CompoundTag; import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.clipboard.Clipboard; import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -84,7 +84,8 @@ public final class EmptyClipboard implements Clipboard {
return false; return false;
} }
public boolean setTile(int x, int y, int z, @Nonnull CompoundTag tile) throws WorldEditException { @Override
public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tile) throws WorldEditException {
return false; return false;
} }

View File

@ -3,10 +3,12 @@ package com.fastasyncworldedit.core.extent.clipboard;
import com.fastasyncworldedit.core.configuration.Settings; import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.jnbt.streamer.IntValueReader; import com.fastasyncworldedit.core.jnbt.streamer.IntValueReader;
import com.fastasyncworldedit.core.math.IntTriple; import com.fastasyncworldedit.core.math.IntTriple;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.util.MainUtil; import com.fastasyncworldedit.core.util.MainUtil;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag; import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.Tag; import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -262,6 +264,12 @@ public class MemoryOptimizedClipboard extends LinearClipboard {
return true; return true;
} }
@Override
public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tile) throws WorldEditException {
// TODO replace
return setTile(x, y, z, new CompoundTag(tile.linTag()));
}
@Override @Override
public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) { public <B extends BlockStateHolder<B>> boolean setBlock(int x, int y, int z, B block) {
return setBlock(getIndex(x, y, z), block); return setBlock(getIndex(x, y, z), block);

View File

@ -1,7 +1,7 @@
package com.fastasyncworldedit.core.extent.clipboard; package com.fastasyncworldedit.core.extent.clipboard;
import com.fastasyncworldedit.core.Fawe; import com.fastasyncworldedit.core.Fawe;
import com.sk89q.jnbt.CompoundTag; import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
@ -106,7 +106,7 @@ public abstract class ReadOnlyClipboard extends SimpleClipboard {
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tag) { public boolean tile(int x, int y, int z, FaweCompoundTag tag) {
throw new UnsupportedOperationException("Clipboard is immutable"); throw new UnsupportedOperationException("Clipboard is immutable");
} }

View File

@ -5,6 +5,7 @@ import com.fastasyncworldedit.core.extent.clipboard.SimpleClipboard;
import com.fastasyncworldedit.core.internal.io.ResettableFileInputStream; import com.fastasyncworldedit.core.internal.io.ResettableFileInputStream;
import com.fastasyncworldedit.core.internal.io.VarIntStreamIterator; import com.fastasyncworldedit.core.internal.io.VarIntStreamIterator;
import com.fastasyncworldedit.core.math.MutableBlockVector3; import com.fastasyncworldedit.core.math.MutableBlockVector3;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.util.IOUtil; import com.fastasyncworldedit.core.util.IOUtil;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
@ -626,12 +627,11 @@ public class FastSchematicReaderV3 implements ClipboardReader {
} }
private EntityTransformer provideTileEntityTransformer(Clipboard clipboard) { private EntityTransformer provideTileEntityTransformer(Clipboard clipboard) {
//noinspection deprecation return (x, y, z, id, tag) -> clipboard.tile(
return (x, y, z, id, tag) -> clipboard.setTile(
MathMan.roundInt(x + clipboard.getMinimumPoint().x()), MathMan.roundInt(x + clipboard.getMinimumPoint().x()),
MathMan.roundInt(y + clipboard.getMinimumPoint().y()), MathMan.roundInt(y + clipboard.getMinimumPoint().y()),
MathMan.roundInt(z + clipboard.getMinimumPoint().z()), MathMan.roundInt(z + clipboard.getMinimumPoint().z()),
new CompoundTag(tag) FaweCompoundTag.of(tag)
); );
} }

View File

@ -1,5 +1,6 @@
package com.fastasyncworldedit.core.extent.filter.block; package com.fastasyncworldedit.core.extent.filter.block;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
@ -105,6 +106,11 @@ public class ArrayFilterBlock extends AbstractExtentFilterBlock {
return getExtent().setBlock(x, y, z, block); return getExtent().setBlock(x, y, z, block);
} }
@Override
public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tile) throws WorldEditException {
return false; // class is unused + deprecated, do not care about impl
}
@Override @Override
public boolean setBiome(int x, int y, int z, BiomeType biome) { public boolean setBiome(int x, int y, int z, BiomeType biome) {
return getExtent().setBiome(x, y, z, biome); return getExtent().setBiome(x, y, z, biome);

View File

@ -1,6 +1,7 @@
package com.fastasyncworldedit.core.extent.filter.block; package com.fastasyncworldedit.core.extent.filter.block;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.Filter; import com.fastasyncworldedit.core.queue.Filter;
import com.fastasyncworldedit.core.queue.FilterBlockMask; import com.fastasyncworldedit.core.queue.FilterBlockMask;
import com.fastasyncworldedit.core.queue.IBlocks; import com.fastasyncworldedit.core.queue.IBlocks;
@ -13,6 +14,7 @@ import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.Extent; import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
@ -20,6 +22,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import com.sk89q.worldedit.world.registry.BlockMaterial; import com.sk89q.worldedit.world.registry.BlockMaterial;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -259,8 +262,9 @@ public class CharFilterBlock extends ChunkFilterBlock {
final BlockState state = getBlock(); final BlockState state = getBlock();
final BlockMaterial material = state.getMaterial(); final BlockMaterial material = state.getMaterial();
if (material.hasContainer()) { if (material.hasContainer()) {
final CompoundTag tag = get.getTile(x, y + yy, z); final FaweCompoundTag tag = get.tile(x, y + yy, z);
return state.toBaseBlock(tag); assert tag != null : "has container but is null";
return state.toBaseBlock(tag.linTag());
} }
return state.toBaseBlock(); return state.toBaseBlock();
} }
@ -268,16 +272,28 @@ public class CharFilterBlock extends ChunkFilterBlock {
@Override @Override
public void setFullBlock(BaseBlock block) { public void setFullBlock(BaseBlock block) {
delegate.set(this, block.getOrdinalChar()); delegate.set(this, block.getOrdinalChar());
final CompoundTag nbt = block.getNbtData(); final LazyReference<LinCompoundTag> nbt = block.getNbtReference();
if (nbt != null) { // TODO optimize check via ImmutableBaseBlock if (nbt != null) { // TODO optimize check via ImmutableBaseBlock
set.setTile(x, yy + y, z, nbt); set.tile(x, yy + y, z, FaweCompoundTag.of(nbt));
} }
} }
@Override @Override
public final CompoundTag getNbtData() { public @Nullable LinCompoundTag getNbt() {
return get.getTile(x, y + yy, z); final FaweCompoundTag tile = get.tile(x, y + yy, z);
if (tile == null) {
return null;
}
return tile.linTag();
} }
@Override
public void setNbt(@Nullable final LinCompoundTag nbtData) {
if (nbtData != null) {
set.tile(x, y + yy, z, FaweCompoundTag.of(nbtData));
}
}
/* /*
NORTH(Vector3.at(0, 0, -1), Flag.CARDINAL, 3, 1), NORTH(Vector3.at(0, 0, -1), Flag.CARDINAL, 3, 1),
EAST(Vector3.at(1, 0, 0), Flag.CARDINAL, 0, 2), EAST(Vector3.at(1, 0, 0), Flag.CARDINAL, 0, 2),
@ -286,9 +302,9 @@ public class CharFilterBlock extends ChunkFilterBlock {
*/ */
@Override @Override
public void setNbtData(CompoundTag tag) { public void setNbtReference(@Nullable final LazyReference<LinCompoundTag> nbtData) {
if (tag != null) { if (nbtData != null) {
set.setTile(x, y + yy, z, tag); set.tile(x, y + yy, z, FaweCompoundTag.of(nbtData));
} }
} }

View File

@ -1,5 +1,6 @@
package com.fastasyncworldedit.core.extent.filter.block; package com.fastasyncworldedit.core.extent.filter.block;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.TileEntityBlock; import com.sk89q.worldedit.blocks.TileEntityBlock;
@ -35,17 +36,6 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
public abstract BiomeType getBiome(); public abstract BiomeType getBiome();
@Override
public abstract CompoundTag getNbtData();
@Override
public abstract void setNbtData(@Nullable CompoundTag nbtData);
@Override
public boolean hasNbtData() {
return getNbtData() != null;
}
@Override @Override
public BlockVector3 getMinimumPoint() { public BlockVector3 getMinimumPoint() {
return getExtent().getMinimumPoint(); return getExtent().getMinimumPoint();
@ -61,10 +51,9 @@ public abstract class FilterBlock extends BlockVector3 implements Extent, TileEn
return getExtent().getBlock(x, y, z); return getExtent().getBlock(x, y, z);
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tile) throws WorldEditException {
return getExtent().setTile(x, y, z, tile); return getExtent().tile(x, y, z, tile);
} }
@Override @Override

View File

@ -4,11 +4,12 @@ import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.extent.HistoryExtent; import com.fastasyncworldedit.core.extent.HistoryExtent;
import com.fastasyncworldedit.core.extent.processor.ProcessorScope; import com.fastasyncworldedit.core.extent.processor.ProcessorScope;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBatchProcessor; import com.fastasyncworldedit.core.queue.IBatchProcessor;
import com.fastasyncworldedit.core.queue.IChunk; import com.fastasyncworldedit.core.queue.IChunk;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.util.MainUtil; import com.fastasyncworldedit.core.util.NbtUtils;
import com.fastasyncworldedit.core.util.TaskManager; import com.fastasyncworldedit.core.util.TaskManager;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
@ -32,9 +33,12 @@ import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import javax.annotation.Nonnull;
import java.io.IOException; import java.io.IOException;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -123,37 +127,38 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
int bx = chunk.getX() << 4; int bx = chunk.getX() << 4;
int bz = chunk.getZ() << 4; int bz = chunk.getZ() << 4;
Map<BlockVector3, CompoundTag> tilesFrom = get.getTiles(); Map<BlockVector3, FaweCompoundTag> tilesFrom = get.tiles();
Map<BlockVector3, CompoundTag> tilesTo = set.getTiles(); Map<BlockVector3, FaweCompoundTag> tilesTo = set.tiles();
if (!tilesFrom.isEmpty()) { if (!tilesFrom.isEmpty()) {
for (Map.Entry<BlockVector3, CompoundTag> entry : tilesFrom.entrySet()) { for (Map.Entry<BlockVector3, FaweCompoundTag> entry : tilesFrom.entrySet()) {
BlockVector3 pos = entry.getKey(); BlockVector3 pos = entry.getKey();
BlockState fromBlock = get.getBlock(pos.x() & 15, pos.y(), pos.z() & 15); BlockState fromBlock = get.getBlock(pos.x() & 15, pos.y(), pos.z() & 15);
BlockState toBlock = set.getBlock(pos.x() & 15, pos.y(), pos.z() & 15); BlockState toBlock = set.getBlock(pos.x() & 15, pos.y(), pos.z() & 15);
if (fromBlock != toBlock || tilesTo.containsKey(pos)) { if (fromBlock != toBlock || tilesTo.containsKey(pos)) {
addTileRemove(MainUtil.setPosition(entry.getValue(), entry.getKey().x(), entry.getKey().y(), addTileRemove(NbtUtils.withPosition(entry.getValue(), entry.getKey().x(), entry.getKey().y(),
entry.getKey().z())); entry.getKey().z()
));
} }
} }
} }
if (!tilesTo.isEmpty()) { if (!tilesTo.isEmpty()) {
for (Map.Entry<BlockVector3, CompoundTag> entry : tilesTo.entrySet()) { for (Map.Entry<BlockVector3, FaweCompoundTag> entry : tilesTo.entrySet()) {
BlockVector3 pos = entry.getKey(); BlockVector3 pos = entry.getKey();
addTileCreate(MainUtil.setPosition(entry.getValue(), pos.x() + bx, pos.y(), pos.z() + bz)); addTileCreate(NbtUtils.withPosition(entry.getValue(), pos.x() + bx, pos.y(), pos.z() + bz));
} }
} }
Set<UUID> entRemoves = set.getEntityRemoves(); Set<UUID> entRemoves = set.getEntityRemoves();
if (!entRemoves.isEmpty()) { if (!entRemoves.isEmpty()) {
for (UUID uuid : entRemoves) { for (UUID uuid : entRemoves) {
CompoundTag found = get.getEntity(uuid); FaweCompoundTag found = get.entity(uuid);
if (found != null) { if (found != null) {
addEntityRemove(found); addEntityRemove(found);
} }
} }
} }
Set<CompoundTag> ents = set.getEntities(); Collection<FaweCompoundTag> ents = set.entities();
if (!ents.isEmpty()) { if (!ents.isEmpty()) {
for (CompoundTag tag : ents) { for (FaweCompoundTag tag : ents) {
addEntityCreate(tag); addEntityCreate(tag);
} }
} }
@ -204,9 +209,9 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
BiomeType[] biomeSection = biomes[layer - set.getMinSectionPosition()]; BiomeType[] biomeSection = biomes[layer - set.getMinSectionPosition()];
int index = 0; int index = 0;
int yy = layer << 4; int yy = layer << 4;
for (int y = 0; y < 16; y+= 4) { for (int y = 0; y < 16; y += 4) {
for (int z = 0; z < 16; z+= 4) { for (int z = 0; z < 16; z += 4) {
for (int x = 0; x < 16; x+= 4, index++) { for (int x = 0; x < 16; x += 4, index++) {
BiomeType newBiome = biomeSection[index]; BiomeType newBiome = biomeSection[index];
if (newBiome != null) { if (newBiome != null) {
BiomeType oldBiome = get.getBiomeType(x, yy + y, z); BiomeType oldBiome = get.getBiomeType(x, yy + y, z);
@ -237,13 +242,62 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
return ProcessorScope.READING_SET_BLOCKS; return ProcessorScope.READING_SET_BLOCKS;
} }
public abstract void addTileCreate(CompoundTag tag); @Deprecated(forRemoval = true, since = "TODO")
public void addTileCreate(CompoundTag tag) {
addTileCreate(adapt(tag));
}
public abstract void addTileRemove(CompoundTag tag); @SuppressWarnings({"deprecation"})
private static @Nonnull FaweCompoundTag adapt(CompoundTag tag) {
return FaweCompoundTag.of(tag.toLinTag());
}
public abstract void addEntityRemove(CompoundTag tag); /**
* Creates a tile/block entity create change to this change set.
*
* @param tag the tile/block entity to add.
* @since TODO
*/
public abstract void addTileCreate(FaweCompoundTag tag);
public abstract void addEntityCreate(CompoundTag tag); @Deprecated(forRemoval = true, since = "TODO")
public void addTileRemove(CompoundTag tag) {
addTileRemove(adapt(tag));
}
/**
* Creates a tile/block entity remove change to this change set.
*
* @param tag the tile/block entity to remove.
* @since TODO
*/
public abstract void addTileRemove(FaweCompoundTag tag);
@Deprecated(forRemoval = true, since = "TODO")
public void addEntityRemove(CompoundTag tag) {
addEntityRemove(adapt(tag));
}
/**
* Creates an entity remove change to this change set.
*
* @param tag the entity to remove.
* @since TODO
*/
public abstract void addEntityRemove(FaweCompoundTag tag);
@Deprecated(forRemoval = true, since = "TODO")
public void addEntityCreate(CompoundTag tag) {
addEntityCreate(adapt(tag));
}
/**
* Creates an entity create change to this change set.
*
* @param tag the entity to add.
* @since TODO
*/
public abstract void addEntityCreate(FaweCompoundTag tag);
public abstract void addBiomeChange(int x, int y, int z, BiomeType from, BiomeType to); public abstract void addBiomeChange(int x, int y, int z, BiomeType from, BiomeType to);
@ -280,13 +334,15 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
} }
public void add(EntityCreate change) { public void add(EntityCreate change) {
CompoundTag tag = change.state.getNbtData(); LinCompoundTag tag = change.state.getNbt();
addEntityCreate(MainUtil.setEntityInfo(tag, change.getEntity())); assert tag != null;
addEntityCreate(FaweCompoundTag.of(NbtUtils.withEntityInfo(tag, change.getEntity())));
} }
public void add(EntityRemove change) { public void add(EntityRemove change) {
CompoundTag tag = change.state.getNbtData(); LinCompoundTag tag = change.state.getNbt();
addEntityRemove(MainUtil.setEntityInfo(tag, change.getEntity())); assert tag != null;
addEntityRemove(FaweCompoundTag.of(NbtUtils.withEntityInfo(tag, change.getEntity())));
} }
@Override @Override
@ -304,9 +360,9 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
public void add(BlockChange change) { public void add(BlockChange change) {
try { try {
BlockVector3 loc = change.getPosition(); BlockVector3 loc = change.position();
BaseBlock from = change.previous(); BaseBlock from = change.previous();
BaseBlock to = change.getCurrent(); BaseBlock to = change.current();
add(loc, from, to); add(loc, from, to);
} catch (Exception e) { } catch (Exception e) {
LOGGER.catching(e); LOGGER.catching(e);
@ -326,31 +382,28 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
public void add(int x, int y, int z, BaseBlock from, BaseBlock to) { public void add(int x, int y, int z, BaseBlock from, BaseBlock to) {
try { try {
if (from.hasNbtData()) { LinCompoundTag nbt = from.getNbt();
CompoundTag nbt = from.getNbtData(); if (nbt != null) {
assert nbt != null; addTileRemove(FaweCompoundTag.of(NbtUtils.withPosition(nbt, x, y, z)));
addTileRemove(MainUtil.setPosition(nbt, x, y, z));
} }
if (to.hasNbtData()) { nbt = to.getNbt();
CompoundTag nbt = to.getNbtData(); if (nbt != null) {
assert nbt != null; addTileCreate(FaweCompoundTag.of(NbtUtils.withPosition(nbt, x, y, z)));
addTileCreate(MainUtil.setPosition(nbt, x, y, z));
} }
int combinedFrom = from.getOrdinal(); int combinedFrom = from.getOrdinal();
int combinedTo = to.getOrdinal(); int combinedTo = to.getOrdinal();
add(x, y, z, combinedFrom, combinedTo); add(x, y, z, combinedFrom, combinedTo);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); LOGGER.catching(e);
} }
} }
public void add(int x, int y, int z, int combinedFrom, BaseBlock to) { public void add(int x, int y, int z, int combinedFrom, BaseBlock to) {
try { try {
if (to.hasNbtData()) { LinCompoundTag nbt = to.getNbt();
CompoundTag nbt = to.getNbtData(); if (nbt != null) {
assert nbt != null; addTileCreate(FaweCompoundTag.of(NbtUtils.withPosition(nbt, x, y, z)));
addTileCreate(MainUtil.setPosition(nbt, x, y, z));
} }
int combinedTo = to.getInternalId(); int combinedTo = to.getInternalId();
add(x, y, z, combinedFrom, combinedTo); add(x, y, z, combinedFrom, combinedTo);

View File

@ -1,6 +1,6 @@
package com.fastasyncworldedit.core.history.changeset; package com.fastasyncworldedit.core.history.changeset;
import com.sk89q.jnbt.CompoundTag; import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
@ -46,26 +46,6 @@ public class AbstractDelegateChangeSet extends AbstractChangeSet {
parent.flush(); parent.flush();
} }
@Override
public void addTileCreate(CompoundTag tag) {
parent.addTileCreate(tag);
}
@Override
public void addTileRemove(CompoundTag tag) {
parent.addTileRemove(tag);
}
@Override
public void addEntityRemove(CompoundTag tag) {
parent.addEntityRemove(tag);
}
@Override
public void addEntityCreate(CompoundTag tag) {
parent.addEntityCreate(tag);
}
@Override @Override
public void addBiomeChange(int x, int y, int z, BiomeType from, BiomeType to) { public void addBiomeChange(int x, int y, int z, BiomeType from, BiomeType to) {
parent.addBiomeChange(x, y, z, from, to); parent.addBiomeChange(x, y, z, from, to);
@ -146,6 +126,26 @@ public class AbstractDelegateChangeSet extends AbstractChangeSet {
return parent.forwardIterator(); return parent.forwardIterator();
} }
@Override
public void addTileCreate(final FaweCompoundTag tag) {
parent.addTileCreate(tag);
}
@Override
public void addTileRemove(final FaweCompoundTag tag) {
parent.addTileRemove(tag);
}
@Override
public void addEntityRemove(final FaweCompoundTag tag) {
parent.addEntityRemove(tag);
}
@Override
public void addEntityCreate(final FaweCompoundTag tag) {
parent.addEntityCreate(tag);
}
@Override @Override
public void close() throws IOException { public void close() throws IOException {
parent.close(); parent.close();

View File

@ -1,8 +1,6 @@
package com.fastasyncworldedit.core.history.changeset; package com.fastasyncworldedit.core.history.changeset;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.extent.inventory.BlockBagException; import com.sk89q.worldedit.extent.inventory.BlockBagException;
import com.sk89q.worldedit.extent.inventory.UnplaceableBlockException; import com.sk89q.worldedit.extent.inventory.UnplaceableBlockException;
@ -109,13 +107,4 @@ public class BlockBagChangeSet extends AbstractDelegateChangeSet {
super.add(x, y, z, combinedFrom, combinedTo); super.add(x, y, z, combinedFrom, combinedTo);
} }
@Override
public void addTileCreate(CompoundTag nbt) {
if (nbt.containsKey("items")) {
Map<String, Tag<?, ?>> map = new HashMap<>(nbt.getValue());
map.remove("items");
}
super.addTileCreate(nbt);
}
} }

View File

@ -10,6 +10,7 @@ import com.fastasyncworldedit.core.history.change.MutableTileChange;
import com.fastasyncworldedit.core.internal.exception.FaweSmallEditUnsupportedException; import com.fastasyncworldedit.core.internal.exception.FaweSmallEditUnsupportedException;
import com.fastasyncworldedit.core.internal.io.FaweInputStream; import com.fastasyncworldedit.core.internal.io.FaweInputStream;
import com.fastasyncworldedit.core.internal.io.FaweOutputStream; import com.fastasyncworldedit.core.internal.io.FaweOutputStream;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.util.MainUtil; import com.fastasyncworldedit.core.util.MainUtil;
import com.fastasyncworldedit.core.util.MathMan; import com.fastasyncworldedit.core.util.MathMan;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
@ -21,9 +22,12 @@ import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockTypes; import com.sk89q.worldedit.world.block.BlockTypes;
import org.enginehub.linbus.stream.LinBinaryIO;
import org.enginehub.linbus.tree.LinRootEntry;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.io.DataOutput;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -398,56 +402,44 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
} }
@Override @Override
public void addTileCreate(CompoundTag tag) { public void addTileCreate(final FaweCompoundTag tag) {
if (tag == null) {
return;
}
blockSize++; blockSize++;
try { try {
NBTOutputStream nbtos = getTileCreateOS(); DataOutput nbtos = getTileCreateOS();
nbtos.writeTag(tag); LinBinaryIO.write(nbtos, new LinRootEntry("tile-create", tag.linTag()));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Override @Override
public void addTileRemove(CompoundTag tag) { public void addTileRemove(final FaweCompoundTag tag) {
if (tag == null) {
return;
}
blockSize++; blockSize++;
try { try {
NBTOutputStream nbtos = getTileRemoveOS(); DataOutput nbtos = getTileRemoveOS();
nbtos.writeTag(tag); LinBinaryIO.write(nbtos, new LinRootEntry("tile-remove", tag.linTag()));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Override @Override
public void addEntityRemove(CompoundTag tag) { public void addEntityRemove(final FaweCompoundTag tag) {
if (tag == null) {
return;
}
blockSize++; blockSize++;
try { try {
NBTOutputStream nbtos = getEntityRemoveOS(); DataOutput nbtos = getEntityRemoveOS();
nbtos.writeTag(tag); LinBinaryIO.write(nbtos, new LinRootEntry("entity-remove", tag.linTag()));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@Override @Override
public void addEntityCreate(CompoundTag tag) { public void addEntityCreate(final FaweCompoundTag tag) {
if (tag == null) {
return;
}
blockSize++; blockSize++;
try { try {
NBTOutputStream nbtos = getEntityCreateOS(); DataOutput nbtos = getEntityCreateOS();
nbtos.writeTag(tag); LinBinaryIO.write(nbtos, new LinRootEntry("entity-create", tag.linTag()));
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -1,6 +1,6 @@
package com.fastasyncworldedit.core.history.changeset; package com.fastasyncworldedit.core.history.changeset;
import com.sk89q.jnbt.CompoundTag; import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.worldedit.extent.inventory.BlockBag; import com.sk89q.worldedit.extent.inventory.BlockBag;
import com.sk89q.worldedit.history.change.Change; import com.sk89q.worldedit.history.change.Change;
import com.sk89q.worldedit.world.World; import com.sk89q.worldedit.world.World;
@ -25,22 +25,22 @@ public class NullChangeSet extends AbstractChangeSet {
} }
@Override @Override
public final void addTileCreate(CompoundTag tag) { public void addTileCreate(final FaweCompoundTag tag) {
} }
@Override @Override
public final void addTileRemove(CompoundTag tag) { public void addTileRemove(final FaweCompoundTag tag) {
} }
@Override @Override
public final void addEntityRemove(CompoundTag tag) { public void addEntityRemove(final FaweCompoundTag tag) {
} }
@Override @Override
public final void addEntityCreate(CompoundTag tag) { public void addEntityCreate(final FaweCompoundTag tag) {
} }

View File

@ -0,0 +1,7 @@
package com.fastasyncworldedit.core.nbt;
import org.enginehub.linbus.tree.LinCompoundTag;
record EagerFaweCompoundTag(LinCompoundTag linTag) implements FaweCompoundTag {
}

View File

@ -0,0 +1,44 @@
package com.fastasyncworldedit.core.nbt;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.sk89q.worldedit.util.concurrency.LazyReference;
import org.enginehub.linbus.tree.LinCompoundTag;
/**
* A wrapper around compound tags, potentially lazily transformed.
* @since TODO
*/
public sealed interface FaweCompoundTag permits EagerFaweCompoundTag, LazyFaweCompoundTag {
/**
* {@return a lazy compound component backed by a lazy reference}
* @param lazyReference the lazy reference to the actual compound tag
*/
static FaweCompoundTag of(LazyReference<? extends LinCompoundTag> lazyReference) {
return new LazyFaweCompoundTag(lazyReference::getValue);
}
/**
* {@return a lazy compound component backed by a supplier}
* Invocations to the supplier are memoized.
* @param supplier the supplier for the actual compound tag
*/
static FaweCompoundTag of(Supplier<? extends LinCompoundTag> supplier) {
return new LazyFaweCompoundTag(Suppliers.memoize(supplier));
}
/**
* {@return a direct reference tho the given compound tag}
* @param linCompoundTag the tag to wrap
*/
static FaweCompoundTag of(LinCompoundTag linCompoundTag) {
return new EagerFaweCompoundTag(linCompoundTag);
}
/**
* {@return the underlying tag}
*/
LinCompoundTag linTag();
}

View File

@ -0,0 +1,14 @@
package com.fastasyncworldedit.core.nbt;
import org.enginehub.linbus.tree.LinCompoundTag;
import java.util.function.Supplier;
record LazyFaweCompoundTag(Supplier<? extends LinCompoundTag> linTagSupplier) implements FaweCompoundTag {
@Override
public LinCompoundTag linTag() {
return this.linTagSupplier().get();
}
}

View File

@ -3,6 +3,8 @@ package com.fastasyncworldedit.core.queue;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream; import com.fastasyncworldedit.core.internal.io.FastByteArrayOutputStream;
import com.fastasyncworldedit.core.internal.io.FaweOutputStream; import com.fastasyncworldedit.core.internal.io.FaweOutputStream;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.util.collection.AdaptedMap;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.Capability; import com.sk89q.worldedit.extension.platform.Capability;
@ -12,10 +14,13 @@ import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import com.sk89q.worldedit.world.registry.BlockRegistry; import com.sk89q.worldedit.world.registry.BlockRegistry;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.io.IOException; import java.io.IOException;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.IntStream; import java.util.stream.IntStream;
/** /**
@ -54,11 +59,38 @@ public interface IBlocks extends Trimable {
BlockState getBlock(int x, int y, int z); BlockState getBlock(int x, int y, int z);
Map<BlockVector3, CompoundTag> getTiles(); @Deprecated(forRemoval = true, since = "TODO")
default Map<BlockVector3, CompoundTag> getTiles() {
return AdaptedMap.immutable(tiles(), pos -> pos, IBlocks::toCompoundTag);
}
CompoundTag getTile(int x, int y, int z); Map<BlockVector3, FaweCompoundTag> tiles();
Set<CompoundTag> getEntities(); @Deprecated(forRemoval = true, since = "TODO")
default CompoundTag getTile(int x, int y, int z) {
final FaweCompoundTag tile = tile(x, y, z);
if (tile == null) {
return null;
}
return toCompoundTag(tile);
}
@SuppressWarnings({"deprecation"})
private static @Nonnull CompoundTag toCompoundTag(FaweCompoundTag tile) {
return new CompoundTag(tile.linTag());
}
@Nullable
FaweCompoundTag tile(int x, int y, int z);
@Deprecated(forRemoval = true, since = "TODO")
default Set<CompoundTag> getEntities() {
return entities().stream()
.map(IBlocks::toCompoundTag)
.collect(Collectors.toSet());
}
Collection<FaweCompoundTag> entities();
BiomeType getBiomeType(int x, int y, int z); BiomeType getBiomeType(int x, int y, int z);

View File

@ -1,11 +1,7 @@
package com.fastasyncworldedit.core.queue; package com.fastasyncworldedit.core.queue;
import com.sk89q.jnbt.CompoundTag; import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.DoubleTag; import com.fastasyncworldedit.core.util.NbtUtils;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.NBTUtils;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
@ -16,6 +12,12 @@ import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinDoubleTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinStringTag;
import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.LinTagType;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -39,9 +41,9 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
} }
@Override @Override
default boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { default boolean tile(int x, int y, int z, FaweCompoundTag tile) throws WorldEditException {
final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4); final IChunk chunk = getOrCreateChunk(x >> 4, z >> 4);
return chunk.setTile(x & 15, y, z & 15, tile); return chunk.tile(x & 15, y, z & 15, tile);
} }
@Override @Override
@ -124,19 +126,19 @@ public interface IChunkExtent<T extends IChunk> extends Extent {
@Override @Override
default Entity createEntity(Location location, BaseEntity entity, UUID uuid) { default Entity createEntity(Location location, BaseEntity entity, UUID uuid) {
final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4); final IChunk chunk = getOrCreateChunk(location.getBlockX() >> 4, location.getBlockZ() >> 4);
Map<String, Tag<?, ?>> map = new HashMap<>(entity.getNbtData().getValue()); //do not modify original entity data Map<String, LinTag<?>> map = new HashMap<>(entity.getNbt().value()); //do not modify original entity data
map.put("Id", new StringTag(entity.getType().getName())); map.put("Id", LinStringTag.of(entity.getType().getName()));
//Set pos //Set pos
List<DoubleTag> posList = new ArrayList<>(); List<LinDoubleTag> posList = new ArrayList<>();
posList.add(new DoubleTag(location.x())); posList.add(LinDoubleTag.of(location.x()));
posList.add(new DoubleTag(location.y())); posList.add(LinDoubleTag.of(location.y()));
posList.add(new DoubleTag(location.z())); posList.add(LinDoubleTag.of(location.z()));
map.put("Pos", new ListTag(DoubleTag.class, posList)); map.put("Pos", LinListTag.of(LinTagType.doubleTag(), posList));
NBTUtils.addUUIDToMap(map, uuid); NbtUtils.addUUIDToMap(map, uuid);
chunk.setEntity(new CompoundTag(map)); chunk.entity(FaweCompoundTag.of(LinCompoundTag.of(map)));
return new IChunkEntity(this, location, uuid, entity); return new IChunkEntity(this, location, uuid, entity);
} }

View File

@ -1,6 +1,7 @@
package com.fastasyncworldedit.core.queue; package com.fastasyncworldedit.core.queue;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.InputExtent; import com.sk89q.worldedit.extent.InputExtent;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -46,7 +47,26 @@ public interface IChunkGet extends IBlocks, Trimable, InputExtent, ITileInput {
<T extends Future<T>> T call(IChunkSet set, Runnable finalize); <T extends Future<T>> T call(IChunkSet set, Runnable finalize);
CompoundTag getEntity(UUID uuid); @Deprecated(forRemoval = true, since = "TODO")
default CompoundTag getEntity(UUID uuid) {
final FaweCompoundTag entity = entity(uuid);
if (entity == null) {
return null;
}
return new CompoundTag(entity.linTag());
}
/**
* {@return the compound tag describing the entity with the given UUID, if any}
* @param uuid the uuid of the entity
*/
@Nullable FaweCompoundTag entity(UUID uuid);
@Override
@Deprecated(forRemoval = true, since = "TODO")
default CompoundTag getTile(int x, int y, int z) {
return IBlocks.super.getTile(x, y, z);
}
boolean isCreateCopy(); boolean isCreateCopy();

View File

@ -1,7 +1,9 @@
package com.fastasyncworldedit.core.queue; package com.fastasyncworldedit.core.queue;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.extent.OutputExtent; import com.sk89q.worldedit.extent.OutputExtent;
import com.sk89q.worldedit.function.operation.Operation; import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
@ -36,7 +38,12 @@ public interface IChunkSet extends IBlocks, OutputExtent {
boolean isEmpty(); boolean isEmpty();
@Override @Override
boolean setTile(int x, int y, int z, CompoundTag tile); @Deprecated(forRemoval = true, since = "TODO")
default boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException {
return tile(x, y, z, FaweCompoundTag.of(tile.toLinTag()));
}
boolean tile(int x, int y, int z, FaweCompoundTag tag);
@Override @Override
void setBlockLight(int x, int y, int z, int value); void setBlockLight(int x, int y, int z, int value);
@ -53,7 +60,12 @@ public interface IChunkSet extends IBlocks, OutputExtent {
void setFullBright(int layer); void setFullBright(int layer);
void setEntity(CompoundTag tag); @Deprecated(forRemoval = true, since = "TODO")
default void setEntity(CompoundTag tag) {
entity(FaweCompoundTag.of(tag::toLinTag));
}
void entity(FaweCompoundTag tag);
void removeEntity(UUID uuid); void removeEntity(UUID uuid);

View File

@ -2,6 +2,7 @@ package com.fastasyncworldedit.core.queue;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
@Deprecated(forRemoval = true, since = "TODO")
public interface ITileInput { public interface ITileInput {
CompoundTag getTile(int x, int y, int z); CompoundTag getTile(int x, int y, int z);

View File

@ -2,9 +2,9 @@ package com.fastasyncworldedit.core.queue.implementation.blocks;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.util.collection.MemBlockSet; import com.fastasyncworldedit.core.util.collection.MemBlockSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
@ -13,6 +13,7 @@ import com.sk89q.worldedit.world.block.BlockTypesCache;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -74,7 +75,7 @@ public class BitSetBlocks implements IChunkSet {
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tile) { public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tag) {
return false; return false;
} }
@ -107,7 +108,7 @@ public class BitSetBlocks implements IChunkSet {
} }
@Override @Override
public void setEntity(CompoundTag tag) { public void entity(final FaweCompoundTag tag) {
} }
@Override @Override
@ -181,18 +182,18 @@ public class BitSetBlocks implements IChunkSet {
} }
@Override @Override
public Map<BlockVector3, CompoundTag> getTiles() { public Map<BlockVector3, FaweCompoundTag> tiles() {
return Collections.emptyMap(); return Collections.emptyMap();
} }
@Override @Override
public CompoundTag getTile(int x, int y, int z) { public @Nullable FaweCompoundTag tile(final int x, final int y, final int z) {
return null; return null;
} }
@Override @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
return Collections.emptySet(); return Collections.emptyList();
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package com.fastasyncworldedit.core.queue.implementation.blocks; package com.fastasyncworldedit.core.queue.implementation.blocks;
import com.fastasyncworldedit.core.queue.IBlocks;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
@ -20,7 +21,7 @@ public abstract class CharGetBlocks extends CharBlocks implements IChunkGet {
@Override @Override
public BaseBlock getFullBlock(int x, int y, int z) { public BaseBlock getFullBlock(int x, int y, int z) {
BlockState state = BlockTypesCache.states[get(x, y, z)]; BlockState state = BlockTypesCache.states[get(x, y, z)];
return state.toBaseBlock(this, x, y, z); return state.toBaseBlock((IBlocks) this, x, y, z);
} }
@Override @Override

View File

@ -4,16 +4,18 @@ import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.configuration.Settings; import com.fastasyncworldedit.core.configuration.Settings;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.math.BlockVector3ChunkMap; import com.fastasyncworldedit.core.math.BlockVector3ChunkMap;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.queue.Pool; import com.fastasyncworldedit.core.queue.Pool;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockStateHolder; import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockTypesCache; import com.sk89q.worldedit.world.block.BlockTypesCache;
import javax.annotation.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashSet; import java.util.HashSet;
@ -36,8 +38,8 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
public BiomeType[][] biomes; public BiomeType[][] biomes;
public char[][] light; public char[][] light;
public char[][] skyLight; public char[][] skyLight;
public BlockVector3ChunkMap<CompoundTag> tiles; public BlockVector3ChunkMap<FaweCompoundTag> tiles;
public HashSet<CompoundTag> entities; public HashSet<FaweCompoundTag> entities;
public HashSet<UUID> entityRemoves; public HashSet<UUID> entityRemoves;
public EnumMap<HeightMapType, int[]> heightMaps; public EnumMap<HeightMapType, int[]> heightMaps;
private boolean fastMode = false; private boolean fastMode = false;
@ -71,17 +73,17 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
} }
@Override @Override
public Map<BlockVector3, CompoundTag> getTiles() { public Map<BlockVector3, FaweCompoundTag> tiles() {
return tiles == null ? Collections.emptyMap() : tiles; return tiles == null ? Collections.emptyMap() : tiles;
} }
@Override @Override
public CompoundTag getTile(int x, int y, int z) { public @Nullable FaweCompoundTag tile(final int x, final int y, final int z) {
return tiles == null ? null : tiles.get(x, y, z); return tiles == null ? null : tiles.get(x, y, z);
} }
@Override @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
return entities == null ? Collections.emptySet() : entities; return entities == null ? Collections.emptySet() : entities;
} }
@ -132,12 +134,12 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tile) { public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tag) {
if (tiles == null) { if (tiles == null) {
tiles = new BlockVector3ChunkMap<>(); tiles = new BlockVector3ChunkMap<>();
} }
updateSectionIndexRange(y >> 4); updateSectionIndexRange(y >> 4);
tiles.put(x, y, z, tile); tiles.put(x, y, z, tag);
return true; return true;
} }
@ -259,7 +261,7 @@ public class CharSetBlocks extends CharBlocks implements IChunkSet {
} }
@Override @Override
public void setEntity(CompoundTag tag) { public void entity(final FaweCompoundTag tag) {
if (entities == null) { if (entities == null) {
entities = new HashSet<>(); entities = new HashSet<>();
} }

View File

@ -2,10 +2,10 @@ package com.fastasyncworldedit.core.queue.implementation.blocks;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBlocks; import com.fastasyncworldedit.core.queue.IBlocks;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.biome.BiomeTypes; import com.sk89q.worldedit.world.biome.BiomeTypes;
@ -15,9 +15,9 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.Future; import java.util.concurrent.Future;
@ -48,24 +48,19 @@ public final class NullChunkGet implements IChunkGet {
return BlockTypes.AIR.getDefaultState(); return BlockTypes.AIR.getDefaultState();
} }
@Nonnull @Override
public Map<BlockVector3, CompoundTag> getTiles() { public Map<BlockVector3, FaweCompoundTag> tiles() {
return Collections.emptyMap(); return Collections.emptyMap();
} }
@Nullable @Override
public CompoundTag getTile(int x, int y, int z) { public @Nullable FaweCompoundTag tile(final int x, final int y, final int z) {
return null; return null;
} }
@Nullable @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
return null; return Collections.emptyList();
}
@Nullable
public CompoundTag getEntity(@Nonnull UUID uuid) {
return null;
} }
@Override @Override
@ -123,6 +118,11 @@ public final class NullChunkGet implements IChunkGet {
return null; return null;
} }
@Override
public @Nullable FaweCompoundTag entity(final UUID uuid) {
return null;
}
@Nonnull @Nonnull
public char[] load(int layer) { public char[] load(int layer) {
return FaweCache.INSTANCE.EMPTY_CHAR_4096; return FaweCache.INSTANCE.EMPTY_CHAR_4096;

View File

@ -4,9 +4,9 @@ import com.fastasyncworldedit.core.Fawe;
import com.fastasyncworldedit.core.FaweCache; import com.fastasyncworldedit.core.FaweCache;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.math.BlockVector3ChunkMap; import com.fastasyncworldedit.core.math.BlockVector3ChunkMap;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBlocks; import com.fastasyncworldedit.core.queue.IBlocks;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -17,6 +17,7 @@ import org.apache.logging.log4j.Logger;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.HashMap; import java.util.HashMap;
@ -44,8 +45,8 @@ public class ThreadUnsafeCharBlocks implements IChunkSet, IBlocks {
private BiomeType[][] biomes; private BiomeType[][] biomes;
private char[][] light; private char[][] light;
private char[][] skyLight; private char[][] skyLight;
private BlockVector3ChunkMap<CompoundTag> tiles; private BlockVector3ChunkMap<FaweCompoundTag> tiles;
private HashSet<CompoundTag> entities; private HashSet<FaweCompoundTag> entities;
private HashSet<UUID> entityRemoves; private HashSet<UUID> entityRemoves;
private Map<HeightMapType, int[]> heightMaps; private Map<HeightMapType, int[]> heightMaps;
private boolean fastMode; private boolean fastMode;
@ -64,8 +65,8 @@ public class ThreadUnsafeCharBlocks implements IChunkSet, IBlocks {
int sectionCount, int sectionCount,
char[][] light, char[][] light,
char[][] skyLight, char[][] skyLight,
BlockVector3ChunkMap<CompoundTag> tiles, BlockVector3ChunkMap<FaweCompoundTag> tiles,
HashSet<CompoundTag> entities, HashSet<FaweCompoundTag> entities,
HashSet<UUID> entityRemoves, HashSet<UUID> entityRemoves,
Map<HeightMapType, int[]> heightMaps, Map<HeightMapType, int[]> heightMaps,
char defaultOrdinal, char defaultOrdinal,
@ -116,18 +117,18 @@ public class ThreadUnsafeCharBlocks implements IChunkSet, IBlocks {
} }
@Override @Override
public Map<BlockVector3, CompoundTag> getTiles() { public Map<BlockVector3, FaweCompoundTag> tiles() {
return tiles == null ? Collections.emptyMap() : tiles; return tiles == null ? Collections.emptyMap() : tiles;
} }
@Override @Override
public CompoundTag getTile(int x, int y, int z) { public @Nullable FaweCompoundTag tile(final int x, final int y, final int z) {
return tiles == null ? null : tiles.get(x, y, z); return tiles == null ? null : tiles.get(x, y, z);
} }
@Override @Override
public Set<CompoundTag> getEntities() { public Collection<FaweCompoundTag> entities() {
return entities == null ? Collections.emptySet() : entities; return entities == null ? Collections.emptyList() : entities;
} }
@Override @Override
@ -268,12 +269,12 @@ public class ThreadUnsafeCharBlocks implements IChunkSet, IBlocks {
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tile) { public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tag) {
updateSectionIndexRange(y >> 4); updateSectionIndexRange(y >> 4);
if (tiles == null) { if (tiles == null) {
tiles = new BlockVector3ChunkMap<>(); tiles = new BlockVector3ChunkMap<>();
} }
tiles.put(x, y, z, tile); tiles.put(x, y, z, tag);
return true; return true;
} }
@ -358,7 +359,7 @@ public class ThreadUnsafeCharBlocks implements IChunkSet, IBlocks {
} }
@Override @Override
public void setEntity(CompoundTag tag) { public void entity(final FaweCompoundTag tag) {
if (entities == null) { if (entities == null) {
entities = new HashSet<>(); entities = new HashSet<>();
} }

View File

@ -3,6 +3,7 @@ package com.fastasyncworldedit.core.queue.implementation.chunk;
import com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock; import com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock;
import com.fastasyncworldedit.core.extent.processor.EmptyBatchProcessor; import com.fastasyncworldedit.core.extent.processor.EmptyBatchProcessor;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.Filter; import com.fastasyncworldedit.core.queue.Filter;
import com.fastasyncworldedit.core.queue.IChunk; import com.fastasyncworldedit.core.queue.IChunk;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
@ -11,7 +12,6 @@ import com.fastasyncworldedit.core.queue.IQueueChunk;
import com.fastasyncworldedit.core.queue.IQueueExtent; import com.fastasyncworldedit.core.queue.IQueueExtent;
import com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent; import com.fastasyncworldedit.core.queue.implementation.ParallelQueueExtent;
import com.fastasyncworldedit.core.util.MemUtil; import com.fastasyncworldedit.core.util.MemUtil;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.internal.util.LogManagerCompat; import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
@ -22,6 +22,7 @@ import com.sk89q.worldedit.world.block.BlockStateHolder;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
@ -76,18 +77,8 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tag) { public void entity(final FaweCompoundTag tag) {
return delegate.set(this).setTile(x, y, z, tag); delegate.set(this).entity(tag);
}
@Override
public CompoundTag getTile(int x, int y, int z) {
return delegate.set(this).getTile(x, y, z);
}
@Override
public void setEntity(CompoundTag tag) {
delegate.set(this).setEntity(tag);
} }
@Override @Override
@ -163,11 +154,6 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
return isInit; return isInit;
} }
@Override
public CompoundTag getEntity(UUID uuid) {
return delegate.get(this).getEntity(uuid);
}
@Override @Override
public int setCreateCopy(boolean createCopy) { public int setCreateCopy(boolean createCopy) {
this.createCopy = createCopy; this.createCopy = createCopy;
@ -879,16 +865,6 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
} }
}; };
@Override
public Map<BlockVector3, CompoundTag> getTiles() {
return delegate.get(this).getTiles();
}
@Override
public Set<CompoundTag> getEntities() {
return delegate.get(this).getEntities();
}
@Override @Override
public boolean hasSection(int layer) { public boolean hasSection(int layer) {
return chunkExisting != null && chunkExisting.hasSection(layer); return chunkExisting != null && chunkExisting.hasSection(layer);
@ -946,6 +922,11 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
return chunkSet == null || chunkSet.isEmpty(); return chunkSet == null || chunkSet.isEmpty();
} }
@Override
public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tag) {
return false;
}
/** /**
* Get or create the existing part of this chunk. * Get or create the existing part of this chunk.
*/ */
@ -1093,6 +1074,21 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
return delegate.getBlock(this, x, y, z); return delegate.getBlock(this, x, y, z);
} }
@Override
public Map<BlockVector3, FaweCompoundTag> tiles() {
return delegate.get(this).tiles();
}
@Override
public @Nullable FaweCompoundTag tile(final int x, final int y, final int z) {
return delegate.get(this).tile(x, y, z);
}
@Override
public Collection<FaweCompoundTag> entities() {
return delegate.get(this).entities();
}
@Override @Override
public BaseBlock getFullBlock(int x, int y, int z) { public BaseBlock getFullBlock(int x, int y, int z) {
return delegate.getFullBlock(this, x, y, z); return delegate.getFullBlock(this, x, y, z);
@ -1158,6 +1154,11 @@ public class ChunkHolder<T extends Future<T>> implements IQueueChunk<T> {
return delegate.getHeightMap(this, type); return delegate.getHeightMap(this, type);
} }
@Override
public @Nullable FaweCompoundTag entity(final UUID uuid) {
return delegate.get(this).entity(uuid);
}
public interface IBlockDelegate { public interface IBlockDelegate {
<C extends Future<C>> IChunkGet get(ChunkHolder<C> chunk); <C extends Future<C>> IChunkGet get(ChunkHolder<C> chunk);

View File

@ -2,10 +2,10 @@ package com.fastasyncworldedit.core.queue.implementation.chunk;
import com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock; import com.fastasyncworldedit.core.extent.filter.block.ChunkFilterBlock;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.Filter; import com.fastasyncworldedit.core.queue.Filter;
import com.fastasyncworldedit.core.queue.IChunkSet; import com.fastasyncworldedit.core.queue.IChunkSet;
import com.fastasyncworldedit.core.queue.IQueueChunk; import com.fastasyncworldedit.core.queue.IQueueChunk;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region; import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.biome.BiomeType;
@ -16,6 +16,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@ -53,13 +54,11 @@ public final class NullChunk implements IQueueChunk {
return false; return false;
} }
public boolean setTile(int x, int y, int z, @Nonnull CompoundTag tag) { @Override
public boolean tile(final int x, final int y, final int z, final FaweCompoundTag tag) {
return false; return false;
} }
public void setEntity(@Nonnull CompoundTag tag) {
}
public void removeEntity(@Nonnull UUID uuid) { public void removeEntity(@Nonnull UUID uuid) {
} }
@ -112,6 +111,10 @@ public final class NullChunk implements IQueueChunk {
public void setFullBright(int layer) { public void setFullBright(int layer) {
} }
@Override
public void entity(final FaweCompoundTag tag) {
}
public void removeSectionLighting(int layer, boolean sky) { public void removeSectionLighting(int layer, boolean sky) {
} }
@ -147,25 +150,26 @@ public final class NullChunk implements IQueueChunk {
return BlockTypes.__RESERVED__.getDefaultState(); return BlockTypes.__RESERVED__.getDefaultState();
} }
@Override
public Map<BlockVector3, FaweCompoundTag> tiles() {
return Collections.emptyMap();
}
@Override
public @Nullable FaweCompoundTag tile(final int x, final int y, final int z) {
return null;
}
@Override
public Collection<FaweCompoundTag> entities() {
return Collections.emptyList();
}
@Nonnull @Nonnull
public BaseBlock getFullBlock(int x, int y, int z) { public BaseBlock getFullBlock(int x, int y, int z) {
return BlockTypes.__RESERVED__.getDefaultState().toBaseBlock(); return BlockTypes.__RESERVED__.getDefaultState().toBaseBlock();
} }
@Nonnull
public Map<BlockVector3, CompoundTag> getTiles() {
return Collections.emptyMap();
}
@Nullable
public CompoundTag getTile(int x, int y, int z) {
return null;
}
@Nonnull
public Set<CompoundTag> getEntities() {
return Collections.emptySet();
}
@Nullable @Nullable
public char[] load(int layer) { public char[] load(int layer) {
@ -178,11 +182,6 @@ public final class NullChunk implements IQueueChunk {
return null; return null;
} }
@Nullable
public CompoundTag getEntity(@Nonnull UUID uuid) {
return null;
}
@Override @Override
public int setCreateCopy(boolean createCopy) { public int setCreateCopy(boolean createCopy) {
return -1; return -1;
@ -230,6 +229,11 @@ public final class NullChunk implements IQueueChunk {
return null; return null;
} }
@Override
public @Nullable FaweCompoundTag entity(final UUID uuid) {
return null;
}
public boolean trim(boolean aggressive) { public boolean trim(boolean aggressive) {
return true; return true;
} }

View File

@ -34,6 +34,7 @@ import net.jpountz.lz4.LZ4Compressor;
import net.jpountz.lz4.LZ4Factory; import net.jpountz.lz4.LZ4Factory;
import net.jpountz.lz4.LZ4FastDecompressor; import net.jpountz.lz4.LZ4FastDecompressor;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.enginehub.linbus.tree.LinCompoundTag;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -424,8 +425,10 @@ public class MainUtil {
* @param y New Y coordinate * @param y New Y coordinate
* @param z New Z coordinate * @param z New Z coordinate
* @return New tag * @return New tag
* @deprecated use {@link NbtUtils#withPosition} instead
*/ */
@Nonnull @Nonnull
@Deprecated(forRemoval = true, since = "TODO")
public static CompoundTag setPosition(@Nonnull CompoundTag tag, int x, int y, int z) { public static CompoundTag setPosition(@Nonnull CompoundTag tag, int x, int y, int z) {
Map<String, Tag<?, ?>> value = new HashMap<>(tag.getValue()); Map<String, Tag<?, ?>> value = new HashMap<>(tag.getValue());
value.put("x", new IntTag(x)); value.put("x", new IntTag(x));
@ -440,8 +443,10 @@ public class MainUtil {
* @param tag Tag to copy * @param tag Tag to copy
* @param entity Entity * @param entity Entity
* @return New tag * @return New tag
* @deprecated use {@link NbtUtils#withEntityInfo(LinCompoundTag, Entity)} instead
*/ */
@Nonnull @Nonnull
@Deprecated(forRemoval = true, since = "TODO")
public static CompoundTag setEntityInfo(@Nonnull CompoundTag tag, @Nonnull Entity entity) { public static CompoundTag setEntityInfo(@Nonnull CompoundTag tag, @Nonnull Entity entity) {
Map<String, Tag<?, ?>> map = new HashMap<>(tag.getValue()); Map<String, Tag<?, ?>> map = new HashMap<>(tag.getValue());
map.put("Id", new StringTag(entity.getState().getType().id())); map.put("Id", new StringTag(entity.getState().getType().id()));

View File

@ -1,17 +1,29 @@
package com.fastasyncworldedit.core.util; package com.fastasyncworldedit.core.util;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.storage.InvalidFormatException; import com.sk89q.worldedit.world.storage.InvalidFormatException;
import org.enginehub.linbus.tree.LinByteTag; import org.enginehub.linbus.tree.LinByteTag;
import org.enginehub.linbus.tree.LinCompoundTag; import org.enginehub.linbus.tree.LinCompoundTag;
import org.enginehub.linbus.tree.LinDoubleTag;
import org.enginehub.linbus.tree.LinIntArrayTag;
import org.enginehub.linbus.tree.LinIntTag; import org.enginehub.linbus.tree.LinIntTag;
import org.enginehub.linbus.tree.LinListTag;
import org.enginehub.linbus.tree.LinLongTag;
import org.enginehub.linbus.tree.LinShortTag; import org.enginehub.linbus.tree.LinShortTag;
import org.enginehub.linbus.tree.LinTag; import org.enginehub.linbus.tree.LinTag;
import org.enginehub.linbus.tree.LinTagType; import org.enginehub.linbus.tree.LinTagType;
import javax.annotation.Nonnull;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
public class NbtUtils { public final class NbtUtils {
private NbtUtils() {
}
/** /**
* Get child tag of a NBT structure. * Get child tag of a NBT structure.
@ -79,4 +91,124 @@ public class NbtUtils {
return value; return value;
} }
/**
* Tries to extract UUID information from a compound tag
*
* @param compoundTag the compound tag to extract uuid information from
* @return the extracted UUID
* @since TODO
*/
public static UUID uuid(FaweCompoundTag compoundTag) {
final LinCompoundTag linTag = compoundTag.linTag();
{
final LinIntArrayTag uuidTag = linTag.findTag("UUID", LinTagType.intArrayTag());
if (uuidTag != null) {
int[] arr = uuidTag.value();
return new UUID((long) arr[0] << 32 | (arr[1] & 0xFFFFFFFFL), (long) arr[2] << 32 | (arr[3] & 0xFFFFFFFFL));
}
}
{
final LinLongTag uuidMostTag = linTag.findTag("UUIDMost", LinTagType.longTag());
if (uuidMostTag != null) {
return new UUID(uuidMostTag.valueAsLong(), linTag.getTag("UUIDLeast", LinTagType.longTag()).valueAsLong());
}
}
{
final LinLongTag uuidMostTag = linTag.findTag("WorldUUIDMost", LinTagType.longTag());
if (uuidMostTag != null) {
return new UUID(uuidMostTag.valueAsLong(), linTag.getTag("WorldUUIDLeast", LinTagType.longTag()).valueAsLong());
}
}
{
final LinLongTag uuidMostTag = linTag.findTag("PersistentIDMSB", LinTagType.longTag());
if (uuidMostTag != null) {
return new UUID(uuidMostTag.valueAsLong(), linTag.getTag("PersistentIDLSB", LinTagType.longTag()).valueAsLong());
}
}
throw new IllegalArgumentException("no uuid present");
}
/**
* Create a copy of the tag and modify the (x, y, z) coordinates
*
* @param tag Tag to copy
* @param x New X coordinate
* @param y New Y coordinate
* @param z New Z coordinate
* @return New tag
* @since TODO
*/
public static @Nonnull LinCompoundTag withPosition(@Nonnull LinCompoundTag tag, int x, int y, int z) {
return tag.toBuilder()
.putInt("x", x)
.putInt("y", y)
.putInt("z", z)
.build();
}
/**
* Create a copy of the tag and modify the (x, y, z) coordinates
*
* @param tag Tag to copy
* @param x New X coordinate
* @param y New Y coordinate
* @param z New Z coordinate
* @return New tag
* @since TODO
*/
public static @Nonnull FaweCompoundTag withPosition(@Nonnull FaweCompoundTag tag, int x, int y, int z) {
return FaweCompoundTag.of(withPosition(tag.linTag(), x, y, z));
}
/**
* {@return a copy of the given tag with the Id and the Pos of the given entity}
*
* @param tag the tag to copy
* @param entity the entity to use the Id and the Pos from
* @since TODO
*/
public static @Nonnull LinCompoundTag withEntityInfo(@Nonnull LinCompoundTag tag, @Nonnull Entity entity) {
final LinCompoundTag.Builder builder = tag.toBuilder()
.putString("Id", entity.getState().getType().id());
LinListTag<LinDoubleTag> pos = tag.findListTag("Pos", LinTagType.doubleTag());
if (pos != null) { // TODO why only if pos != null?
Location loc = entity.getLocation();
final LinListTag<LinDoubleTag> newPos = LinListTag.builder(LinTagType.doubleTag())
.add(LinDoubleTag.of(loc.x()))
.add(LinDoubleTag.of(loc.y()))
.add(LinDoubleTag.of(loc.z()))
.build();
builder.put("Pos", newPos);
}
return builder.build();
}
/**
* Adds a UUID to the given map
*
* @param map the map to insert to
* @param uuid the uuid to insert
* @since TODO
*/
public static void addUUIDToMap(Map<String, LinTag<?>> map, UUID uuid) {
int[] uuidArray = new int[4];
uuidArray[0] = (int) (uuid.getMostSignificantBits() >> 32);
uuidArray[1] = (int) uuid.getMostSignificantBits();
uuidArray[2] = (int) (uuid.getLeastSignificantBits() >> 32);
uuidArray[3] = (int) uuid.getLeastSignificantBits();
map.put("UUID", LinIntArrayTag.of(uuidArray));
map.put("UUIDMost", LinLongTag.of(uuid.getMostSignificantBits()));
map.put("UUIDLeast", LinLongTag.of(uuid.getLeastSignificantBits()));
map.put("WorldUUIDMost", LinLongTag.of(uuid.getMostSignificantBits()));
map.put("WorldUUIDLeast", LinLongTag.of(uuid.getLeastSignificantBits()));
map.put("PersistentIDMSB", LinLongTag.of(uuid.getMostSignificantBits()));
map.put("PersistentIDLSB", LinLongTag.of(uuid.getLeastSignificantBits()));
}
} }

View File

@ -1,5 +1,7 @@
package com.fastasyncworldedit.core.world.block; package com.fastasyncworldedit.core.world.block;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBlocks;
import com.fastasyncworldedit.core.queue.ITileInput; import com.fastasyncworldedit.core.queue.ITileInput;
import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.world.block.BlockState; import com.sk89q.worldedit.world.block.BlockState;
@ -11,9 +13,21 @@ public enum CompoundInput {
public BaseBlock get(BlockState state, ITileInput input, int x, int y, int z) { public BaseBlock get(BlockState state, ITileInput input, int x, int y, int z) {
return state.toBaseBlock(input.getTile(x, y, z)); return state.toBaseBlock(input.getTile(x, y, z));
} }
@Override
public BaseBlock get(final BlockState state, final IBlocks blocks, final int x, final int y, final int z) {
final FaweCompoundTag tile = blocks.tile(x, y, z);
assert tile != null : "container without tile entity";
return state.toBaseBlock(tile.linTag());
}
}; };
@Deprecated(forRemoval = true, since = "TODO")
public BaseBlock get(BlockState state, ITileInput input, int x, int y, int z) { public BaseBlock get(BlockState state, ITileInput input, int x, int y, int z) {
return state.toBaseBlock(); return state.toBaseBlock();
} }
public BaseBlock get(BlockState state, IBlocks blocks, int x, int y, int z) {
return state.toBaseBlock();
}
} }

View File

@ -1,5 +1,6 @@
package com.fastasyncworldedit.core.wrappers; package com.fastasyncworldedit.core.wrappers;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket; import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
import com.fastasyncworldedit.core.util.ExtentTraverser; import com.fastasyncworldedit.core.util.ExtentTraverser;
@ -187,8 +188,8 @@ public class WorldWrapper extends AbstractWorld {
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { public boolean tile(int x, int y, int z, FaweCompoundTag tile) throws WorldEditException {
return parent.setTile(x, y, z, tile); return parent.tile(x, y, z, tile);
} }
@Override @Override

View File

@ -172,7 +172,9 @@ public final class NBTUtils {
* @param map Map to add uuid to * @param map Map to add uuid to
* @param uuid {@link UUID} to add * @param uuid {@link UUID} to add
* @since 2.4.0 * @since 2.4.0
* @deprecated use {@link com.fastasyncworldedit.core.util.NbtUtils#addUUIDToMap(Map, UUID)} instead
*/ */
@Deprecated(forRemoval = true, since = "TODO")
public static void addUUIDToMap(Map<String, Tag<?, ?>> map, UUID uuid) { public static void addUUIDToMap(Map<String, Tag<?, ?>> map, UUID uuid) {
int[] uuidArray = new int[4]; int[] uuidArray = new int[4];
uuidArray[0] = (int) (uuid.getMostSignificantBits() >> 32); uuidArray[0] = (int) (uuid.getMostSignificantBits() >> 32);

View File

@ -25,6 +25,7 @@ import com.fastasyncworldedit.core.extent.HistoryExtent;
import com.fastasyncworldedit.core.extent.NullExtent; import com.fastasyncworldedit.core.extent.NullExtent;
import com.fastasyncworldedit.core.history.changeset.AbstractChangeSet; import com.fastasyncworldedit.core.history.changeset.AbstractChangeSet;
import com.fastasyncworldedit.core.internal.exception.FaweException; import com.fastasyncworldedit.core.internal.exception.FaweException;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.Filter; import com.fastasyncworldedit.core.queue.Filter;
import com.fastasyncworldedit.core.queue.IBatchProcessor; import com.fastasyncworldedit.core.queue.IBatchProcessor;
import com.fastasyncworldedit.core.util.ExtentTraverser; import com.fastasyncworldedit.core.util.ExtentTraverser;
@ -425,8 +426,8 @@ public class AbstractDelegateExtent implements Extent {
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { public boolean tile(int x, int y, int z, FaweCompoundTag tile) throws WorldEditException {
return setBlock(x, y, z, getBlock(x, y, z).toBaseBlock(tile)); return setBlock(x, y, z, getBlock(x, y, z).toBaseBlock(tile.linTag()));
} }
//FAWE end //FAWE end

View File

@ -736,7 +736,6 @@ public interface Extent extends InputExtent, OutputExtent {
default <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException { default <B extends BlockStateHolder<B>> int setBlocks(Region region, B block) throws MaxChangedBlocksException {
checkNotNull(region); checkNotNull(region);
checkNotNull(block); checkNotNull(block);
boolean hasNbt = block instanceof BaseBlock && block.hasNbtData();
int changes = 0; int changes = 0;
for (BlockVector3 pos : region) { for (BlockVector3 pos : region) {

View File

@ -19,8 +19,8 @@
package com.sk89q.worldedit.extent; package com.sk89q.worldedit.extent;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IBatchProcessor; import com.fastasyncworldedit.core.queue.IBatchProcessor;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity; import com.sk89q.worldedit.entity.Entity;
@ -108,7 +108,7 @@ public class NullExtent implements Extent {
} }
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { public boolean tile(int x, int y, int z, FaweCompoundTag tile) throws WorldEditException {
return false; return false;
} }

View File

@ -21,6 +21,7 @@ package com.sk89q.worldedit.extent;
import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType; import com.fastasyncworldedit.core.extent.processor.heightmap.HeightMapType;
import com.fastasyncworldedit.core.math.MutableBlockVector3; import com.fastasyncworldedit.core.math.MutableBlockVector3;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEdit; import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
@ -68,7 +69,24 @@ public interface OutputExtent {
return setBlock(MutableBlockVector3.get(x, y, z), block); return setBlock(MutableBlockVector3.get(x, y, z), block);
} }
boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException; /**
* @deprecated use {@link #tile(int, int, int, FaweCompoundTag)} instead
*/
@Deprecated(forRemoval = true, since = "TODO")
default boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException {
return tile(x, y, z, FaweCompoundTag.of(tile.toLinTag()));
}
/**
* Sets a tile/block entity at the given location.
* @param x the x position
* @param y the y position
* @param z the z position
* @param tile the tile/block entity to set
* @return {@code true} if the tile/block entity was placed
* @since TODO
*/
boolean tile(int x, int y, int z, FaweCompoundTag tile) throws WorldEditException;
/** /**
* Check if this extent fully supports 3D biomes. * Check if this extent fully supports 3D biomes.

View File

@ -23,6 +23,7 @@ import com.fastasyncworldedit.core.extent.clipboard.SimpleClipboard;
import com.fastasyncworldedit.core.function.visitor.Order; import com.fastasyncworldedit.core.function.visitor.Order;
import com.fastasyncworldedit.core.math.MutableBlockVector2; import com.fastasyncworldedit.core.math.MutableBlockVector2;
import com.fastasyncworldedit.core.math.OffsetBlockVector3; import com.fastasyncworldedit.core.math.OffsetBlockVector3;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.google.common.collect.Iterators; import com.google.common.collect.Iterators;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
@ -200,16 +201,17 @@ public class BlockArrayClipboard implements Clipboard {
//FAWE start //FAWE start
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tag) { public boolean tile(int x, int y, int z, FaweCompoundTag tag) {
x -= offset.x(); x -= offset.x();
y -= offset.y(); y -= offset.y();
z -= offset.z(); z -= offset.z();
return getParent().setTile(x, y, z, tag); return getParent().tile(x, y, z, tag);
} }
@Deprecated(forRemoval = true, since = "TODO")
public boolean setTile(BlockVector3 position, CompoundTag tag) { public boolean setTile(BlockVector3 position, CompoundTag tag) {
return setTile(position.x(), position.y(), position.z(), tag); return tile(position.x(), position.y(), position.z(), FaweCompoundTag.of(tag.toLinTag()));
} }
@Override @Override

View File

@ -852,6 +852,7 @@ public abstract class BlockVector3 {
return orDefault.getBiome(this); return orDefault.getBiome(this);
} }
@Deprecated(forRemoval = true, since = "TODO")
public CompoundTag getNbtData(Extent orDefault) { public CompoundTag getNbtData(Extent orDefault) {
return orDefault.getFullBlock(x(), y(), z()).getNbtData(); return orDefault.getFullBlock(x(), y(), z()).getNbtData();
} }

View File

@ -19,7 +19,7 @@
package com.sk89q.worldedit.session.request; package com.sk89q.worldedit.session.request;
import com.sk89q.jnbt.CompoundTag; import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity; import com.sk89q.worldedit.entity.BaseEntity;
@ -119,8 +119,8 @@ public class RequestExtent implements Extent {
//FAWE start //FAWE start
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { public boolean tile(int x, int y, int z, FaweCompoundTag tile) throws WorldEditException {
return getExtent().setTile(x, y, z, tile); return getExtent().tile(x, y, z, tile);
} }
@Override @Override

View File

@ -19,11 +19,11 @@
package com.sk89q.worldedit.world; package com.sk89q.worldedit.world;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.queue.IChunkGet; import com.fastasyncworldedit.core.queue.IChunkGet;
import com.fastasyncworldedit.core.queue.implementation.blocks.NullChunkGet; import com.fastasyncworldedit.core.queue.implementation.blocks.NullChunkGet;
import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket; import com.fastasyncworldedit.core.queue.implementation.packet.ChunkPacket;
import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.EditSession; import com.sk89q.worldedit.EditSession;
import com.sk89q.worldedit.MaxChangedBlocksException; import com.sk89q.worldedit.MaxChangedBlocksException;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
@ -204,7 +204,7 @@ public class NullWorld extends AbstractWorld {
//FAWE start //FAWE start
@Override @Override
public boolean setTile(int x, int y, int z, CompoundTag tile) throws WorldEditException { public boolean tile(int x, int y, int z, FaweCompoundTag tile) throws WorldEditException {
return false; return false;
} }
//FAWE end //FAWE end

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.block; package com.sk89q.worldedit.world.block;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.fastasyncworldedit.core.registry.state.PropertyKey; import com.fastasyncworldedit.core.registry.state.PropertyKey;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException; import com.sk89q.worldedit.WorldEditException;
@ -262,15 +263,15 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
@Override @Override
public void applyTileEntity(OutputExtent output, int x, int y, int z) { public void applyTileEntity(OutputExtent output, int x, int y, int z) {
CompoundTag nbt = getNbtData(); LinCompoundTag nbt = getNbt();
if (nbt != null) { if (nbt != null) {
output.setTile(x, y, z, nbt); output.tile(x, y, z, FaweCompoundTag.of(nbt));
} }
} }
@Override @Override
public BaseBlock withPropertyId(int propertyId) { public BaseBlock withPropertyId(int propertyId) {
return getBlockType().withPropertyId(propertyId).toBaseBlock(getNbtData()); return getBlockType().withPropertyId(propertyId).toBaseBlock(getNbtReference());
} }
@Override @Override
@ -285,7 +286,7 @@ public class BaseBlock implements BlockStateHolder<BaseBlock>, TileEntityBlock {
@Override @Override
public <V> BaseBlock with(PropertyKey property, V value) { public <V> BaseBlock with(PropertyKey property, V value) {
return toImmutableState().with(property, value).toBaseBlock(getNbtData()); return toImmutableState().with(property, value).toBaseBlock(getNbtReference());
} }
@Override @Override

View File

@ -22,6 +22,7 @@ package com.sk89q.worldedit.world.block;
import com.fastasyncworldedit.core.command.SuggestInputParseException; import com.fastasyncworldedit.core.command.SuggestInputParseException;
import com.fastasyncworldedit.core.configuration.Caption; import com.fastasyncworldedit.core.configuration.Caption;
import com.fastasyncworldedit.core.function.mask.SingleBlockStateMask; import com.fastasyncworldedit.core.function.mask.SingleBlockStateMask;
import com.fastasyncworldedit.core.queue.IBlocks;
import com.fastasyncworldedit.core.queue.ITileInput; import com.fastasyncworldedit.core.queue.ITileInput;
import com.fastasyncworldedit.core.registry.state.PropertyKey; import com.fastasyncworldedit.core.registry.state.PropertyKey;
import com.fastasyncworldedit.core.util.MutableCharSequence; import com.fastasyncworldedit.core.util.MutableCharSequence;
@ -476,6 +477,12 @@ public class BlockState implements BlockStateHolder<BlockState>, Pattern {
public BaseBlock toBaseBlock(ITileInput input, int x, int y, int z) { public BaseBlock toBaseBlock(ITileInput input, int x, int y, int z) {
return compoundInput.get(this, input, x, y, z); return compoundInput.get(this, input, x, y, z);
} }
@Override
public BaseBlock toBaseBlock(final IBlocks blocks, final int x, final int y, final int z) {
return compoundInput.get(this, blocks, x, y, z);
}
//FAWE end //FAWE end
@Override @Override

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.block; package com.sk89q.worldedit.world.block;
import com.fastasyncworldedit.core.queue.IBlocks;
import com.fastasyncworldedit.core.queue.ITileInput; import com.fastasyncworldedit.core.queue.ITileInput;
import com.fastasyncworldedit.core.registry.state.PropertyKey; import com.fastasyncworldedit.core.registry.state.PropertyKey;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
@ -201,6 +202,10 @@ public interface BlockStateHolder<B extends BlockStateHolder<B>> extends TileEnt
default BaseBlock toBaseBlock(ITileInput input, int x, int y, int z) { default BaseBlock toBaseBlock(ITileInput input, int x, int y, int z) {
throw new UnsupportedOperationException("State is immutable"); throw new UnsupportedOperationException("State is immutable");
} }
default BaseBlock toBaseBlock(IBlocks blocks, int x, int y, int z) {
throw new UnsupportedOperationException("State is immutable");
}
//FAWE end //FAWE end
default String getAsString() { default String getAsString() {

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.registry; package com.sk89q.worldedit.world.registry;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -185,7 +186,19 @@ public interface BlockMaterial {
* @return default tile entity data * @return default tile entity data
*/ */
@Nullable @Nullable
CompoundTag getDefaultTile(); default CompoundTag getDefaultTile() {
final FaweCompoundTag faweCompoundTag = defaultTile();
if (faweCompoundTag == null) {
return null;
}
return new CompoundTag(faweCompoundTag.linTag());
}
/**
* {@return the default tile associated with this material, if any}
* @since TODO
*/
@Nullable FaweCompoundTag defaultTile();
/** /**
* Get the map color. * Get the map color.

View File

@ -19,6 +19,7 @@
package com.sk89q.worldedit.world.registry; package com.sk89q.worldedit.world.registry;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import javax.annotation.Nullable; import javax.annotation.Nullable;
@ -168,5 +169,11 @@ public class PassthroughBlockMaterial implements BlockMaterial {
public CompoundTag getDefaultTile() { public CompoundTag getDefaultTile() {
return blockMaterial.getDefaultTile(); return blockMaterial.getDefaultTile();
} }
@Override
public @Nullable FaweCompoundTag defaultTile() {
return blockMaterial.defaultTile();
}
//FAWE end //FAWE end
} }

View File

@ -19,8 +19,11 @@
package com.sk89q.worldedit.world.registry; package com.sk89q.worldedit.world.registry;
import com.fastasyncworldedit.core.nbt.FaweCompoundTag;
import com.sk89q.jnbt.CompoundTag; import com.sk89q.jnbt.CompoundTag;
import javax.annotation.Nullable;
class SimpleBlockMaterial implements BlockMaterial { class SimpleBlockMaterial implements BlockMaterial {
private boolean isAir; private boolean isAir;
@ -251,8 +254,12 @@ class SimpleBlockMaterial implements BlockMaterial {
} }
@Override @Override
public CompoundTag getDefaultTile() { public @Nullable FaweCompoundTag defaultTile() {
return tile; // this implementation is very lazy, but SimpleBlockMaterial isn't really used anyway
if (tile != null) {
return FaweCompoundTag.of(tile.toLinTag());
}
return null;
} }
//FAWE end //FAWE end