mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-07-04 03:56:41 +00:00
Remove hardcoding of world limits (#1199)
* Remove hardcoding of world limits - seems to be working fine without the datapack for world height changing - particular attention should be given to LocalBlockVectorSet and MathMan changes * update adapters * Override getMinY in various classes and ensure selections have a world attached to them * no message * Address comments - Fix for lighting mode 1 * A few more changes * Fix LocalBlockVectorSet * Fix range statement * Various fixes/comment-addressing - There's not much point in having a different file name now for history. We've broken it before... - Fix history read/write - Fix range on for loops in CharBlocks * undo bad CharBlocks change * Fix history y level * Fix biome history * Fix lighting * Fix /up * Make regen fail not because of these changes * Fixes for y < 0 * Fix isEmpty where only the uppermost chunksection is edited * Fix javadocs/FAWE annotations * Better explain why BiomeMath is removed * If history task throws an error, it should only be caught and printed if not completing now. * Min|max world heights for new patterns * Load biomes from NMS instead of bukkit (#1200) * Update adapters * Update adapters * Don't initialise BlockTypes when biomes aren't set up yet so all BiomeTypes.BIOME are no longer null thanks. * Address some comments. * rename layer -> sectionIndex to imply inclusivity * Javadoctored. Co-authored-by: NotMyFault <mc.cache@web.de> Co-authored-by: Hannes Greule <SirYwell@users.noreply.github.com>
This commit is contained in:
@ -102,6 +102,7 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
||||
nbttFile = new File(folder, index + ".nbtt");
|
||||
entfFile = new File(folder, index + ".entf");
|
||||
enttFile = new File(folder, index + ".entt");
|
||||
//Switch file ending due to new (sort-of) format. (Added e for Extended height)
|
||||
bdFile = new File(folder, index + ".bd");
|
||||
bioFile = new File(folder, index + ".bio");
|
||||
}
|
||||
@ -431,6 +432,8 @@ public class DiskStorageHistory extends FaweStreamChangeSet {
|
||||
final FaweInputStream gis = MainUtil.getCompressedIS(fis);
|
||||
// skip mode
|
||||
gis.skipFully(1);
|
||||
// skip version
|
||||
gis.skipFully(1);
|
||||
// origin
|
||||
ox = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + gis.read());
|
||||
oz = ((gis.read() << 24) + (gis.read() << 16) + (gis.read() << 8) + gis.read());
|
||||
|
@ -157,7 +157,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
|
||||
addEntityCreate(tag);
|
||||
}
|
||||
}
|
||||
for (int layer = 0; layer < 16; layer++) {
|
||||
for (int layer = get.getMinSectionIndex(); layer <= get.getMaxSectionIndex(); layer++) {
|
||||
if (!set.hasSection(layer)) {
|
||||
continue;
|
||||
}
|
||||
@ -172,6 +172,7 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
|
||||
char[] blocksSet;
|
||||
System.arraycopy(set.load(layer), 0, (blocksSet = new char[4096]), 0, 4096);
|
||||
|
||||
// Account for negative layers
|
||||
int by = layer << 4;
|
||||
for (int y = 0, index = 0; y < 16; y++) {
|
||||
int yy = y + by;
|
||||
@ -195,14 +196,21 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
|
||||
|
||||
BiomeType[] biomes = set.getBiomes();
|
||||
if (biomes != null) {
|
||||
for (int y = 0, index = 0; y < 64; y++) {
|
||||
for (int z = 0; z < 4; z++) {
|
||||
for (int x = 0; x < 4; x++, index++) {
|
||||
BiomeType newBiome = biomes[index];
|
||||
if (newBiome != null) {
|
||||
BiomeType oldBiome = get.getBiomeType(x, y, z);
|
||||
if (oldBiome != newBiome) {
|
||||
addBiomeChange(bx + (x << 2), y << 2, bz + (z << 2), oldBiome, newBiome);
|
||||
int index = 0;
|
||||
for (int layer = get.getMinSectionIndex(); layer <= get.getMaxSectionIndex(); layer++) {
|
||||
if (!set.hasBiomes(layer)) {
|
||||
continue;
|
||||
}
|
||||
int yy = layer << 4;
|
||||
for (int y = 0; y < 4; y++) {
|
||||
for (int z = 0; z < 4; z++) {
|
||||
for (int x = 0; x < 4; x++, index++) {
|
||||
BiomeType newBiome = biomes[index];
|
||||
if (newBiome != null) {
|
||||
BiomeType oldBiome = get.getBiomeType(x, y, z);
|
||||
if (oldBiome != newBiome) {
|
||||
addBiomeChange(bx + (x << 2), yy + (y << 2), bz + (z << 2), oldBiome, newBiome);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -341,11 +349,17 @@ public abstract class AbstractChangeSet implements ChangeSet, IBatchProcessor {
|
||||
return addWriteTask(writeTask, Fawe.isMainThread());
|
||||
}
|
||||
|
||||
public Future<?> addWriteTask(Runnable writeTask, boolean completeNow) {
|
||||
public Future<?> addWriteTask(final Runnable writeTask, final boolean completeNow) {
|
||||
AbstractChangeSet.this.waitingCombined.incrementAndGet();
|
||||
Runnable wrappedTask = () -> {
|
||||
try {
|
||||
writeTask.run();
|
||||
} catch (Throwable t) {
|
||||
if (completeNow) {
|
||||
throw t;
|
||||
} else {
|
||||
t.printStackTrace();
|
||||
}
|
||||
} finally {
|
||||
if (AbstractChangeSet.this.waitingCombined.decrementAndGet() <= 0) {
|
||||
synchronized (AbstractChangeSet.this.waitingAsync) {
|
||||
|
@ -28,11 +28,16 @@ import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
/**
|
||||
* FAWE stream ChangeSet offering support for extended-height worlds
|
||||
*/
|
||||
public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
|
||||
public static final int HEADER_SIZE = 9;
|
||||
private static final int version = 1;
|
||||
private int mode;
|
||||
private final int compression;
|
||||
private final int minY;
|
||||
|
||||
protected FaweStreamIdDelegate idDel;
|
||||
protected FaweStreamPositionDelegate posDel;
|
||||
@ -44,6 +49,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
public FaweStreamChangeSet(World world, int compression, boolean storeRedo, boolean smallLoc) {
|
||||
super(world);
|
||||
this.compression = compression;
|
||||
this.minY = world.getMinY();
|
||||
init(storeRedo, smallLoc);
|
||||
}
|
||||
|
||||
@ -139,6 +145,10 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
|
||||
@Override
|
||||
public void write(OutputStream out, int x, int y, int z) throws IOException {
|
||||
if (y < 0 || y > 255) {
|
||||
throw new UnsupportedOperationException("y cannot be outside range 0-255 for " +
|
||||
"small-edits=true");
|
||||
}
|
||||
int rx = -lx + (lx = x);
|
||||
int ry = -ly + (ly = y);
|
||||
int rz = -lz + (lz = z);
|
||||
@ -174,7 +184,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
};
|
||||
} else {
|
||||
posDel = new FaweStreamPositionDelegate() {
|
||||
final byte[] buffer = new byte[5];
|
||||
final byte[] buffer = new byte[6];
|
||||
int lx;
|
||||
int ly;
|
||||
int lz;
|
||||
@ -188,7 +198,8 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
stream.write(((rx) >> 8) & 0xff);
|
||||
stream.write((rz) & 0xff);
|
||||
stream.write(((rz) >> 8) & 0xff);
|
||||
stream.write((byte) ry);
|
||||
stream.write((ry) & 0xff);
|
||||
stream.write(((ry) >> 8) & 0xff);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -199,7 +210,7 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
|
||||
@Override
|
||||
public int readY(FaweInputStream is) throws IOException {
|
||||
return (ly = (ly + (buffer[4]))) & 0xFF;
|
||||
return ly = (ly + (buffer[4] & 0xFF) + (buffer[5] << 8));
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -212,6 +223,8 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
|
||||
public void writeHeader(OutputStream os, int x, int y, int z) throws IOException {
|
||||
os.write(mode);
|
||||
// Allows for version detection of history in case of changes to format.
|
||||
os.write(version);
|
||||
setOrigin(x, z);
|
||||
os.write((byte) (x >> 24));
|
||||
os.write((byte) (x >> 16));
|
||||
@ -227,6 +240,10 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
public void readHeader(InputStream is) throws IOException {
|
||||
// skip mode
|
||||
int mode = is.read();
|
||||
int version = is.read();
|
||||
if (version != FaweStreamChangeSet.version) {
|
||||
throw new UnsupportedOperationException(String.format("Version %s history not supported!", version));
|
||||
}
|
||||
// origin
|
||||
int x = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + is.read());
|
||||
int z = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + is.read());
|
||||
@ -290,10 +307,6 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
public abstract NBTInputStream getTileRemoveIS() throws IOException;
|
||||
|
||||
protected int blockSize;
|
||||
public int entityCreateSize;
|
||||
public int entityRemoveSize;
|
||||
public int tileCreateSize;
|
||||
public int tileRemoveSize;
|
||||
|
||||
private int originX;
|
||||
private int originZ;
|
||||
@ -325,9 +338,12 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addBiomeChange(int x, int y, int z, BiomeType from, BiomeType to) {
|
||||
public void addBiomeChange(int bx, int by, int bz, BiomeType from, BiomeType to) {
|
||||
blockSize++;
|
||||
try {
|
||||
int x = bx >> 2;
|
||||
int y = by >> 2;
|
||||
int z = bz >> 2;
|
||||
FaweOutputStream os = getBiomeOS();
|
||||
os.write((byte) (x >> 24));
|
||||
os.write((byte) (x >> 16));
|
||||
@ -337,7 +353,9 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
os.write((byte) (z >> 16));
|
||||
os.write((byte) (z >> 8));
|
||||
os.write((byte) (z));
|
||||
os.write((byte) (y));
|
||||
// only need to store biomes in the 4x4x4 chunks so only need one byte for y still (signed byte -128 -> 127)
|
||||
// means -512 -> 508. Add 128 to avoid negative value casting.
|
||||
os.write((byte) (y + 128));
|
||||
os.writeVarInt(from.getInternalId());
|
||||
os.writeVarInt(to.getInternalId());
|
||||
} catch (Throwable e) {
|
||||
@ -465,9 +483,9 @@ public abstract class FaweStreamChangeSet extends AbstractChangeSet {
|
||||
try {
|
||||
int int1 = is.read();
|
||||
if (int1 != -1) {
|
||||
int x = ((int1 << 24) + (is.read() << 16) + (is.read() << 8) + is.read());
|
||||
int z = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + is.read());
|
||||
int y = is.read();
|
||||
int x = ((int1 << 24) + (is.read() << 16) + (is.read() << 8) + is.read()) << 2;
|
||||
int z = ((is.read() << 24) + (is.read() << 16) + (is.read() << 8) + is.read()) << 2;
|
||||
int y = (is.read() - 128) << 2;
|
||||
int from = is.readVarInt();
|
||||
int to = is.readVarInt();
|
||||
change.setBiome(x, y, z, from, to);
|
||||
|
Reference in New Issue
Block a user