614a664bd3
Mark chunks that are blocking main thread for world generation as urgent Implements a general priority system so that chunks that are sorted in the generator queues can prioritize certain chunks over another. Urgent chunks will jump to the front of the line, ensuring that a sync chunk load on an ungenerated chunk does not lag the server for a long period of time if the servers generator queues are filled with lots of chunks already. This massively reduces the lag spikes from sync chunk gens. Then we further prioritize loading order so nearby chunks have higher priority than distant chunks, reducing the pressure a high no tick view distance holds on you. Chunks in front of the player have higher priority, to help with fast traveling players keep up with their movement. This commit also improves single core cpu scenarios in that we will now automatically disable Async Chunks as well as Minecrafts thread pool. It is never recommended to use async chunks on a single CPU as context switching will be slower than just running it all on main. This also bumps the number of server worker threads by default too. Mojang does not utilize the workers in an effecient manner, resulting in them using barely any sustained CPU. So give it more workers so more chunks can be processed concurrently This change also improves urgent chunk loading, so players flying into unloaded chunks will hurt a little bit less (but still hurt) Ping #3395 #3363 (Not marking as closed, we need to make prevent moving work)
102 lines
5.5 KiB
Diff
102 lines
5.5 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Mariell Hoversholm <proximyst@proximyst.com>
|
|
Date: Thu, 30 Apr 2020 16:56:54 +0200
|
|
Subject: [PATCH] Add Raw Byte ItemStack Serialization
|
|
|
|
Serializes using NBT which is safer for server data migrations than bukkits format.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/DataConverterRegistry.java b/src/main/java/net/minecraft/server/DataConverterRegistry.java
|
|
index 77c77973bb335cc89dae31bef2bbbcd4adc1d14b..d957d5fc2dc724cdda553e3a67ffe65e1e41c304 100644
|
|
--- a/src/main/java/net/minecraft/server/DataConverterRegistry.java
|
|
+++ b/src/main/java/net/minecraft/server/DataConverterRegistry.java
|
|
@@ -22,6 +22,7 @@ public class DataConverterRegistry {
|
|
return datafixerbuilder.build(SystemUtils.e());
|
|
}
|
|
|
|
+ public static DataFixer getDataFixer() { return a(); } // Paper - OBFHELPER
|
|
public static DataFixer a() {
|
|
return DataConverterRegistry.c;
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/ItemStack.java b/src/main/java/net/minecraft/server/ItemStack.java
|
|
index d6e43313bf0c678cf78fe77de2f8f4b6f819e3f4..ea60880c6f15b1a39579896d78cf641563621aa4 100644
|
|
--- a/src/main/java/net/minecraft/server/ItemStack.java
|
|
+++ b/src/main/java/net/minecraft/server/ItemStack.java
|
|
@@ -140,6 +140,7 @@ public final class ItemStack {
|
|
this.checkEmpty();
|
|
}
|
|
|
|
+ public static ItemStack fromCompound(NBTTagCompound nbttagcompound) { return a(nbttagcompound); } // Paper - OBFHELPER
|
|
public static ItemStack a(NBTTagCompound nbttagcompound) {
|
|
try {
|
|
return new ItemStack(nbttagcompound);
|
|
diff --git a/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java b/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
|
|
index 2322c0c8c5aacebb6317eab8ce4245554f6d9d55..3e6f878cdbbf5ebfa7fb390745ead135c1c4dee8 100644
|
|
--- a/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
|
|
+++ b/src/main/java/net/minecraft/server/NBTCompressedStreamTools.java
|
|
@@ -14,6 +14,7 @@ import java.util.zip.GZIPOutputStream;
|
|
|
|
public class NBTCompressedStreamTools {
|
|
|
|
+ public static NBTTagCompound readNBT(InputStream inputstream) throws IOException { return a(inputstream); } // Paper - OBFHELPER
|
|
public static NBTTagCompound a(InputStream inputstream) throws IOException {
|
|
DataInputStream datainputstream = new DataInputStream(new BufferedInputStream(new GZIPInputStream(inputstream)));
|
|
Throwable throwable = null;
|
|
@@ -43,6 +44,7 @@ public class NBTCompressedStreamTools {
|
|
return nbttagcompound;
|
|
}
|
|
|
|
+ public static void writeNBT(NBTTagCompound nbttagcompound, OutputStream outputstream) throws IOException { a(nbttagcompound, outputstream); } // Paper - OBFHELPER
|
|
public static void a(NBTTagCompound nbttagcompound, OutputStream outputstream) throws IOException {
|
|
DataOutputStream dataoutputstream = new DataOutputStream(new BufferedOutputStream(new GZIPOutputStream(outputstream)));
|
|
Throwable throwable = null;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index 770375ed4207920e71d2d0799c611c4b3cdbe6f7..549ba4d8068763f41c2307a9c88f0b3f304b17e9 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -313,6 +313,46 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
public boolean isSupportedApiVersion(String apiVersion) {
|
|
return apiVersion != null && SUPPORTED_API.contains(apiVersion);
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public byte[] serializeItem(ItemStack item) {
|
|
+ Preconditions.checkNotNull(item, "null cannot be serialized");
|
|
+ Preconditions.checkArgument(item.getType() != Material.AIR, "air cannot be serialized");
|
|
+
|
|
+ java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
|
|
+ NBTTagCompound compound = (item instanceof CraftItemStack ? ((CraftItemStack) item).getHandle() : CraftItemStack.asNMSCopy(item)).save(new NBTTagCompound());
|
|
+ compound.setInt("DataVersion", getDataVersion());
|
|
+ try {
|
|
+ net.minecraft.server.NBTCompressedStreamTools.writeNBT(
|
|
+ compound,
|
|
+ outputStream
|
|
+ );
|
|
+ } catch (IOException ex) {
|
|
+ throw new RuntimeException(ex);
|
|
+ }
|
|
+
|
|
+ return outputStream.toByteArray();
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ItemStack deserializeItem(byte[] data) {
|
|
+ Preconditions.checkNotNull(data, "null cannot be deserialized");
|
|
+ Preconditions.checkArgument(data.length > 0, "cannot deserialize nothing");
|
|
+
|
|
+ try {
|
|
+ NBTTagCompound compound = net.minecraft.server.NBTCompressedStreamTools.readNBT(
|
|
+ new java.io.ByteArrayInputStream(data)
|
|
+ );
|
|
+ int dataVersion = compound.getInt("DataVersion");
|
|
+
|
|
+ Preconditions.checkArgument(dataVersion <= getDataVersion(), "Newer version! Server downgrades are not supported!");
|
|
+ Dynamic<NBTBase> converted = DataConverterRegistry.getDataFixer().update(DataConverterTypes.ITEM_STACK, new Dynamic<NBTBase>(DynamicOpsNBT.a, compound), -1, getDataVersion());
|
|
+ return CraftItemStack.asCraftMirror(net.minecraft.server.ItemStack.fromCompound((NBTTagCompound) converted.getValue()));
|
|
+ } catch (IOException ex) {
|
|
+ com.destroystokyo.paper.util.SneakyThrow.sneaky(ex);
|
|
+ throw new RuntimeException();
|
|
+ }
|
|
+ }
|
|
// Paper end
|
|
|
|
/**
|