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