Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increased supported blockids to 65792 #25

Merged
merged 4 commits into from
Jan 18, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,7 @@ public ISchematic readFromNBT(NBTTagCompound tagCompound) {

byte[] localBlocks = tagCompound.getByteArray(Names.NBT.BLOCKS);
byte[] localMetadata = tagCompound.getByteArray(Names.NBT.DATA);

boolean extra = false;
byte[] extraBlocks = null;
byte[] extraBlocksNibble;
if (tagCompound.hasKey(Names.NBT.ADD_BLOCKS)) {
extra = true;
extraBlocksNibble = tagCompound.getByteArray(Names.NBT.ADD_BLOCKS);
extraBlocks = new byte[extraBlocksNibble.length * 2];
for (int i = 0; i < extraBlocksNibble.length; i++) {
extraBlocks[i * 2 + 0] = (byte) ((extraBlocksNibble[i] >> 4) & 0xF);
extraBlocks[i * 2 + 1] = (byte) (extraBlocksNibble[i] & 0xF);
}
} else if (tagCompound.hasKey(Names.NBT.ADD_BLOCKS_SCHEMATICA)) {
extra = true;
extraBlocks = tagCompound.getByteArray(Names.NBT.ADD_BLOCKS_SCHEMATICA);
}
byte[] extraBlocks = tagCompound.getByteArray(Names.NBT.ADD_BLOCKS);

short width = tagCompound.getShort(Names.NBT.WIDTH);
short length = tagCompound.getShort(Names.NBT.LENGTH);
Expand All @@ -72,7 +57,7 @@ public ISchematic readFromNBT(NBTTagCompound tagCompound) {
for (int y = 0; y < height; y++) {
for (int z = 0; z < length; z++) {
int index = x + (y * length + z) * width;
int blockID = (localBlocks[index] & 0xFF) | (extra ? ((extraBlocks[index] & 0xFF) << 8) : 0);
int blockID = (localBlocks[index] & 0xFF) | ((extraBlocks[index] & 0xFF) * 256);
int meta = localMetadata[index] & 0xFF;

if ((id = oldToNew.get((short) blockID)) != null) {
Expand Down Expand Up @@ -115,22 +100,23 @@ public boolean writeToNBT(NBTTagCompound tagCompound, ISchematic schematic, Worl
byte[] localBlocks = new byte[size];
byte[] localMetadata = new byte[size];
byte[] extraBlocks = new byte[size];
byte[] extraBlocksNibble = new byte[(int) Math.ceil(size / 2.0)];
boolean extra = false;

Map<String, Short> mappings = new HashMap<>();
for (int x = 0; x < schematic.getWidth(); x++) {
for (int y = 0; y < schematic.getHeight(); y++) {
for (int z = 0; z < schematic.getLength(); z++) {
final int index = x + (y * schematic.getLength() + z) * schematic.getWidth();
final Block block = schematic.getBlock(x, y, z);
final int blockId = BLOCK_REGISTRY.getId(block);
localBlocks[index] = (byte) blockId;
localMetadata[index] = (byte) schematic.getBlockMetadata(x, y, z);
if ((extraBlocks[index] = (byte) (blockId >> 8)) > 0) {
extra = true;
int blockId = BLOCK_REGISTRY.getId(block);
int tempblockId = blockId;
int numextra = 0;
for (int i = 1; tempblockId > 256; i++) {
tempblockId = tempblockId - 256;
numextra = i;
}

localBlocks[index] = (byte) tempblockId;
extraBlocks[index] = (byte) numextra;
localMetadata[index] = (byte) schematic.getBlockMetadata(x, y, z);
String name = BLOCK_REGISTRY.getNameForObject(block);
if (!mappings.containsKey(name)) {
mappings.put(name, (short) blockId);
Expand Down Expand Up @@ -167,14 +153,6 @@ public boolean writeToNBT(NBTTagCompound tagCompound, ISchematic schematic, Worl
}
}

for (int i = 0; i < extraBlocksNibble.length; i++) {
if (i * 2 + 1 < extraBlocks.length) {
extraBlocksNibble[i] = (byte) ((extraBlocks[i * 2 + 0] << 4) | extraBlocks[i * 2 + 1]);
} else {
extraBlocksNibble[i] = (byte) (extraBlocks[i * 2 + 0] << 4);
}
}

final NBTTagList entityList = new NBTTagList();
final List<Entity> entities = schematic.getEntities();
for (Entity entity : entities) {
Expand All @@ -199,9 +177,7 @@ public boolean writeToNBT(NBTTagCompound tagCompound, ISchematic schematic, Worl
tagCompound.setString(Names.NBT.MATERIALS, Names.NBT.FORMAT_ALPHA);
tagCompound.setByteArray(Names.NBT.BLOCKS, localBlocks);
tagCompound.setByteArray(Names.NBT.DATA, localMetadata);
if (extra) {
tagCompound.setByteArray(Names.NBT.ADD_BLOCKS, extraBlocksNibble);
}
tagCompound.setByteArray(Names.NBT.ADD_BLOCKS, extraBlocks);
tagCompound.setTag(Names.NBT.ENTITIES, entityList);
tagCompound.setTag(Names.NBT.TILE_ENTITIES, tileEntitiesList);
tagCompound.setTag(Names.NBT.MAPPING_SCHEMATICA, nbtMapping);
Expand Down