Better reading of schematic biomes.

Use biomes in the P2 schematic handler and save as a .schem not .schematic (when it's enabled again)
Dieser Commit ist enthalten in:
dordsor21 2020-03-28 10:44:51 +00:00
Ursprung 6275e9298e
Commit 8ffdd8a9e9
2 geänderte Dateien mit 31 neuen und 34 gelöschten Zeilen

Datei anzeigen

@ -61,7 +61,7 @@ public class FaweSchematicHandler extends SchematicHandler {
final CuboidRegion region = new CuboidRegion(BlockVector3.at(pos1.getX(), pos1.getY(), pos1.getZ()), BlockVector3.at(pos2.getX(), pos2.getY(), pos2.getZ()));
final EditSession editSession = new EditSessionBuilder(adaptedWorld).checkMemory(false).fastmode(true).limitUnlimited().changeSetNull().autoQueue(false).build();
ReadOnlyClipboard clipboard = ReadOnlyClipboard.of(editSession, region);
ReadOnlyClipboard clipboard = ReadOnlyClipboard.of(editSession, region, false, true);
Clipboard holder = new BlockArrayClipboard(region, clipboard);
CompressedSchematicTag tag = new CompressedSchematicTag(holder);
@ -120,7 +120,7 @@ public class FaweSchematicHandler extends SchematicHandler {
whenDone.run(url);
return;
}
MainUtil.upload(uuid, file, "schematic", new RunnableVal<OutputStream>() {
MainUtil.upload(uuid, file, "schem", new RunnableVal<OutputStream>() {
@Override
public void run(OutputStream output) {
try {

Datei anzeigen

@ -20,7 +20,6 @@
package com.sk89q.worldedit.extent.clipboard.io;
import com.boydti.fawe.FaweCache;
import com.boydti.fawe.jnbt.streamer.IntValueReader;
import com.boydti.fawe.jnbt.streamer.StreamDelegate;
import com.boydti.fawe.jnbt.streamer.ValueReader;
import com.boydti.fawe.object.FaweInputStream;
@ -38,7 +37,6 @@ import com.sk89q.worldedit.extension.input.InputParseException;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.world.DataFixer;
import com.sk89q.worldedit.world.biome.BiomeType;
@ -112,6 +110,11 @@ public class FastSchematicReader extends NBTSchematicReader {
return fixer.fixUp(DataFixer.FixTypes.ENTITY, tag, dataVersion);
}
private String fixBiome(String biomePalettePart) {
if(fixer == null || dataVersion == -1) return biomePalettePart;
return fixer.fixUp(DataFixer.FixTypes.BIOME, biomePalettePart, dataVersion);
}
public StreamDelegate createDelegate() {
StreamDelegate root = new StreamDelegate();
StreamDelegate schematic = root.add("Schematic");
@ -147,6 +150,7 @@ public class FastSchematicReader extends NBTSchematicReader {
blocks = new FaweOutputStream(new LZ4BlockOutputStream(blocksOut));
});
blockData.withInt((index, value) -> blocks.write(value));
StreamDelegate tilesDelegate = schematic.add("TileEntities");
tilesDelegate.withInfo((length, type) -> tiles = new ArrayList<>(length));
tilesDelegate.withElem((ValueReader<Map<String, Object>>) (index, tile) -> tiles.add(tile));
@ -154,36 +158,28 @@ public class FastSchematicReader extends NBTSchematicReader {
StreamDelegate entitiesDelegate = schematic.add("Entities");
entitiesDelegate.withInfo((length, type) -> entities = new ArrayList<>(length));
entitiesDelegate.withElem((ValueReader<Map<String, Object>>) (index, entity) -> entities.add(entity));
StreamDelegate biomePaletteDelegate = schematic.add("BiomePalette");
biomePaletteDelegate.withValue((ValueReader<Map<String, Object>>) (ignore, v) -> {
biomePalette = new char[v.size()];
for (Entry<String, Object> entry : v.entrySet()) {
BiomeType biome = null;
try {
String biomePalettePart = fixBiome(entry.getKey());
biome = BiomeTypes.get(biomePalettePart);
} catch (InputParseException e) {
e.printStackTrace();
}
int index = (int) entry.getValue();
biomePalette[index] = (char) biome.getInternalId();
}
});
StreamDelegate biomeData = schematic.add("BiomeData");
biomeData.withInfo((length, type) -> {
biomesOut = new FastByteArrayOutputStream();
biomes = new FaweOutputStream(new LZ4BlockOutputStream(blocksOut));
});
biomeData.withElem((IntValueReader) (index, value) -> {
try {
biomes.write(value); // byte of varInt
} catch (IOException e) {
e.printStackTrace();
}
});
StreamDelegate biomePaletteDelegate = schematic.add("BiomePalette");
biomePaletteDelegate.withInfo((length, type) -> biomePalette = new char[length]);
biomePaletteDelegate.withElem(new ValueReader<Map.Entry<String, Number>>() {
@Override
public void apply(int index, Map.Entry<String, Number> palettePart) {
String key = palettePart.getKey();
if (fixer != null) {
key = fixer.fixUp(DataFixer.FixTypes.BIOME, key, dataVersion);
}
BiomeType biome = BiomeTypes.get(key);
if (biome == null) {
System. out.println("Unknown biome " + key);
biome = BiomeTypes.FOREST;
}
int paletteIndex = palettePart.getValue().intValue();
biomePalette[paletteIndex] = (char) biome.getInternalId();
}
biomes = new FaweOutputStream(new LZ4BlockOutputStream(biomesOut));
});
biomeData.withInt((index, value) -> biomes.write(value));
return root;
}
@ -193,8 +189,7 @@ public class FastSchematicReader extends NBTSchematicReader {
private BiomeType getBiomeType(FaweInputStream fis) throws IOException {
char biomeId = biomePalette[fis.readVarInt()];
BiomeType biome = BiomeTypes.get(biomeId);
return biome;
return BiomeTypes.get(biomeId);
}
@Override
@ -255,12 +250,14 @@ public class FastSchematicReader extends NBTSchematicReader {
LinearClipboard linear = (LinearClipboard) clipboard;
int volume = width * length;
for (int index = 0; index < volume; index++) {
linear.setBiome(index, getBiomeType(fis));
BiomeType biome = getBiomeType(fis);
linear.setBiome(index, biome);
}
} else {
for (int z = 0; z < length; z++) {
for (int x = 0; x < width; x++) {
clipboard.setBiome(x, 0, z, getBiomeType(fis));
BiomeType biome = getBiomeType(fis);
clipboard.setBiome(x, 0, z, biome);
}
}
}