mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-02-16 10:30:42 +00:00
Merge branch 'ver/6.3.0' into dev/img-lib
This commit is contained in:
@@ -30,6 +30,7 @@ import com.dfsek.terra.api.inject.annotations.Inject;
|
||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||
import com.dfsek.terra.api.structure.Structure;
|
||||
import com.dfsek.terra.api.util.StringUtil;
|
||||
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||
|
||||
|
||||
public class SpongeSchematicAddon implements AddonInitializer {
|
||||
@@ -71,9 +72,36 @@ public class SpongeSchematicAddon implements AddonInitializer {
|
||||
public SpongeStructure convert(InputStream in, String id) {
|
||||
try {
|
||||
CompoundTag baseTag = (CompoundTag) new NBTDeserializer(false).fromStream(detectDecompression(in)).getTag();
|
||||
int ver = baseTag.getInt("Version");
|
||||
int wid = baseTag.getShort("Width");
|
||||
int len = baseTag.getShort("Length");
|
||||
int hei = baseTag.getShort("Height");
|
||||
|
||||
CompoundTag metadata = baseTag.getCompoundTag("Metadata");
|
||||
|
||||
Vector3Int offset = switch(ver) {
|
||||
case 2 -> {
|
||||
// Use WorldEdit defined legacy relative offset if it exists in schematic metadata
|
||||
IntTag worldEditOffsetX = metadata.getIntTag("WEOffsetX");
|
||||
IntTag worldEditOffsetY = metadata.getIntTag("WEOffsetY");
|
||||
IntTag worldEditOffsetZ = metadata.getIntTag("WEOffsetZ");
|
||||
if(worldEditOffsetX != null || worldEditOffsetY != null || worldEditOffsetZ != null) {
|
||||
if(worldEditOffsetX == null || worldEditOffsetY == null || worldEditOffsetZ == null) {
|
||||
throw new IllegalArgumentException("Failed to parse Sponge schematic: Malformed WorldEdit offset");
|
||||
}
|
||||
yield Vector3Int.of(worldEditOffsetX.asInt(), worldEditOffsetY.asInt(), worldEditOffsetZ.asInt());
|
||||
} else {
|
||||
// Relative offset handling via 'Offset' field is ambiguous in spec 2 so just apply no offset
|
||||
yield Vector3Int.zero();
|
||||
}
|
||||
}
|
||||
case 3 -> {
|
||||
// Relative offset is more concretely defined in spec 3 to use 'Offset' field
|
||||
int[] offsetArray = baseTag.getIntArray("Offset");
|
||||
yield Vector3Int.of(offsetArray[0], offsetArray[1], offsetArray[2]);
|
||||
}
|
||||
default -> throw new IllegalArgumentException("Failed to parse Sponge schematic: Unsupported format version: " + ver);
|
||||
};
|
||||
|
||||
ByteArrayTag blocks = baseTag.getByteArrayTag("BlockData");
|
||||
|
||||
@@ -97,7 +125,7 @@ public class SpongeSchematicAddon implements AddonInitializer {
|
||||
}
|
||||
}
|
||||
|
||||
return new SpongeStructure(states, addon.key(id));
|
||||
return new SpongeStructure(states, offset, addon.key(id));
|
||||
} catch(IOException e) {
|
||||
throw new IllegalArgumentException("Failed to parse Sponge schematic: ", e);
|
||||
}
|
||||
|
||||
@@ -23,10 +23,15 @@ public class SpongeStructure implements Structure, Keyed<SpongeStructure> {
|
||||
|
||||
private final BlockState[][][] blocks;
|
||||
|
||||
private final int offsetX, offsetY, offsetZ;
|
||||
|
||||
private final RegistryKey id;
|
||||
|
||||
public SpongeStructure(BlockState[][][] blocks, RegistryKey id) {
|
||||
public SpongeStructure(BlockState[][][] blocks, Vector3Int offset, RegistryKey id) {
|
||||
this.blocks = blocks;
|
||||
this.offsetX = offset.getX();
|
||||
this.offsetY = offset.getY();
|
||||
this.offsetZ = offset.getZ();
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -37,13 +42,15 @@ public class SpongeStructure implements Structure, Keyed<SpongeStructure> {
|
||||
int bZ = location.getZ();
|
||||
for(int x = 0; x < blocks.length; x++) {
|
||||
for(int z = 0; z < blocks[x].length; z++) {
|
||||
Vector2Int r = Vector2Int.of(x, z).rotate(rotation);
|
||||
int oX = x + offsetX;
|
||||
int oZ = z + offsetZ;
|
||||
Vector2Int r = Vector2Int.of(oX, oZ).rotate(rotation);
|
||||
int rX = r.getX();
|
||||
int rZ = r.getZ();
|
||||
for(int y = 0; y < blocks[x][z].length; y++) {
|
||||
BlockState state = blocks[x][z][y];
|
||||
if(state == null) continue;
|
||||
world.setBlockState(bX + rX, bY + y, bZ + rZ, state);
|
||||
world.setBlockState(bX + rX, bY + y + offsetY, bZ + rZ, state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user