mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-23 17:57:38 +00:00
Merge pull request #587 from aurorasmiles/fixnms
improve performance of chunk updates for 1.16.2
This commit is contained 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.BlockState;
|
||||||
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
import com.sk89q.worldedit.world.block.BlockTypesCache;
|
||||||
import io.papermc.lib.PaperLib;
|
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.jpountz.util.UnsafeUtils;
|
||||||
import net.minecraft.server.v1_16_R2.Block;
|
import net.minecraft.server.v1_16_R2.Block;
|
||||||
import net.minecraft.server.v1_16_R2.Chunk;
|
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.invoke.MethodHandles;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
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 Field fieldLock;
|
||||||
|
|
||||||
private static final Constructor shortArraySetConstructor;
|
private static final short[] FULL_CHUNK_SECTION_CHANGE_SET;
|
||||||
|
private static final Constructor shortArraySetFromShortArrayConstructor;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
try {
|
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");
|
throw new Error("data type scale not a power of two");
|
||||||
CHUNKSECTION_SHIFT = 31 - Integer.numberOfLeadingZeros(scale);
|
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) {
|
} catch (RuntimeException e) {
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Throwable rethrow) {
|
} catch (Throwable rethrow) {
|
||||||
@ -195,11 +209,7 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
|
|||||||
nmsWorld.getChunkProvider().playerChunkMap.a(playerChunk);
|
nmsWorld.getChunkProvider().playerChunkMap.a(playerChunk);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 16; i++) {
|
for (int i = 0; i < 16; i++) {
|
||||||
if (dirtyblocks[i] == null) dirtyblocks[i] = (Set<Short>) shortArraySetConstructor.newInstance();
|
dirtyblocks[i] = getFullChunkSliceChangeSet();
|
||||||
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)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fieldDirtyBlocks.set(playerChunk, dirtyblocks);
|
fieldDirtyBlocks.set(playerChunk, dirtyblocks);
|
||||||
@ -213,13 +223,8 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
|
|||||||
p.playerConnection.sendPacket(packet);
|
p.playerConnection.sendPacket(packet);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IllegalAccessException e) {
|
} catch (IllegalAccessException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (InvocationTargetException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (InstantiationException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@ -320,4 +325,14 @@ public final class BukkitAdapter_1_16_2 extends NMSAdapter {
|
|||||||
fieldTickingBlockCount.setShort(section, (short) tickingBlockCount);
|
fieldTickingBlockCount.setShort(section, (short) tickingBlockCount);
|
||||||
fieldNonEmptyBlockCount.setShort(section, (short) nonEmptyBlockCount);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user