mirror of
https://github.com/PolyhedralDev/Terra.git
synced 2026-10-26 14:00:14 +00:00
Merge branch 'ver/6.3.0' into dev/img-lib
This commit is contained in:
commit
5188477a6d
2 files changed
+39
-4
No files matched your search
+29
-1
@@ -30,6 +30,7 @@ import com.dfsek.terra.api.inject.annotations.Inject;
|
|||||||
import com.dfsek.terra.api.registry.CheckedRegistry;
|
import com.dfsek.terra.api.registry.CheckedRegistry;
|
||||||
import com.dfsek.terra.api.structure.Structure;
|
import com.dfsek.terra.api.structure.Structure;
|
||||||
import com.dfsek.terra.api.util.StringUtil;
|
import com.dfsek.terra.api.util.StringUtil;
|
||||||
|
import com.dfsek.terra.api.util.vector.Vector3Int;
|
||||||
|
|
||||||
|
|
||||||
public class SpongeSchematicAddon implements AddonInitializer {
|
public class SpongeSchematicAddon implements AddonInitializer {
|
||||||
@@ -71,10 +72,37 @@ public class SpongeSchematicAddon implements AddonInitializer {
|
|||||||
public SpongeStructure convert(InputStream in, String id) {
|
public SpongeStructure convert(InputStream in, String id) {
|
||||||
try {
|
try {
|
||||||
CompoundTag baseTag = (CompoundTag) new NBTDeserializer(false).fromStream(detectDecompression(in)).getTag();
|
CompoundTag baseTag = (CompoundTag) new NBTDeserializer(false).fromStream(detectDecompression(in)).getTag();
|
||||||
|
int ver = baseTag.getInt("Version");
|
||||||
int wid = baseTag.getShort("Width");
|
int wid = baseTag.getShort("Width");
|
||||||
int len = baseTag.getShort("Length");
|
int len = baseTag.getShort("Length");
|
||||||
int hei = baseTag.getShort("Height");
|
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");
|
ByteArrayTag blocks = baseTag.getByteArrayTag("BlockData");
|
||||||
|
|
||||||
CompoundTag palette = (CompoundTag) baseTag.get("Palette");
|
CompoundTag palette = (CompoundTag) baseTag.get("Palette");
|
||||||
@@ -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) {
|
} catch(IOException e) {
|
||||||
throw new IllegalArgumentException("Failed to parse Sponge schematic: ", e);
|
throw new IllegalArgumentException("Failed to parse Sponge schematic: ", e);
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-3
@@ -23,10 +23,15 @@ public class SpongeStructure implements Structure, Keyed<SpongeStructure> {
|
|||||||
|
|
||||||
private final BlockState[][][] blocks;
|
private final BlockState[][][] blocks;
|
||||||
|
|
||||||
|
private final int offsetX, offsetY, offsetZ;
|
||||||
|
|
||||||
private final RegistryKey id;
|
private final RegistryKey id;
|
||||||
|
|
||||||
public SpongeStructure(BlockState[][][] blocks, RegistryKey id) {
|
public SpongeStructure(BlockState[][][] blocks, Vector3Int offset, RegistryKey id) {
|
||||||
this.blocks = blocks;
|
this.blocks = blocks;
|
||||||
|
this.offsetX = offset.getX();
|
||||||
|
this.offsetY = offset.getY();
|
||||||
|
this.offsetZ = offset.getZ();
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,13 +42,15 @@ public class SpongeStructure implements Structure, Keyed<SpongeStructure> {
|
|||||||
int bZ = location.getZ();
|
int bZ = location.getZ();
|
||||||
for(int x = 0; x < blocks.length; x++) {
|
for(int x = 0; x < blocks.length; x++) {
|
||||||
for(int z = 0; z < blocks[x].length; z++) {
|
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 rX = r.getX();
|
||||||
int rZ = r.getZ();
|
int rZ = r.getZ();
|
||||||
for(int y = 0; y < blocks[x][z].length; y++) {
|
for(int y = 0; y < blocks[x][z].length; y++) {
|
||||||
BlockState state = blocks[x][z][y];
|
BlockState state = blocks[x][z][y];
|
||||||
if(state == null) continue;
|
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