mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 09:17:39 +00:00
fix: apply origin to sponge v3 schematics (#2909)
* fix(#2864) * Cherry-picked EngineHub/WorldEdit@cfd9eea Co-authored-by: Pierre Maurice Schwang <mail@pschwang.eu> * Allow metadata tags to be optional + default value for this.origin Co-authored-by: Pierre Maurice Schwang <mail@pschwang.eu> * Correct depth to be default of `0` Co-authored-by: Pierre Maurice Schwang <mail@pschwang.eu> --------- Co-authored-by: Pierre Maurice Schwang <mail@pschwang.eu>
This commit is contained in:
parent
7daafa97f0
commit
8e1922dfe7
@ -41,6 +41,8 @@ import org.apache.logging.log4j.Logger;
|
|||||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
import org.enginehub.linbus.tree.LinCompoundTag;
|
import org.enginehub.linbus.tree.LinCompoundTag;
|
||||||
|
import org.enginehub.linbus.tree.LinIntArrayTag;
|
||||||
|
import org.enginehub.linbus.tree.LinTagType;
|
||||||
import org.jetbrains.annotations.ApiStatus;
|
import org.jetbrains.annotations.ApiStatus;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
@ -88,6 +90,7 @@ public class FastSchematicReaderV3 implements ClipboardReader {
|
|||||||
|
|
||||||
private VersionedDataFixer dataFixer;
|
private VersionedDataFixer dataFixer;
|
||||||
private BlockVector3 offset;
|
private BlockVector3 offset;
|
||||||
|
private BlockVector3 origin = BlockVector3.ZERO;
|
||||||
private BlockState[] blockPalette;
|
private BlockState[] blockPalette;
|
||||||
private BiomeType[] biomePalette;
|
private BiomeType[] biomePalette;
|
||||||
private int dataVersion = -1;
|
private int dataVersion = -1;
|
||||||
@ -137,6 +140,24 @@ public class FastSchematicReaderV3 implements ClipboardReader {
|
|||||||
this.dataVersion = this.dataInputStream.readInt();
|
this.dataVersion = this.dataInputStream.readInt();
|
||||||
this.dataFixer = ReaderUtil.getVersionedDataFixer(this.dataVersion, platform, platform.getDataVersion());
|
this.dataFixer = ReaderUtil.getVersionedDataFixer(this.dataVersion, platform, platform.getDataVersion());
|
||||||
}
|
}
|
||||||
|
case "Metadata" -> {
|
||||||
|
LinCompoundTag metadataCompoundTag =
|
||||||
|
(LinCompoundTag) this.nbtInputStream.readTagPayload(NBTConstants.TYPE_COMPOUND, 0).toLinTag();
|
||||||
|
|
||||||
|
LinCompoundTag worldEditTag = metadataCompoundTag.findTag("WorldEdit", LinTagType.compoundTag());
|
||||||
|
if (worldEditTag != null) { // allowed to be optional
|
||||||
|
LinIntArrayTag originTag = worldEditTag.findTag("Origin", LinTagType.intArrayTag());
|
||||||
|
if (originTag != null) { // allowed to be optional
|
||||||
|
int[] parts = originTag.value();
|
||||||
|
|
||||||
|
if (parts.length != 3) {
|
||||||
|
throw new IOException("`Metadata > WorldEdit > Origin` int array length is invalid.");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.origin = BlockVector3.at(parts[0], parts[1], parts[2]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
case "Offset" -> {
|
case "Offset" -> {
|
||||||
this.dataInputStream.skipNBytes(4); // Array Length field (4 byte int)
|
this.dataInputStream.skipNBytes(4); // Array Length field (4 byte int)
|
||||||
this.offset = BlockVector3.at(
|
this.offset = BlockVector3.at(
|
||||||
@ -173,7 +194,7 @@ public class FastSchematicReaderV3 implements ClipboardReader {
|
|||||||
|
|
||||||
clipboard.setOrigin(this.offset.multiply(-1));
|
clipboard.setOrigin(this.offset.multiply(-1));
|
||||||
if (clipboard instanceof SimpleClipboard simpleClipboard && !this.offset.equals(BlockVector3.ZERO)) {
|
if (clipboard instanceof SimpleClipboard simpleClipboard && !this.offset.equals(BlockVector3.ZERO)) {
|
||||||
clipboard = new BlockArrayClipboard(simpleClipboard, this.offset);
|
clipboard = new BlockArrayClipboard(simpleClipboard, this.offset.add(this.origin));
|
||||||
}
|
}
|
||||||
return clipboard;
|
return clipboard;
|
||||||
}
|
}
|
||||||
|
@ -135,7 +135,7 @@ public class SpongeSchematicV3Reader implements ClipboardReader {
|
|||||||
Map<Integer, BlockState> palette = ReaderUtil.decodePalette(paletteObject, fixer);
|
Map<Integer, BlockState> palette = ReaderUtil.decodePalette(paletteObject, fixer);
|
||||||
|
|
||||||
byte[] blocks = blockContainer.getTag("Data", LinTagType.byteArrayTag()).value();
|
byte[] blocks = blockContainer.getTag("Data", LinTagType.byteArrayTag()).value();
|
||||||
LinListTag<LinCompoundTag> blockEntities = blockContainer.getListTag("BlockEntities", LinTagType.compoundTag());
|
LinListTag<LinCompoundTag> blockEntities = blockContainer.findListTag("BlockEntities", LinTagType.compoundTag());
|
||||||
|
|
||||||
ReaderUtil.initializeClipboardFromBlocks(clipboard, palette, blocks, blockEntities, fixer, true);
|
ReaderUtil.initializeClipboardFromBlocks(clipboard, palette, blocks, blockEntities, fixer, true);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user