3
0
Mirror von https://github.com/IntellectualSites/FastAsyncWorldEdit.git synchronisiert 2024-07-03 09:18:03 +02:00

fix: correctly create Minecraft Structure format schematics (#2787)

- fixes #2784
 - fixes #2785
Dieser Commit ist enthalten in:
Jordan 2024-06-15 15:52:11 +02:00 committet von GitHub
Ursprung af83b2f9c9
Commit 3761b5184c
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -19,7 +19,6 @@ 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.registry.state.AbstractProperty;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.block.BaseBlock;
@ -174,27 +173,23 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
ArrayList<HashMap<String, Object>> palette = new ArrayList<>();
for (BlockVector3 point : region) {
BlockState block = clipboard.getBlock(point);
int combined = block.getInternalId();
char ordinal = block.getOrdinalChar();
BlockType type = block.getBlockType();
if (type == BlockTypes.STRUCTURE_VOID || indexes.containsKey(combined)) {
if (type == BlockTypes.STRUCTURE_VOID || indexes.containsKey(ordinal)) {
continue;
}
indexes.put(combined, (Integer) palette.size());
indexes.put(ordinal, palette.size());
HashMap<String, Object> paletteEntry = new HashMap<>();
paletteEntry.put("Name", type.id());
if (block.getInternalId() != type.getInternalId()) {
Map<String, Object> properties = null;
for (AbstractProperty property : (List<AbstractProperty<?>>) type.getProperties()) {
int propIndex = property.getIndex(block.getInternalId());
if (propIndex != 0) {
if (properties == null) {
properties = new HashMap<>();
}
Object value = property.getValues().get(propIndex);
properties.put(property.getName(), value.toString());
for (Map.Entry<Property<?>, Object> entry : block.getStates().entrySet()) {
if (properties == null) {
properties = new HashMap<>();
}
properties.put(entry.getKey().getName(), entry.getValue().toString());
}
if (properties != null) {
paletteEntry.put("Properties", properties);
@ -211,16 +206,23 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
for (BlockVector3 point : region) {
BaseBlock block = clipboard.getFullBlock(point);
if (block.getBlockType() != BlockTypes.STRUCTURE_VOID) {
int combined = block.getInternalId();
int index = indexes.get(combined);
List<Integer> pos = Arrays.asList(point.x() - min.x(),
point.y() - min.y(), point.z() - min.z()
char ordinal = block.getOrdinalChar();
int index = indexes.get(ordinal);
List<Integer> pos = Arrays.asList(
point.x() - min.x(),
point.y() - min.y(),
point.z() - min.z()
);
if (!block.hasNbtData()) {
blocks.add(FaweCache.INSTANCE.asMap("state", index, "pos", pos));
} else {
Map<String, Tag> tag = new HashMap<>(block.getNbtData().getValue());
tag.remove("x");
tag.remove("y");
tag.remove("z");
CompoundTag cTag = new CompoundTag(tag);
blocks.add(
FaweCache.INSTANCE.asMap("state", index, "pos", pos, "nbt", block.getNbtData()));
FaweCache.INSTANCE.asMap("state", index, "pos", pos, "nbt", cTag));
}
}
}
@ -231,8 +233,16 @@ public class MinecraftStructure implements ClipboardReader, ClipboardWriter {
ArrayList<Map<String, Object>> entities = new ArrayList<>();
for (Entity entity : clipboard.getEntities()) {
Location loc = entity.getLocation();
List<Double> pos = Arrays.asList(loc.x(), loc.y(), loc.z());
List<Integer> blockPos = Arrays.asList(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
List<Double> pos = Arrays.asList(
loc.x() - min.x(),
loc.y() - min.y(),
loc.z() - min.z()
);
List<Integer> blockPos = Arrays.asList(
loc.getBlockX() - min.x(),
loc.getBlockY() - min.y(),
loc.getBlockZ() - min.z()
);
BaseEntity state = entity.getState();
if (state != null) {
CompoundTag nbt = state.getNbtData();