Skip to content

Commit

Permalink
Fix schemetic across world
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleid-liner committed Oct 28, 2023
1 parent e3681f6 commit 92d32cf
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

import javax.annotation.Nullable;

import net.minecraft.block.Block;

import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag;
Expand Down Expand Up @@ -205,7 +207,26 @@ public Clipboard read(WorldData data) throws IOException {
for (int z = 0; z < length; ++z) {
int index = y * width * length + z * width + x;
BlockVector pt = new BlockVector(x, y, z);
BaseBlock block = new BaseBlock(blocks[index], blockData[index]);

short bId = blocks[index];
if (tileEntitiesMap.containsKey(pt)) {
var tileEntity = tileEntitiesMap.get(pt);
if (tileEntity.containsKey("blockName")) {
bId = (short) Block.blockRegistry.getIDForObject(
Block.blockRegistry.getObject(
tileEntity.get("blockName")
.getValue()));
System.out.println(
tileEntity.get("blockName")
.getValue() + Short.toString(bId));
tileEntity.remove("blockName");
if (tileEntity.size() == 3) {
tileEntitiesMap.remove(pt);
}
}
}

BaseBlock block = new BaseBlock(bId, blockData[index]);

if (tileEntitiesMap.containsKey(pt)) {
block.setNbtData(new CompoundTag(tileEntitiesMap.get(pt)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import java.util.Map;
import java.util.Map.Entry;

import net.minecraft.block.Block;

import com.sk89q.jnbt.ByteArrayTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.DoubleTag;
Expand Down Expand Up @@ -130,23 +132,26 @@ public void write(Clipboard clipboard, WorldData data) throws IOException {
blocks[index] = (byte) block.getType();
blockData[index] = (byte) block.getData();

String name = Block.blockRegistry.getNameForObject(Block.blockRegistry.getObjectById(block.getType()));
Map<String, Tag> values = new HashMap<String, Tag>();
values.put("blockName", new StringTag(name));

// Store TileEntity data
CompoundTag rawTag = block.getNbtData();
if (rawTag != null) {
Map<String, Tag> values = new HashMap<String, Tag>();
for (Entry<String, Tag> entry : rawTag.getValue()
.entrySet()) {
values.put(entry.getKey(), entry.getValue());
}

values.put("id", new StringTag(block.getNbtId()));
values.put("x", new IntTag(x));
values.put("y", new IntTag(y));
values.put("z", new IntTag(z));

CompoundTag tileEntityTag = new CompoundTag(values);
tileEntities.add(tileEntityTag);
}
values.put("x", new IntTag(x));
values.put("y", new IntTag(y));
values.put("z", new IntTag(z));

CompoundTag tileEntityTag = new CompoundTag(values);
tileEntities.add(tileEntityTag);
}

schematic.put("Blocks", new ByteArrayTag(blocks));
Expand Down

0 comments on commit 92d32cf

Please sign in to comment.