Fixes #694
Fixes #691
Closes #693
This commit is contained in:
Jesse Boyd 2017-08-18 00:35:15 +10:00
parent e9db802e2d
commit 891f50a7c7
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 49 additions and 24 deletions

View File

@ -25,6 +25,7 @@ import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
@ -90,6 +91,7 @@ public class BukkitQueue_1_12 extends BukkitQueue_0<net.minecraft.server.v1_12_R
protected static Field fieldSize;
protected static Method getEntitySlices;
protected static Method methodTileEntityLoad;
protected static Method methodSaveChunk;
protected static Field fieldTickingBlockCount;
protected static Field fieldNonEmptyBlockCount;
protected static Field fieldSection;
@ -102,6 +104,7 @@ public class BukkitQueue_1_12 extends BukkitQueue_0<net.minecraft.server.v1_12_R
protected static Field fieldGenLayer2;
protected static Field fieldChunks;
protected static Field fieldChunkLoader;
private static Field fieldSave;
protected static MutableGenLayer genLayer;
protected static ChunkSection emptySection;
@ -133,6 +136,8 @@ public class BukkitQueue_1_12 extends BukkitQueue_0<net.minecraft.server.v1_12_R
fieldGenLayer1.setAccessible(true);
fieldGenLayer2.setAccessible(true);
fieldSave = ReflectionUtils.setAccessible(net.minecraft.server.v1_12_R1.Chunk.class.getDeclaredField("s"));
fieldChunks = ChunkProviderServer.class.getDeclaredField("chunks");
fieldChunkLoader = ChunkProviderServer.class.getDeclaredField("chunkLoader");
fieldChunks.setAccessible(true);
@ -166,6 +171,9 @@ public class BukkitQueue_1_12 extends BukkitQueue_0<net.minecraft.server.v1_12_R
} catch (Throwable e) {
e.printStackTrace();
}
try {
methodSaveChunk = ChunkProviderServer.class.getDeclaredMethod("saveChunk", net.minecraft.server.v1_12_R1.Chunk.class, boolean.class);
} catch (NoSuchMethodError | NoSuchMethodException ignore) { }
}
public BukkitQueue_1_12(final com.sk89q.worldedit.world.World world) {
@ -178,6 +186,25 @@ public class BukkitQueue_1_12 extends BukkitQueue_0<net.minecraft.server.v1_12_R
getImpWorld();
}
private boolean save(net.minecraft.server.v1_12_R1.Chunk chunk, ChunkProviderServer cps) {
try {
if (!(boolean) fieldSave.get(chunk)) return false;
if (methodSaveChunk != null) {
methodSaveChunk.invoke(cps, chunk, false);
} else {
cps.saveChunk(chunk);
}
cps.saveChunkNOP(chunk);
return true;
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return false;
}
@Override
public ChunkSection[] getSections(net.minecraft.server.v1_12_R1.Chunk chunk) {
return chunk.getSections();
@ -287,11 +314,7 @@ public class BukkitQueue_1_12 extends BukkitQueue_0<net.minecraft.server.v1_12_R
boolean isIn = allowed.isInChunk(chunk.locX, chunk.locZ);
if (isIn) {
if (!load) {
if (chunk.a(false)) {
mustSave = true;
provider.saveChunk(chunk);
provider.saveChunkNOP(chunk);
}
mustSave |= save(chunk, provider);
continue;
}
iter.remove();

View File

@ -176,16 +176,17 @@ public class CorruptSchematicStreamer {
}
}
});
match("Add", new CorruptSchematicStreamer.CorruptReader() {
match("AddBlocks", new CorruptSchematicStreamer.CorruptReader() {
@Override
public void run(DataInputStream in) throws IOException {
int length = in.readInt();
int expected = volume.get();
if (expected == 0) {
volume.set(length * 2);
expected = length * 2;
volume.set(expected);
}
setupClipboard();
if (expected != length) {
if (expected == length * 2) {
for (int i = 0; i < length; i++) {
int value = in.read();
int first = value & 0x0F;
@ -202,7 +203,7 @@ public class CorruptSchematicStreamer {
}
}
});
match("Blocks", new CorruptSchematicStreamer.CorruptReader() {
match("Biomes", new CorruptSchematicStreamer.CorruptReader() {
@Override
public void run(DataInputStream in) throws IOException {
int length = in.readInt();

View File

@ -52,23 +52,20 @@ public class CatenaryBrush implements Brush, ResettableTool {
return true;
}
public Vector getVertex(Vector pos1, Vector pos2, double lenPercent) {
double len = pos1.distance(pos2) * lenPercent;
public static Vector getVertex(Vector pos1, Vector pos2, double lenPercent) {
if (lenPercent <= 1) return Vector.getMidpoint(pos1, pos2);
double curveLen = pos1.distance(pos2) * lenPercent;
double dy = pos2.getY() - pos1.getY();
double dx = pos2.getX() - pos1.getX();
double dz = pos2.getZ() - pos1.getZ();
double h = Math.sqrt(dx * dx + dz * dz);
double t = Math.sqrt(len * len - dy * dy) / h;
double z = 0.001;
for (; Math.sinh(z) < t*z; z += 0.001); // close enough
double a = (h / 2) / z;
double p = (h - a * Math.log((len + dy) / (len - dy)))/2;
double q = (dy - len * Math.cosh(z) / Math.sinh(z)) / 2;
double y = a * 1 + q;
return pos1.add(pos2.subtract(pos1).multiply(p / h).add(0, y, 0)).round();
double dh = Math.sqrt(dx * dx + dz * dz);
double g = Math.sqrt(curveLen * curveLen - dy * dy) / 2;
double a = 0.00001;
for (;g < a * Math.sinh(dh/(2 * a)); a *= 1.00001);
double vertX = (dh-a*Math.log((curveLen + dy)/(curveLen - dy)))/2.0;
double z = (dh/2)/a;
double oY = (dy - curveLen * (Math.cosh(z) / Math.sinh(z))) / 2;
double vertY = a * 1 + oY;
return pos1.add(pos2.subtract(pos1).multiply(vertX / dh).add(0, vertY, 0)).round();
}
}

View File

@ -169,6 +169,10 @@ public class Sniper {
FaweQueue baseQueue = FaweAPI.createQueue(fp.getLocation().world, false);
RegionWrapper[] mask = WEManager.IMP.getMask(fp);
if (mask.length == 0) {
BBC.NO_REGION.send(fp);
return false;
}
MaskedFaweQueue maskQueue = new MaskedFaweQueue(baseQueue, mask);
com.sk89q.worldedit.world.World worldEditWorld = fp.getWorld();
FaweChangeSet changeSet = FaweChangeSet.getDefaultChangeSet(worldEditWorld, fp.getUUID());