Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-19 17:30:08 +01:00
Update for final changes
(cherry picked from commit 2f6b50a4276b33b615d9dbc52e73e958308735f9)
Dieser Commit ist enthalten in:
Ursprung
f3216326e6
Commit
5ba7b1fe39
@ -19,9 +19,9 @@
|
|||||||
|
|
||||||
package com.sk89q.worldedit.extent.clipboard.io.sponge;
|
package com.sk89q.worldedit.extent.clipboard.io.sponge;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.sk89q.jnbt.AdventureNBTConverter;
|
import com.sk89q.jnbt.AdventureNBTConverter;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
|
import com.sk89q.jnbt.CompoundTagBuilder;
|
||||||
import com.sk89q.jnbt.IntArrayTag;
|
import com.sk89q.jnbt.IntArrayTag;
|
||||||
import com.sk89q.jnbt.IntTag;
|
import com.sk89q.jnbt.IntTag;
|
||||||
import com.sk89q.jnbt.ListTag;
|
import com.sk89q.jnbt.ListTag;
|
||||||
@ -49,12 +49,14 @@ import org.apache.logging.log4j.Logger;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkState;
|
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;
|
import static com.sk89q.worldedit.extent.clipboard.io.SchematicNbtUtil.requireTag;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -135,7 +137,7 @@ class ReaderUtil {
|
|||||||
|
|
||||||
static void initializeClipboardFromBlocks(
|
static void initializeClipboardFromBlocks(
|
||||||
Clipboard clipboard, Map<Integer, BlockState> palette, byte[] blocks, ListTag tileEntities,
|
Clipboard clipboard, Map<Integer, BlockState> palette, byte[] blocks, ListTag tileEntities,
|
||||||
VersionedDataFixer fixer
|
VersionedDataFixer fixer, boolean dataIsNested
|
||||||
) throws IOException {
|
) throws IOException {
|
||||||
Map<BlockVector3, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
|
Map<BlockVector3, Map<String, Tag>> tileEntitiesMap = new HashMap<>();
|
||||||
if (tileEntities != null) {
|
if (tileEntities != null) {
|
||||||
@ -147,13 +149,23 @@ class ReaderUtil {
|
|||||||
for (Map<String, Tag> tileEntity : tileEntityTags) {
|
for (Map<String, Tag> tileEntity : tileEntityTags) {
|
||||||
int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue();
|
int[] pos = requireTag(tileEntity, "Pos", IntArrayTag.class).getValue();
|
||||||
final BlockVector3 pt = clipboard.getMinimumPoint().add(pos[0], pos[1], pos[2]);
|
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("x", new IntTag(pt.getBlockX()));
|
||||||
values.put("y", new IntTag(pt.getBlockY()));
|
values.put("y", new IntTag(pt.getBlockY()));
|
||||||
values.put("z", new IntTag(pt.getBlockZ()));
|
values.put("z", new IntTag(pt.getBlockZ()));
|
||||||
values.put("id", values.get("Id"));
|
values.put("id", tileEntity.get("Id"));
|
||||||
values.remove("Id");
|
|
||||||
values.remove("Pos");
|
|
||||||
if (fixer.isActive()) {
|
if (fixer.isActive()) {
|
||||||
tileEntity = ((CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
|
tileEntity = ((CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
|
||||||
DataFixer.FixTypes.BLOCK_ENTITY,
|
DataFixer.FixTypes.BLOCK_ENTITY,
|
||||||
@ -222,18 +234,32 @@ class ReaderUtil {
|
|||||||
CompoundTag entityTag = (CompoundTag) et;
|
CompoundTag entityTag = (CompoundTag) et;
|
||||||
Map<String, Tag> tags = entityTag.getValue();
|
Map<String, Tag> tags = entityTag.getValue();
|
||||||
String id = requireTag(tags, "Id", StringTag.class).getValue();
|
String id = requireTag(tags, "Id", StringTag.class).getValue();
|
||||||
entityTag = entityTag.createBuilder().putString("id", id).remove("Id").build();
|
CompoundTagBuilder dataTagBuilder = CompoundTagBuilder.create();
|
||||||
entityTag = ((CompoundTag) AdventureNBTConverter.fromAdventure(fixer.fixUp(
|
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,
|
DataFixer.FixTypes.ENTITY,
|
||||||
entityTag.asBinaryTag()
|
dataTag.asBinaryTag()
|
||||||
)));
|
)));
|
||||||
|
|
||||||
EntityType entityType = EntityTypes.get(id);
|
EntityType entityType = EntityTypes.get(id);
|
||||||
if (entityType != null) {
|
if (entityType != null) {
|
||||||
Location location = NBTConversions.toLocation(clipboard,
|
Location location = NBTConversions.toLocation(clipboard,
|
||||||
requireTag(tags, "Pos", ListTag.class),
|
requireTag(tags, "Pos", ListTag.class),
|
||||||
requireTag(tags, "Rotation", ListTag.class));
|
requireTag(dataTag.getValue(), "Rotation", ListTag.class)
|
||||||
BaseEntity state = new BaseEntity(entityType, entityTag);
|
);
|
||||||
|
BaseEntity state = new BaseEntity(entityType, dataTag);
|
||||||
if (positionIsRelative) {
|
if (positionIsRelative) {
|
||||||
location = location.setPosition(
|
location = location.setPosition(
|
||||||
location.toVector().add(clipboard.getMinimumPoint().toVector3())
|
location.toVector().add(clipboard.getMinimumPoint().toVector3())
|
||||||
|
@ -35,12 +35,10 @@ import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
|
|||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
import com.sk89q.worldedit.extent.clipboard.io.NBTSchematicReader;
|
import com.sk89q.worldedit.extent.clipboard.io.NBTSchematicReader;
|
||||||
import com.sk89q.worldedit.internal.Constants;
|
import com.sk89q.worldedit.internal.Constants;
|
||||||
import com.sk89q.worldedit.internal.util.LogManagerCompat;
|
|
||||||
import com.sk89q.worldedit.math.BlockVector3;
|
import com.sk89q.worldedit.math.BlockVector3;
|
||||||
import com.sk89q.worldedit.regions.CuboidRegion;
|
import com.sk89q.worldedit.regions.CuboidRegion;
|
||||||
import com.sk89q.worldedit.regions.Region;
|
import com.sk89q.worldedit.regions.Region;
|
||||||
import com.sk89q.worldedit.world.block.BlockState;
|
import com.sk89q.worldedit.world.block.BlockState;
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -143,7 +141,7 @@ public class SpongeSchematicV1Reader extends NBTSchematicReader {
|
|||||||
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
|
BlockArrayClipboard clipboard = new BlockArrayClipboard(region);
|
||||||
clipboard.setOrigin(origin);
|
clipboard.setOrigin(origin);
|
||||||
ReaderUtil.initializeClipboardFromBlocks(
|
ReaderUtil.initializeClipboardFromBlocks(
|
||||||
clipboard, palette, blocks, tileEntities, fixer
|
clipboard, palette, blocks, tileEntities, fixer, false
|
||||||
);
|
);
|
||||||
return clipboard;
|
return clipboard;
|
||||||
}
|
}
|
||||||
|
@ -167,7 +167,7 @@ public class SpongeSchematicV3Reader extends NBTSchematicReader {
|
|||||||
ListTag tileEntities = getTag(blockContainer, "BlockEntities", ListTag.class);
|
ListTag tileEntities = getTag(blockContainer, "BlockEntities", ListTag.class);
|
||||||
|
|
||||||
ReaderUtil.initializeClipboardFromBlocks(
|
ReaderUtil.initializeClipboardFromBlocks(
|
||||||
clipboard, palette, blocks, tileEntities, fixer
|
clipboard, palette, blocks, tileEntities, fixer, true
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import com.google.common.collect.ImmutableMap;
|
|||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
import com.sk89q.jnbt.ByteArrayTag;
|
import com.sk89q.jnbt.ByteArrayTag;
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
|
import com.sk89q.jnbt.CompoundTagBuilder;
|
||||||
import com.sk89q.jnbt.IntArrayTag;
|
import com.sk89q.jnbt.IntArrayTag;
|
||||||
import com.sk89q.jnbt.IntTag;
|
import com.sk89q.jnbt.IntTag;
|
||||||
import com.sk89q.jnbt.ListTag;
|
import com.sk89q.jnbt.ListTag;
|
||||||
@ -186,24 +187,18 @@ public class SpongeSchematicV3Writer implements ClipboardWriter {
|
|||||||
BaseBlock block = clipboard.getFullBlock(point);
|
BaseBlock block = clipboard.getFullBlock(point);
|
||||||
// Also compute block entity side-effect here
|
// Also compute block entity side-effect here
|
||||||
if (block.getNbtData() != null) {
|
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'
|
builder.putString("Id", block.getNbtId());
|
||||||
|
|
||||||
// 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()));
|
|
||||||
BlockVector3 adjustedPos = point.subtract(clipboard.getMinimumPoint());
|
BlockVector3 adjustedPos = point.subtract(clipboard.getMinimumPoint());
|
||||||
values.put("Pos", new IntArrayTag(new int[] {
|
builder.putIntArray("Pos", new int[] {
|
||||||
adjustedPos.getBlockX(),
|
adjustedPos.getBlockX(),
|
||||||
adjustedPos.getBlockY(),
|
adjustedPos.getBlockY(),
|
||||||
adjustedPos.getBlockZ()
|
adjustedPos.getBlockZ()
|
||||||
}));
|
});
|
||||||
|
builder.put("Data", block.getNbtData());
|
||||||
|
|
||||||
blockEntities.add(new CompoundTag(values));
|
blockEntities.add(builder.build());
|
||||||
}
|
}
|
||||||
return block.toImmutableState().getAsString();
|
return block.toImmutableState().getAsString();
|
||||||
});
|
});
|
||||||
|
@ -20,12 +20,11 @@
|
|||||||
package com.sk89q.worldedit.extent.clipboard.io.sponge;
|
package com.sk89q.worldedit.extent.clipboard.io.sponge;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import com.sk89q.jnbt.CompoundTag;
|
import com.sk89q.jnbt.CompoundTag;
|
||||||
|
import com.sk89q.jnbt.CompoundTagBuilder;
|
||||||
import com.sk89q.jnbt.DoubleTag;
|
import com.sk89q.jnbt.DoubleTag;
|
||||||
import com.sk89q.jnbt.FloatTag;
|
import com.sk89q.jnbt.FloatTag;
|
||||||
import com.sk89q.jnbt.ListTag;
|
import com.sk89q.jnbt.ListTag;
|
||||||
import com.sk89q.jnbt.StringTag;
|
|
||||||
import com.sk89q.jnbt.Tag;
|
import com.sk89q.jnbt.Tag;
|
||||||
import com.sk89q.worldedit.entity.BaseEntity;
|
import com.sk89q.worldedit.entity.BaseEntity;
|
||||||
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||||
@ -33,7 +32,6 @@ import com.sk89q.worldedit.math.Vector3;
|
|||||||
import com.sk89q.worldedit.util.Location;
|
import com.sk89q.worldedit.util.Location;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -44,22 +42,27 @@ class WriterUtil {
|
|||||||
if (state == null) {
|
if (state == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Map<String, Tag> values = Maps.newHashMap();
|
CompoundTagBuilder fullTagBuilder = CompoundTagBuilder.create();
|
||||||
|
CompoundTagBuilder dataTagBuilder = CompoundTagBuilder.create();
|
||||||
CompoundTag rawData = state.getNbtData();
|
CompoundTag rawData = state.getNbtData();
|
||||||
if (rawData != null) {
|
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();
|
final Location location = e.getLocation();
|
||||||
Vector3 pos = location.toVector();
|
Vector3 pos = location.toVector();
|
||||||
|
dataTagBuilder.put("Rotation", encodeRotation(location));
|
||||||
if (positionIsRelative) {
|
if (positionIsRelative) {
|
||||||
pos = pos.subtract(clipboard.getMinimumPoint().toVector3());
|
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());
|
}).filter(Objects::nonNull).collect(Collectors.toList());
|
||||||
if (entities.isEmpty()) {
|
if (entities.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren