Convert nether portals

This commit is contained in:
Jesse Boyd 2017-10-08 16:20:17 +11:00
parent f5d40ea1bf
commit 911f613f2f
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
3 changed files with 54 additions and 2 deletions

View File

@ -97,4 +97,8 @@ public class DelegateMCAFilter<T> extends MCAFilter<T> {
public DelegateMCAFilter(MCAFilter<T> filter) {
this.filter = filter;
}
public MCAFilter<T> getFilter() {
return filter;
}
}

View File

@ -6,21 +6,28 @@ import com.boydti.fawe.jnbt.anvil.MCAFile;
import com.boydti.fawe.jnbt.anvil.MCAFilterCounter;
import com.boydti.fawe.jnbt.anvil.MutableMCABackedBaseBlock;
import com.boydti.fawe.object.clipboard.ClipboardRemapper;
import com.boydti.fawe.object.collection.BlockVectorSet;
import com.boydti.fawe.object.number.MutableLong;
import com.boydti.fawe.util.ReflectionUtils;
import com.sk89q.jnbt.ByteTag;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.jnbt.IntTag;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.blocks.BaseBlock;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class RemapFilter extends MCAFilterCounter {
private final ClipboardRemapper remapper;
private final ClipboardRemapper.RemapPlatform from;
private boolean skipRemap;
private List<CompoundTag> portals = Collections.synchronizedList(new ArrayList<>());
private BlockVectorSet pLocs = new BlockVectorSet();
private int dimension;
public RemapFilter(ClipboardRemapper remapper) {
this.remapper = remapper;
@ -45,6 +52,14 @@ public class RemapFilter extends MCAFilterCounter {
return super.applyChunk(chunk, cache);
}
public List<CompoundTag> getPortals() {
return portals;
}
public void setDimension(int dimension) {
this.dimension = dimension;
}
@Override
public void applyBlock(int x, int y, int z, BaseBlock block, MutableLong cache) {
int id = block.getId();
@ -69,6 +84,20 @@ public class RemapFilter extends MCAFilterCounter {
case PC: {
int newLight = 0;
switch (id) {
case 90:
pLocs.add(x, y, z);
if (pLocs.contains(x, y - 1, z) || pLocs.contains(x - 1, y, z) || pLocs.contains(x, y, z - 1)) break;
Map<String, Tag> tag = new HashMap<>();
tag.put("Span", new ByteTag((byte) 1));
tag.put("TpX", new IntTag(x));
tag.put("TpY", new IntTag(y));
tag.put("TpZ", new IntTag(z));
tag.put("DimId", new IntTag(dimension));
int data = block.getData();
tag.put("Xa", new ByteTag((byte) ((data == 2) ? 0 : 1)));
tag.put("Za", new ByteTag((byte) ((data == 2) ? 1 : 0)));
portals.add(new CompoundTag(tag));
break;
case 29:
case 33:
Map<String, Object> map = new HashMap<>();

View File

@ -40,12 +40,14 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;
@ -69,6 +71,8 @@ public class MCAFile2LevelDB extends MapConverter {
private boolean remap;
private ConcurrentLinkedQueue<CompoundTag> portals = new ConcurrentLinkedQueue<>();
private ConcurrentHashMap<Thread, WriteBatch> batches = new ConcurrentHashMap<Thread, WriteBatch>() {
@Override
@ -137,8 +141,9 @@ public class MCAFile2LevelDB extends MapConverter {
}
}
public MCAFilter<MutableLong> toFilter(final int dimension) {
public DelegateMCAFilter<MutableLong> toFilter(final int dimension) {
RemapFilter filter = new RemapFilter(ClipboardRemapper.RemapPlatform.PC, ClipboardRemapper.RemapPlatform.PE);
filter.setDimension(dimension);
DelegateMCAFilter<MutableLong> delegate = new DelegateMCAFilter<MutableLong>(filter) {
@Override
public void finishFile(MCAFile file, MutableLong cache) {
@ -170,17 +175,31 @@ public class MCAFile2LevelDB extends MapConverter {
}
}
List<CompoundTag> portals = new ArrayList<>();
String[] dimDirs = {"region", "DIM-1/region", "DIM1/region"};
for (int dim = 0; dim < 3; dim++) {
File source = new File(folderFrom, dimDirs[dim]);
if (source.exists()) {
MCAFilter filter = toFilter(dim);
DelegateMCAFilter filter = toFilter(dim);
MCAQueue queue = new MCAQueue(null, source, true);
MCAFilter result = queue.filterWorld(filter);
portals.addAll(((RemapFilter) filter.getFilter()).getPortals());
}
}
// Portals
if (!portals.isEmpty()) {
CompoundTag portalData = new CompoundTag(Collections.singletonMap("PortalRecords", new ListTag(CompoundTag.class, portals)));
CompoundTag portalsTag = new CompoundTag(Collections.singletonMap("data", portalData));
try {
db.put("portals".getBytes(), write(Arrays.asList(portalsTag)));
} catch (IOException e) {
e.printStackTrace();
}
}
try {
flush(false);
} catch (IOException e) {