SteamWar/BauSystem2.0
Archiviert
12
0

Fix some bugs and increase the size by to much
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2023-02-11 08:12:49 +01:00
Ursprung 42f8a044a4
Commit b17cd9acda

Datei anzeigen

@ -75,21 +75,59 @@ public class TSchemWriter implements ClipboardWriter {
} }
out.writeNamedTag("SizeMinOffset", new ByteArrayTag(bsArray)); out.writeNamedTag("SizeMinOffset", new ByteArrayTag(bsArray));
Map<BlockState, BitSet> blockMap = new HashMap<>(); Map<BlockState, byte[]> blocks = new HashMap<>();
typedClipboard.getBlocks().forEach((blockState, blockVector3s) -> {
blockMap.put(blockState, new BitSet(volume));
});
clipboard.getRegion().forEach(blockVector3 -> {
int index = blockVector3.getBlockX() + blockVector3.getBlockY() * region.getWidth() + blockVector3.getBlockZ() * region.getWidth() * region.getHeight();
for (Map.Entry<BlockState, Set<BlockVector3>> entry : typedClipboard.getBlocks().entrySet()) { for (Map.Entry<BlockState, Set<BlockVector3>> entry : typedClipboard.getBlocks().entrySet()) {
if (entry.getValue().contains(blockVector3)) { BitSet bitSet = new BitSet(volume);
blockMap.get(entry.getKey()).set(index); for (BlockVector3 blockVector3 : entry.getValue()) {
int index = blockVector3.getBlockX() + blockVector3.getBlockY() * region.getWidth() + blockVector3.getBlockZ() * region.getWidth() * region.getHeight();
bitSet.set(index);
}
byte[] bytes = bitSet.toByteArray();
// RunLengthEncoding
List<Byte> bytes2 = new ArrayList<>();
int last = -1;
int count = 0;
for (int i = 0; i < bytes.length; i++) {
byte b = bytes[i];
if (b == last) {
count++;
} else {
if (count > 0) {
writeVarInt((count - 1), bytes2);
bytes2.add((byte) last);
}
last = b;
count = 1;
} }
} }
}); if (count > 0) {
writeVarInt((count - 1), bytes2);
bytes2.add((byte) last);
}
// Convert to byte array
bytes = new byte[bytes2.size()];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = bytes2.get(i);
}
System.out.println(entry.getKey().getAsString() + " " + bitSet.toByteArray().length + " -> " + bytes2.size());
blocks.put(entry.getKey(), bytes);
}
BlockState biggest = null;
int biggestSize = 0;
for (Map.Entry<BlockState, byte[]> entry : blocks.entrySet()) {
if (entry.getValue().length > biggestSize) {
biggest = entry.getKey();
biggestSize = entry.getValue().length;
}
}
System.out.println("Biggest: " + biggest.getAsString() + " " + biggestSize);
blocks.remove(biggest);
out.writeNamedTag("BaseBlock", biggest.getAsString());
out.writeLazyCompoundTag("Blocks", out2 -> { out.writeLazyCompoundTag("Blocks", out2 -> {
for (Map.Entry<BlockState, BitSet> entry : blockMap.entrySet()) { for (Map.Entry<BlockState, byte[]> entry : blocks.entrySet()) {
out2.writeNamedTag(entry.getKey().getAsString(), entry.getValue().toByteArray()); out2.writeNamedTag(entry.getKey().getAsString(), entry.getValue());
} }
}); });
}); });