Fix schem save order

This commit is contained in:
Jesse Boyd 2019-11-11 21:06:10 +00:00
parent 032942c0e8
commit 53ad3d3cd2
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
5 changed files with 89 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import com.boydti.fawe.jnbt.streamer.IntValueReader;
import com.google.common.collect.ForwardingIterator;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.visitor.Order;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
@ -57,7 +58,14 @@ public abstract class LinearClipboard extends SimpleClipboard implements Clipboa
@Override
public Iterator<BlockVector3> iterator() {
return iterator(Order.YZX);
}
@Override
public Iterator<BlockVector3> iterator(Order order) {
Region region = getRegion();
switch (order) {
case YZX:
if (region instanceof CuboidRegion) {
Iterator<BlockVector3> iter = ((CuboidRegion) region).iterator_old();
LinearFilter filter = new LinearFilter();
@ -73,9 +81,11 @@ public abstract class LinearClipboard extends SimpleClipboard implements Clipboa
return filter.next(super.next());
}
};
} else {
return super.iterator();
}
default:
return order.create(region);
}
}
private class LinearFilter extends AbstractFilterBlock {

View File

@ -19,12 +19,14 @@
package com.sk89q.worldedit.extent.clipboard;
import com.boydti.fawe.beta.Filter;
import com.boydti.fawe.object.clipboard.DelegateClipboard;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldedit.function.visitor.Order;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
@ -38,6 +40,7 @@ import com.sk89q.worldedit.world.block.BlockTypes;
import javax.annotation.Nullable;
import java.io.Closeable;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
@ -232,6 +235,21 @@ public class BlockArrayClipboard extends DelegateClipboard implements Clipboard,
return getParent().getBiomeType(x, z);
}
@Override
public Iterator<BlockVector3> iterator() {
return getParent().iterator();
}
@Override
public Iterator<BlockVector2> iterator2d() {
return getParent().iterator2d();
}
@Override
public Iterator<BlockVector3> iterator(Order order) {
return getParent().iterator(order);
}
/**
* Stores entity data.
*/

View File

@ -41,6 +41,7 @@ import com.sk89q.worldedit.function.mask.Mask;
import com.sk89q.worldedit.function.operation.ForwardExtentCopy;
import com.sk89q.worldedit.function.operation.Operation;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.function.visitor.Order;
import com.sk89q.worldedit.function.visitor.RegionVisitor;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
@ -155,6 +156,10 @@ public interface Clipboard extends Extent, Iterable<BlockVector3>, Closeable {
return getWidth() * getHeight() * getLength();
}
default Iterator<BlockVector3> iterator(Order order) {
return order.create(getRegion());
}
default Iterator<BlockVector3> iterator() {
return getRegion().iterator();
}

View File

@ -21,6 +21,7 @@ package com.sk89q.worldedit.extent.clipboard.io;
import com.boydti.fawe.jnbt.streamer.IntValueReader;
import com.boydti.fawe.object.FaweOutputStream;
import com.boydti.fawe.object.clipboard.LinearClipboard;
import com.boydti.fawe.util.IOUtil;
import com.google.common.collect.Maps;
import com.sk89q.jnbt.CompoundTag;
@ -34,7 +35,9 @@ import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.extension.platform.Capability;
import com.sk89q.worldedit.extent.clipboard.BlockArrayClipboard;
import com.sk89q.worldedit.extent.clipboard.Clipboard;
import com.sk89q.worldedit.function.visitor.Order;
import com.sk89q.worldedit.math.BlockVector2;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.Region;
@ -55,6 +58,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@ -144,8 +148,18 @@ public class SpongeSchematicWriter implements ClipboardWriter {
Arrays.fill(palette, Character.MAX_VALUE);
int paletteMax = 0;
int numTiles = 0;
for (BlockVector3 pos : clipboard) {
BaseBlock block = pos.getFullBlock(clipboard);
Clipboard finalClipboard;
if (clipboard instanceof BlockArrayClipboard) {
finalClipboard = ((BlockArrayClipboard) clipboard).getParent();
} else {
finalClipboard = clipboard;
}
System.out.println(finalClipboard.getClass());
System.out.println(finalClipboard.getRegion());
Iterator<BlockVector3> iterator = finalClipboard.iterator(Order.YZX);
while (iterator.hasNext()) {
BlockVector3 pos = iterator.next();
BaseBlock block = pos.getFullBlock(finalClipboard);
CompoundTag nbt = block.getNbtData();
if (nbt != null) {
Map<String, Tag> values = nbt.getValue();
@ -208,12 +222,12 @@ public class SpongeSchematicWriter implements ClipboardWriter {
out.writeNamedEmptyList("TileEntities");
}
if (clipboard.hasBiomes()) {
writeBiomes(clipboard, out);
if (finalClipboard.hasBiomes()) {
writeBiomes(finalClipboard, out);
}
List<Tag> entities = new ArrayList<>();
for (Entity entity : clipboard.getEntities()) {
for (Entity entity : finalClipboard.getEntities()) {
BaseEntity state = entity.getState();
if (state != null) {
@ -267,7 +281,6 @@ public class SpongeSchematicWriter implements ClipboardWriter {
}
}
};
System.out.println("TODO Optimize biome write");
BlockVector3 min = clipboard.getMinimumPoint();
int width = clipboard.getRegion().getWidth();
int length = clipboard.getRegion().getLength();

View File

@ -0,0 +1,23 @@
package com.sk89q.worldedit.function.visitor;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.regions.CuboidRegion;
import com.sk89q.worldedit.regions.Region;
import java.util.Iterator;
public enum Order {
YZX() {
@Override
public Iterator<BlockVector3> create(Region region) {
if (!(region instanceof CuboidRegion)) {
region = new CuboidRegion(region.getMinimumPoint(), region.getMaximumPoint());
}
return ((CuboidRegion) region).iterator_old();
}
}
;
public abstract Iterator<BlockVector3> create(Region region);
}