3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-11-19 09:20:08 +01:00

Update for final changes

(cherry picked from commit 2f6b50a4276b33b615d9dbc52e73e958308735f9)
Dieser Commit ist enthalten in:
Octavia Togami 2021-05-29 10:35:31 -07:00 committet von Pierre Maurice Schwang
Ursprung f3216326e6
Commit 5ba7b1fe39
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 37E613079F3E5BB9
5 geänderte Dateien mit 60 neuen und 38 gelöschten Zeilen

Datei anzeigen

@ -19,9 +19,9 @@
package com.sk89q.worldedit.extent.clipboard.io.sponge;
import com.google.common.collect.Maps;
import com.sk89q.jnbt.AdventureNBTConverter;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.CompoundTagBuilder;
import com.sk89q.jnbt.IntArrayTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.ListTag;
@ -49,12 +49,14 @@ import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import static com.google.common.base.Preconditions.checkState;
import static com.sk89q.worldedit.extent.clipboard.io.SchematicNbtUtil.getTag;
import static com.sk89q.worldedit.extent.clipboard.io.SchematicNbtUtil.requireTag;
/**
@ -135,7 +137,7 @@ class ReaderUtil {
static void initializeClipboardFromBlocks(
Clipboard clipboard, Map<Integer, BlockState> palette, byte[] blocks, ListTag tileEntities,
VersionedDataFixer fixer
VersionedDataFixer fixer, boolean dataIsNested
) throws IOException {
Map<BlockVector3, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
if (tileEntities != null) {
@ -147,13 +149,23 @@ class ReaderUtil {
for (Map<String, Tag> tileEntity : tileEntityTags) {
int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue();
final BlockVector3 pt = clipboard.getMinimumPoint().add(pos[0], pos[1], pos[2]);
Map<String, Tag> values = Maps.newHashMap(tileEntity);
Map<String, Tag> values;
if (dataIsNested) {
CompoundTag dataTag = getTag(tileEntity, "Data", CompoundTag.class);
if (dataTag != null) {
values = new LinkedHashMap<>(dataTag.getValue());
} else {
values = new LinkedHashMap<>();
}
} else {
values = new LinkedHashMap<>(tileEntity);
values.remove("Id");
values.remove("Pos");
}
values.put("x", new IntTag(pt.getBlockX()));
values.put("y", new IntTag(pt.getBlockY()));
values.put("z", new IntTag(pt.getBlockZ()));
values.put("id", values.get("Id"));
values.remove("Id");
values.remove("Pos");
values.put("id", tileEntity.get("Id"));
if (fixer.isActive()) {
tileEntity = ((CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
DataFixer.FixTypes.BLOCK_ENTITY,
@ -222,18 +234,32 @@ class ReaderUtil {
CompoundTag entityTag = (CompoundTag) et;
Map<String, Tag> tags = entityTag.getValue();
String id = requireTag(tags, "Id", StringTag.class).getValue();
entityTag = entityTag.createBuilder().putString("id", id).remove("Id").build();
entityTag = ((CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
CompoundTagBuilder dataTagBuilder = CompoundTagBuilder.create();
if (positionIsRelative) {
// then we're in version 3
CompoundTag subTag = getTag(entityTag.getValue(), "Data", CompoundTag.class);
if (subTag != null) {
dataTagBuilder.putAll(subTag.getValue());
}
} else {
// version 2
dataTagBuilder.putAll(tags);
dataTagBuilder.remove("Id");
dataTagBuilder.remove("Pos");
}
CompoundTag dataTag = dataTagBuilder.putString("id", id).build();
dataTag = ((CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
DataFixer.FixTypes.ENTITY,
entityTag.asBinaryTag()
dataTag.asBinaryTag()
)));
EntityType entityType = EntityTypes.get(id);
if (entityType != null) {
Location location = NBTConversions.toLocation(clipboard,
requireTag(tags, "Pos", ListTag.class),
requireTag(tags, "Rotation", ListTag.class));
BaseEntity state = new BaseEntity(entityType, entityTag);
requireTag(dataTag.getValue(), "Rotation", ListTag.class)
);
BaseEntity state = new BaseEntity(entityType, dataTag);
if (positionIsRelative) {
location = location.setPosition(
location.toVector().add(clipboard.getMinimumPoint().toVector3())

Datei anzeigen

@ -35,12 +35,10 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.extent.clipboard.io.NBTSchematicReader;
import com.sk89q.worldedit.internal.Constants;
import com.sk89q.worldedit.internal.util.LogManagerCompat;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import com.sk89q.worldedit.world.block.BlockState;
import org.apache.logging.log4j.Logger;
import java.io.IOException;
import java.util.Map;
@ -143,7 +141,7 @@ public class SpongeSchematicV1Reader extends NBTSchematicReader {
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
clipboard.setOrigin(origin);
ReaderUtil.initializeClipboardFromBlocks(
clipboard, palette, blocks, tileEntities, fixer
clipboard, palette, blocks, tileEntities, fixer, false
);
return clipboard;
}

Datei anzeigen

@ -167,7 +167,7 @@ public class SpongeSchematicV3Reader extends NBTSchematicReader {
ListTag tileEntities = getTag(blockContainer, "BlockEntities", ListTag.class);
ReaderUtil.initializeClipboardFromBlocks(
clipboard, palette, blocks, tileEntities, fixer
clipboard, palette, blocks, tileEntities, fixer, true
);
}

Datei anzeigen

@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.CompoundTagBuilder;
import com.sk89q.jnbt.IntArrayTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.ListTag;
@ -186,24 +187,18 @@ public class SpongeSchematicV3Writer implements ClipboardWriter {
BaseBlock block = clipboard.getFullBlock(point);
// Also compute block entity side-effect here
if (block.getNbtData() != null) {
Map<String, Tag> values = new HashMap<>(block.getNbtData().getValue());
CompoundTagBuilder builder = CompoundTagBuilder.create();
values.remove("id"); // Remove 'id' if it exists. We want 'Id'
// Positions are kept in NBT, we don't want that.
values.remove("x");
values.remove("y");
values.remove("z");
values.put("Id", new StringTag(block.getNbtId()));
builder.putString("Id", block.getNbtId());
BlockVector3 adjustedPos = point.subtract(clipboard.getMinimumPoint());
values.put("Pos", new IntArrayTag(new int[] {
builder.putIntArray("Pos", new int[] {
adjustedPos.getBlockX(),
adjustedPos.getBlockY(),
adjustedPos.getBlockZ()
}));
});
builder.put("Data", block.getNbtData());
blockEntities.add(new CompoundTag(values));
blockEntities.add(builder.build());
}
return block.toImmutableState().getAsString();
});

Datei anzeigen

@ -20,12 +20,11 @@
package com.sk89q.worldedit.extent.clipboard.io.sponge;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.CompoundTagBuilder;
import com.sk89q.jnbt.DoubleTag;
import com.sk89q.jnbt.FloatTag;
import com.sk89q.jnbt.ListTag;
import com.sk89q.jnbt.StringTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
@ -33,7 +32,6 @@ import com.sk89q.worldedit.math.Vector3;
import com.sk89q.worldedit.util.Location;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@ -44,22 +42,27 @@ class WriterUtil {
if (state == null) {
return null;
}
Map<String, Tag> values = Maps.newHashMap();
CompoundTagBuilder fullTagBuilder = CompoundTagBuilder.create();
CompoundTagBuilder dataTagBuilder = CompoundTagBuilder.create();
CompoundTag rawData = state.getNbtData();
if (rawData != null) {
values.putAll(rawData.getValue());
dataTagBuilder.putAll(rawData.getValue());
dataTagBuilder.remove("id");
}
values.remove("id");
values.put("Id", new StringTag(state.getType().getId()));
final Location location = e.getLocation();
Vector3 pos = location.toVector();
dataTagBuilder.put("Rotation", encodeRotation(location));
if (positionIsRelative) {
pos = pos.subtract(clipboard.getMinimumPoint().toVector3());
}
values.put("Pos", encodeVector(pos));
values.put("Rotation", encodeRotation(location));
return new CompoundTag(values);
fullTagBuilder.put("Data", dataTagBuilder.build());
} else {
fullTagBuilder.putAll(dataTagBuilder.build().getValue());
}
fullTagBuilder.putString("Id", state.getType().getId());
fullTagBuilder.put("Pos", encodeVector(pos));
return fullTagBuilder.build();
}).filter(Objects::nonNull).collect(Collectors.toList());
if (entities.isEmpty()) {
return null;