Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-03 01:50:07 +01:00
Merge pull request #587 from aurorasmiles/fixnms
improve performance of chunk updates for 1.16.2
Dieser Commit ist enthalten in:
Commit
aa93f192c6
@ -13,8 +13,6 @@ import com.sk89q.worldedit.math.BlockVector3;
|
||||
import com.sk89q.worldedit.world.block.BlockState;
|
||||
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import it.unimi.dsi.fastutil.shorts.ShortArraySet;
|
||||
import it.unimi.dsi.fastutil.shorts.ShortSet;
|
||||
import net.jpountz.util.UnsafeUtils;
|
||||
import net.minecraft.server.v1_16_R2.Block;
|
||||
import net.minecraft.server.v1_16_R2.Chunk;
|
||||
@ -39,7 +37,6 @@ import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
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.HashMap;
|
||||
@ -73,7 +70,8 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
|
||||
|
||||
private static final Field fieldLock;
|
||||
|
||||
private static final Constructor shortArraySetConstructor;
|
||||
private static final short[] FULL_CHUNK_SECTION_CHANGE_SET;
|
||||
private static final Constructor shortArraySetFromShortArrayConstructor;
|
||||
|
||||
static {
|
||||
try {
|
||||
@ -115,7 +113,23 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
|
||||
throw new Error("data type scale not a power of two");
|
||||
CHUNKSECTION_SHIFT = 31 - Integer.numberOfLeadingZeros(scale);
|
||||
|
||||
shortArraySetConstructor = Class.forName(new String(new char[]{'i','t','.','u','n','i','m','i','.','d','s','i','.','f','a','s','t','u','t','i','l','.','s','h','o','r','t','s','.','S','h','o','r','t','A','r','r','a','y','S','e','t'})).getConstructor();
|
||||
Class clsShortArraySet;
|
||||
try { //paper
|
||||
clsShortArraySet = Class.forName(new String(new char[]{'i', 't', '.', 'u', 'n', 'i', 'm', 'i', '.', 'd', 's', 'i', '.', 'f', 'a', 's', 't', 'u', 't', 'i', 'l', '.', 's', 'h', 'o', 'r', 't', 's', '.', 'S', 'h', 'o', 'r', 't', 'A', 'r', 'r', 'a', 'y', 'S', 'e', 't'}));
|
||||
} catch (Throwable t) {// still using spigot boooo
|
||||
clsShortArraySet = Class.forName(new String(new char[]{'o', 'r', 'g', '.', 'b', 'u', 'k', 'k', 'i', 't', '.', 'c', 'r', 'a', 'f', 't', 'b', 'u', 'k', 'k', 'i', 't', '.', 'l', 'i', 'b', 's', '.', 'i', 't', '.', 'u', 'n', 'i', 'm', 'i', '.', 'd', 's', 'i', '.', 'f', 'a', 's', 't', 'u', 't', 'i', 'l', '.', 's', 'h', 'o', 'r', 't', 's', '.', 'S', 'h', 'o', 'r', 't', 'A', 'r', 'r', 'a', 'y', 'S', 'e', 't'}));
|
||||
}
|
||||
shortArraySetFromShortArrayConstructor = clsShortArraySet.getConstructor(short[].class);
|
||||
|
||||
FULL_CHUNK_SECTION_CHANGE_SET = new short[16 * 16 * 16];
|
||||
for (int x = 0; x < 16; x++) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
short i = (short) ((x << 8) | (z << 4) | y);
|
||||
FULL_CHUNK_SECTION_CHANGE_SET[i] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
throw e;
|
||||
} catch (Throwable rethrow) {
|
||||
@ -195,11 +209,7 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
|
||||
nmsWorld.getChunkProvider().playerChunkMap.a(playerChunk);
|
||||
}
|
||||
for (int i = 0; i < 16; i++) {
|
||||
if (dirtyblocks[i] == null) dirtyblocks[i] = (Set<Short>) shortArraySetConstructor.newInstance();
|
||||
for (int x = 0; x < 16; x++)
|
||||
for (int y = 0; y < 16; y++)
|
||||
for (int z = 0; z < 16; z++)
|
||||
dirtyblocks[i].add((short) ((x << 8) | (z << 4) | (y)));
|
||||
dirtyblocks[i] = getFullChunkSliceChangeSet();
|
||||
}
|
||||
|
||||
fieldDirtyBlocks.set(playerChunk, dirtyblocks);
|
||||
@ -213,13 +223,8 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
|
||||
p.playerConnection.sendPacket(packet);
|
||||
});
|
||||
}
|
||||
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
@ -320,4 +325,14 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
|
||||
fieldTickingBlockCount.setShort(section, (short) tickingBlockCount);
|
||||
fieldNonEmptyBlockCount.setShort(section, (short) nonEmptyBlockCount);
|
||||
}
|
||||
|
||||
private static Set<Short> getFullChunkSliceChangeSet() {
|
||||
try {
|
||||
short[] data = new short[16 * 16 * 16];
|
||||
System.arraycopy(FULL_CHUNK_SECTION_CHANGE_SET, 0, data, 0, FULL_CHUNK_SECTION_CHANGE_SET.length);
|
||||
return (Set<Short>) shortArraySetFromShortArrayConstructor.newInstance((Object) data);
|
||||
} catch (Throwable e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren