mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-01 02:46:41 +00:00
WIP Anvil API
This commit is contained in:
@ -34,6 +34,7 @@ import com.sk89q.worldedit.regions.Regions;
|
||||
import com.sk89q.worldedit.util.Location;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.net.URI;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -127,6 +128,14 @@ public interface Clipboard extends Extent, Iterable<BlockVector3> {
|
||||
return Regions.asFlatRegion(getRegion()).asFlatRegion().iterator();
|
||||
}
|
||||
|
||||
default URI getURI() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// default void paste(Extent other, BlockVector3 to) {
|
||||
// TODO FIXME
|
||||
// }
|
||||
|
||||
@Override
|
||||
default <T extends Filter> T apply(Region region, T filter) {
|
||||
if (region.equals(getRegion())) {
|
||||
|
@ -0,0 +1,4 @@
|
||||
package com.sk89q.worldedit.extent.clipboard.io;
|
||||
|
||||
public class FaweFormat {
|
||||
}
|
@ -48,6 +48,7 @@ import com.sk89q.worldedit.extent.clipboard.Clipboard;
|
||||
import com.sk89q.worldedit.math.BlockVector2;
|
||||
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;
|
||||
import com.sk89q.worldedit.world.biome.BiomeTypes;
|
||||
@ -113,7 +114,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
private LinearClipboard setupClipboard(int size, UUID uuid) {
|
||||
if (fc != null) {
|
||||
if (fc.getDimensions().getX() == 0) {
|
||||
fc.setDimensions(BlockVector3.at(size, 1, 1));
|
||||
// fc.setDimensions(BlockVector3.at(size, 1, 1));
|
||||
}
|
||||
return fc;
|
||||
}
|
||||
@ -237,20 +238,19 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
value.remove("Id");
|
||||
}
|
||||
|
||||
ListTag positionTag = compound.getListTag("Pos");
|
||||
ListTag directionTag = compound.getListTag("Rotation");
|
||||
EntityType type = EntityTypes.parse(id.getValue());
|
||||
if (type != null) {
|
||||
compound = fixEntity(compound);
|
||||
BaseEntity state = new BaseEntity(type, compound);
|
||||
fc.createEntity(clipboard, positionTag.asDouble(0), positionTag.asDouble(1), positionTag.asDouble(2), (float) directionTag.asDouble(0), (float) directionTag.asDouble(1), state);
|
||||
Location loc = compound.getEntityLocation(fc);
|
||||
fc.createEntity(loc, state);
|
||||
} else {
|
||||
Fawe.debug("Invalid entity: " + id);
|
||||
}
|
||||
});
|
||||
streamer.readFully();
|
||||
if (fc == null) setupClipboard(length * width * height, uuid);
|
||||
fc.setDimensions(BlockVector3.at(width, height, length));
|
||||
// fc.setDimensions(BlockVector3.at(width, height, length));
|
||||
BlockVector3 origin = min;
|
||||
CuboidRegion region;
|
||||
if (offsetX != Integer.MIN_VALUE && offsetY != Integer.MIN_VALUE && offsetZ != Integer.MIN_VALUE) {
|
||||
@ -281,7 +281,7 @@ public class SpongeSchematicReader extends NBTSchematicReader {
|
||||
}
|
||||
}
|
||||
}
|
||||
clipboard.init(region, fc);
|
||||
// clipboard.init(region, fc);
|
||||
clipboard.setOrigin(origin);
|
||||
return clipboard;
|
||||
}
|
||||
|
@ -143,58 +143,29 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
char[] palette = new char[BlockTypes.states.length];
|
||||
Arrays.fill(palette, Character.MAX_VALUE);
|
||||
int[] paletteMax = {0};
|
||||
int numTiles = 0;
|
||||
for (BlockVector3 pos : clipboard) {
|
||||
BaseBlock block = pos.getFullBlock(clipboard);
|
||||
CompoundTag nbt = block.getNbtData();
|
||||
if (nbt != null) {
|
||||
Map<String, Tag> values = nbt.getValue();
|
||||
|
||||
values.remove("id"); // Remove 'id' if it exists. We want 'Id'
|
||||
|
||||
int[] numTiles = {0};
|
||||
LinearClipboard.BlockReader reader = new LinearClipboard.BlockReader() {
|
||||
@Override
|
||||
public <B extends BlockStateHolder<B>> void run(int x, int y, int z, B block) {
|
||||
try {
|
||||
if (block.hasNbtData()) {
|
||||
CompoundTag nbt = block.getNbtData();
|
||||
if (nbt != null) {
|
||||
Map<String, Tag> values = nbt.getValue();
|
||||
|
||||
values.remove("id"); // Remove 'id' if it exists. We want 'Id'
|
||||
|
||||
// Positions are kept in NBT, we don't want that.
|
||||
values.remove("x");
|
||||
values.remove("y");
|
||||
values.remove("z");
|
||||
if (!values.containsKey("Id")) {
|
||||
values.put("Id", new StringTag(block.getNbtId()));
|
||||
}
|
||||
values.put("Pos", new IntArrayTag(new int[]{
|
||||
x,
|
||||
y,
|
||||
z
|
||||
}));
|
||||
numTiles[0]++;
|
||||
tilesOut.writeTagPayload(block.getNbtData());
|
||||
}
|
||||
}
|
||||
int ordinal = block.getOrdinal();
|
||||
char value = palette[ordinal];
|
||||
if (value == Character.MAX_VALUE) {
|
||||
int size = paletteMax[0]++;
|
||||
palette[ordinal] = value = (char) size;
|
||||
paletteList.add(ordinal);
|
||||
}
|
||||
IOUtil.writeVarInt(blocksOut, value);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
// Positions are kept in NBT, we don't want that.
|
||||
values.remove("x");
|
||||
values.remove("y");
|
||||
values.remove("z");
|
||||
if (!values.containsKey("Id")) {
|
||||
values.put("Id", new StringTag(block.getNbtId()));
|
||||
}
|
||||
}
|
||||
};
|
||||
if (clipboard instanceof BlockArrayClipboard) {
|
||||
((BlockArrayClipboard) clipboard).IMP.forEach(reader, true);
|
||||
} else {
|
||||
for (BlockVector3 pt : region) {
|
||||
BaseBlock block = clipboard.getFullBlock(pt);
|
||||
int x = pt.getBlockX() - min.getBlockX();
|
||||
int y = pt.getBlockY() - min.getBlockY();
|
||||
int z = pt.getBlockZ() - min.getBlockY();
|
||||
reader.run(x, y, z, block);
|
||||
values.put("Pos", new IntArrayTag(new int[]{
|
||||
pos.getX(),
|
||||
pos.getY(),
|
||||
pos.getZ()
|
||||
}));
|
||||
numTiles++;
|
||||
tilesOut.writeTagPayload(block.getNbtData());
|
||||
}
|
||||
}
|
||||
// close
|
||||
@ -217,10 +188,10 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
IOUtil.copy(in, rawStream);
|
||||
}
|
||||
|
||||
if (numTiles[0] != 0) {
|
||||
if (numTiles != 0) {
|
||||
out.writeNamedTagName("TileEntities", NBTConstants.TYPE_LIST);
|
||||
rawStream.write(NBTConstants.TYPE_COMPOUND);
|
||||
rawStream.writeInt(numTiles[0]);
|
||||
rawStream.writeInt(numTiles);
|
||||
try (LZ4BlockInputStream in = new LZ4BlockInputStream(new ByteArrayInputStream(tilesCompressed.toByteArray()))) {
|
||||
IOUtil.copy(in, rawStream);
|
||||
}
|
||||
@ -287,20 +258,17 @@ public class SpongeSchematicWriter implements ClipboardWriter {
|
||||
}
|
||||
}
|
||||
};
|
||||
if (clipboard instanceof BlockArrayClipboard) {
|
||||
((BlockArrayClipboard) clipboard).IMP.streamBiomes(task);
|
||||
} else {
|
||||
BlockVector3 min = clipboard.getMinimumPoint();
|
||||
int width = clipboard.getRegion().getWidth();
|
||||
int length = clipboard.getRegion().getLength();
|
||||
for (int z = 0, i = 0; z < length; z++) {
|
||||
int z0 = min.getBlockZ() + z;
|
||||
for (int x = 0; x < width; x++, i++) {
|
||||
int x0 = min.getBlockX() + x;
|
||||
BlockVector2 pt = BlockVector2.at(x0, z0);
|
||||
BiomeType biome = clipboard.getBiome(pt);
|
||||
task.run(i, biome.getInternalId());
|
||||
}
|
||||
System.out.println("TODO Optimize biome write");
|
||||
BlockVector3 min = clipboard.getMinimumPoint();
|
||||
int width = clipboard.getRegion().getWidth();
|
||||
int length = clipboard.getRegion().getLength();
|
||||
for (int z = 0, i = 0; z < length; z++) {
|
||||
int z0 = min.getBlockZ() + z;
|
||||
for (int x = 0; x < width; x++, i++) {
|
||||
int x0 = min.getBlockX() + x;
|
||||
BlockVector2 pt = BlockVector2.at(x0, z0);
|
||||
BiomeType biome = clipboard.getBiome(pt);
|
||||
task.run(i, biome.getInternalId());
|
||||
}
|
||||
}
|
||||
biomesOut.close();
|
||||
|
Reference in New Issue
Block a user