Fixes for anvil queue

This commit is contained in:
Jesse Boyd 2016-08-21 01:07:20 +10:00
parent 3618007052
commit b32b633248
7 changed files with 116 additions and 42 deletions

View File

@ -175,9 +175,7 @@ public class FaweBukkit implements IFawe, Listener {
}
try {
return plugin.getQueue(world);
} catch (Throwable ignore) {
ignore.printStackTrace();
}
} catch (Throwable ignore) {}
// Disable incompatible settings
Settings.QUEUE.PARALLEL_THREADS = 1; // BukkitAPI placer is too slow to parallel thread at the chunk level
Settings.HISTORY.COMBINE_STAGES = false; // Performing a chunk copy (if possible) wouldn't be faster using the BukkitAPI

View File

@ -64,6 +64,15 @@ public class DefaultFaweQueueMap implements IFaweQueueMap {
return chunk;
}
@Override
public FaweChunk getCachedFaweChunk(int cx, int cz) {
if (cx == lastX && cz == lastZ) {
return lastWrappedChunk;
}
long pair = MathMan.pairInt(cx, cz);
return this.blocks.get(pair);
}
@Override
public void add(FaweChunk chunk) {
long pair = MathMan.pairInt(chunk.getX(), chunk.getZ());

View File

@ -12,6 +12,8 @@ public interface IFaweQueueMap {
FaweChunk getFaweChunk(int cx, int cz);
FaweChunk getCachedFaweChunk(int cx, int cz);
void add(FaweChunk chunk);
void clear();

View File

@ -371,7 +371,8 @@ public class MCAChunk extends FaweChunk<Void> {
int layer = y >> 4;
byte[] idsLayer = ids[layer];
if (idsLayer == null) {
return;
idsLayer = this.ids[layer] = new byte[4096];
this.data[layer] = new byte[2048];
}
int j = FaweCache.CACHE_J[y][z & 15][x & 15];
idsLayer[j] = (byte) id;

View File

@ -95,6 +95,9 @@ public class MCAFile {
int i = ((cx & 31) << 2) + ((cz & 31) << 7);
int offset = (((locations[i] & 0xFF) << 16) + ((locations[i + 1] & 0xFF) << 8) + ((locations[i+ 2] & 0xFF))) << 12;
int size = (locations[i + 3] & 0xFF) << 12;
if (offset == 0) {
return null;
}
NBTInputStream nis = getChunkIS(offset);
MCAChunk chunk = new MCAChunk(nis, queue, cx, cz, size);
int pair = MathMan.pair((short) (cx & 31), (short) (cz & 31));
@ -180,6 +183,9 @@ public class MCAFile {
}
public void streamChunk(int offset, RunnableVal<NBTStreamer> addReaders) throws IOException {
if (offset == 0) {
return;
}
NBTInputStream is = getChunkIS(offset);
NBTStreamer ns = new NBTStreamer(is);
addReaders.run(ns);
@ -200,6 +206,9 @@ public class MCAFile {
}
private NBTStreamer getChunkReader(int offset) throws Exception {
if (offset == 0) {
return null;
}
return new NBTStreamer(getChunkIS(offset));
}
@ -307,9 +316,6 @@ public class MCAFile {
}
} else {
newBytes = getChunkBytes(cx, cz);
if (newBytes == null) {
System.out.println("This shouldn't be null?");
}
}
}
if (newBytes == null) {

View File

@ -13,15 +13,19 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, MCAChunk, MCAChunk, MCAChunk> {
public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, FaweChunk, FaweChunk, FaweChunk> {
private FaweQueue parent;
private NMSMappedFaweQueue parentNMS;
private final boolean hasSky;
private final File saveFolder;
public MCAQueue(FaweQueue parent) {
super(parent.getWorldName(), new MCAQueueMap());
this.parent = parent;
if (parent instanceof NMSMappedFaweQueue) {
parentNMS = (NMSMappedFaweQueue) parent;
}
((MCAQueueMap) getFaweQueueMap()).setParentQueue(parent);
hasSky = parent.hasSky();
saveFolder = parent.getSaveFolder();
@ -60,7 +64,7 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, MCAChunk, MCAChunk,
}
@Override
public CharFaweChunk getPrevious(CharFaweChunk fs, MCAChunk sections, Map<?, ?> tiles, Collection<?>[] entities, Set<UUID> createdEntities, boolean all) throws Exception {
public CharFaweChunk getPrevious(CharFaweChunk fs, FaweChunk sections, Map<?, ?> tiles, Collection<?>[] entities, Set<UUID> createdEntities, boolean all) throws Exception {
throw new UnsupportedOperationException("Not supported");
}
@ -75,27 +79,55 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, MCAChunk, MCAChunk,
}
@Override
public void setFullbright(MCAChunk sections) {
sections.setFullbright();
public void setFullbright(FaweChunk sections) {
if (sections.getClass() == MCAChunk.class) {
((MCAChunk) sections).setFullbright();
} else if (parentNMS != null) {
int cx = sections.getX();
int cz = sections.getZ();
parentNMS.ensureChunkLoaded(cx, cz);
Object parentSections = parentNMS.getCachedSections(parentNMS.getWorld(), cx, cz);
if (parentSections != null) {
parentNMS.setFullbright(sections);
}
}
}
@Override
public boolean removeLighting(MCAChunk sections, RelightMode mode, boolean hasSky) {
public boolean removeLighting(FaweChunk sections, RelightMode mode, boolean hasSky) {
if (mode != RelightMode.NONE) {
sections.removeLight();
if (sections.getClass() == MCAChunk.class) {
((MCAChunk) sections).removeLight();
} else if (parentNMS != null) {
int cx = sections.getX();
int cz = sections.getZ();
parentNMS.ensureChunkLoaded(cx, cz);
Object parentSections = parentNMS.getCachedSections(parentNMS.getWorld(), cx, cz);
if (parentSections != null) {
parentNMS.removeLighting(sections, mode, hasSky);
}
}
return true;
}
return false;
}
@Override
public void setSkyLight(MCAChunk chars, int x, int y, int z, int value) {
chars.setSkyLight(x, y, z, value);
public void setSkyLight(FaweChunk sections, int x, int y, int z, int value) {
if (sections.getClass() == MCAChunk.class) {
((MCAChunk) sections).setSkyLight(x, y, z, value);
} else if (parentNMS != null) {
parentNMS.setSkyLight(x, y, z, value);
}
}
@Override
public void setBlockLight(MCAChunk chars, int x, int y, int z, int value) {
chars.setBlockLight(x, y, z, value);
public void setBlockLight(FaweChunk sections, int x, int y, int z, int value) {
if (sections.getClass() == MCAChunk.class) {
((MCAChunk) sections).setBlockLight(x, y, z, value);
} else if (parentNMS != null) {
parentNMS.setBlockLight(x, y, z, value);
}
}
@Override
@ -106,8 +138,8 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, MCAChunk, MCAChunk,
}
@Override
public CompoundTag getTileEntity(MCAChunk mcaChunk, int x, int y, int z) {
return mcaChunk.getTile(x, y, z);
public CompoundTag getTileEntity(FaweChunk sections, int x, int y, int z) {
return sections.getTile(x, y, z);
}
@Override
@ -141,26 +173,39 @@ public class MCAQueue extends NMSMappedFaweQueue<FaweQueue, MCAChunk, MCAChunk,
}
@Override
public MCAChunk getCachedSection(MCAChunk mcaChunk, int cy) {
if (mcaChunk.doesSectionExist(cy)) {
return mcaChunk;
public FaweChunk getCachedSection(FaweChunk sections, int cy) {
if (sections.getClass() == MCAChunk.class) {
if (((MCAChunk) sections).doesSectionExist(cy)) {
return sections;
}
return null;
} else if (parentNMS != null) {
return sections;
}
return null;
}
@Override
public int getCombinedId4Data(MCAChunk chars, int x, int y, int z) {
return chars.getBlockCombinedId(x, y, z);
public int getCombinedId4Data(FaweChunk sections, int x, int y, int z) {
return sections.getBlockCombinedId(x, y, z);
}
@Override
public int getSkyLight(MCAChunk sections, int x, int y, int z) {
return sections.getSkyLight(x, y, z);
public int getSkyLight(FaweChunk sections, int x, int y, int z) {
if (sections.getClass() == MCAChunk.class) {
return ((MCAChunk) sections).getSkyLight(x, y, z);
} else {
return parentNMS.getSkyLight(x, y, z);
}
}
@Override
public int getEmmittedLight(MCAChunk sections, int x, int y, int z) {
return sections.getBlockLight(x, y, z);
public int getEmmittedLight(FaweChunk sections, int x, int y, int z) {
if (sections.getClass() == MCAChunk.class) {
return ((MCAChunk) sections).getBlockLight(x, y, z);
} else {
return parentNMS.getEmmittedLight(x, y, z);
}
}
@Override

View File

@ -42,9 +42,6 @@ public class MCAQueueMap implements IFaweQueueMap {
long pair = MathMan.pairInt(lastFileX = mcaX, lastFileZ = mcaZ);
lastFile = mcaFileMap.get(pair);
if (lastFile == null) {
if (mcaFileMap.containsKey(pair)) {
return null;
}
try {
lastFile = new MCAFile(queue, lastFileX, lastFileZ);
} catch (Exception e) {
@ -89,29 +86,45 @@ public class MCAQueueMap implements IFaweQueueMap {
}
lastX = cx;
lastZ = cz;
try {
MCAFile mcaFile = getMCAFile(cx, cz);
if (mcaFile == null) {
return lastChunk = null;
}
lastChunk = mcaFile.getChunk(cx, cz);
if (isHybridQueue) {
lastChunk = ((MappedFaweQueue) queue).getFaweQueueMap().getCachedFaweChunk(cx, cz);
if (lastChunk != null) {
return lastChunk;
}
} catch (Throwable ignore) {
ignore.printStackTrace();
}
if (!isHybridQueue || !queue.isChunkLoaded(cx, cz)) {
try {
MCAFile mcaFile = getMCAFile(cx, cz);
if (mcaFile != null) {
lastChunk = mcaFile.getChunk(cx, cz);
if (lastChunk != null) {
return lastChunk;
}
}
} catch (Throwable ignore) {
ignore.printStackTrace();
}
}
if (isHybridQueue) { // Use parent queue for in use chunks
lastChunk = ((MappedFaweQueue)queue).getFaweQueueMap().getFaweChunk(cx, cz);
if (lastChunk == null) {
System.out.println("Will work this out later.");
}
return lastChunk;
}
nullChunk.setLoc(queue, lastX, lastZ);
return lastChunk = nullChunk;
}
@Override
public FaweChunk getCachedFaweChunk(int cx, int cz) {
int mcaX = cx >> 5;
int mcaZ = cz >> 5;
long pair = MathMan.pairInt(mcaX, mcaZ);
MCAFile file = mcaFileMap.get(pair);
if (file != null) {
return file.getCachedChunk(cx, cz);
}
return null;
}
@Override
public void add(FaweChunk chunk) {
throw new UnsupportedOperationException("Not supported");