Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-11-15 04:20:04 +01:00
c5a10665b8
Spigot still maintains some partial implementation of "tick skipping", a practice in which the MinecraftServer.currentTick field is updated not by an increment of one per actual tick, but instead set to System.currentTimeMillis() / 50. This behaviour means that the tracked tick may "skip" a tick value in case a previous tick took more than the expected 50ms. To compensate for this in important paths, spigot/craftbukkit implements "wall-time". Instead of incrementing/decrementing ticks on block entities/entities by one for each call to their tick() method, they instead increment/decrement important values, like an ItemEntity's age or pickupDelay, by the difference of `currentTick - lastTick`, where `lastTick` is the value of `currentTick` during the last tick() call. These "fixes" however do not play nicely with minecraft's simulation distance as entities/block entities implementing the above behaviour would "catch up" their values when moving from a non-ticking chunk to a ticking one as their `lastTick` value remains stuck on the last tick in a ticking chunk and hence lead to a large "catch up" once ticked again. Paper completely removes the "tick skipping" behaviour (See patch "Further-improve-server-tick-loop"), making the above precautions completely unnecessary, which also rids paper of the previous described incompatibility with non-ticking chunks.
66 Zeilen
3.2 KiB
Diff
66 Zeilen
3.2 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/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
index d08b01fef9928f2239c8663cf90219dc7acad58c..af706146a26ede6b9f5a39c8deb490ff25334ae6 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
|
@@ -458,6 +458,53 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
|
public com.destroystokyo.paper.util.VersionFetcher getVersionFetcher() {
|
|
return new com.destroystokyo.paper.PaperVersionFetcher();
|
|
}
|
|
+
|
|
+ @Override
|
|
+ public byte[] serializeItem(ItemStack item) {
|
|
+ Preconditions.checkNotNull(item, "null cannot be serialized");
|
|
+ Preconditions.checkArgument(item.getType() != Material.AIR, "air cannot be serialized");
|
|
+
|
|
+ return serializeNbtToBytes((net.minecraft.nbt.CompoundTag) (item instanceof CraftItemStack ? ((CraftItemStack) item).handle : CraftItemStack.asNMSCopy(item)).save(MinecraftServer.getServer().registryAccess()));
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public ItemStack deserializeItem(byte[] data) {
|
|
+ Preconditions.checkNotNull(data, "null cannot be deserialized");
|
|
+ Preconditions.checkArgument(data.length > 0, "cannot deserialize nothing");
|
|
+
|
|
+ net.minecraft.nbt.CompoundTag compound = deserializeNbtFromBytes(data);
|
|
+ final int dataVersion = compound.getInt("DataVersion");
|
|
+ compound = (net.minecraft.nbt.CompoundTag) MinecraftServer.getServer().fixerUpper.update(References.ITEM_STACK, new Dynamic<>(NbtOps.INSTANCE, compound), dataVersion, this.getDataVersion()).getValue();
|
|
+ return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.parse(MinecraftServer.getServer().registryAccess(), compound).orElseThrow());
|
|
+ }
|
|
+
|
|
+ private byte[] serializeNbtToBytes(CompoundTag compound) {
|
|
+ compound.putInt("DataVersion", getDataVersion());
|
|
+ java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
|
|
+ try {
|
|
+ net.minecraft.nbt.NbtIo.writeCompressed(
|
|
+ compound,
|
|
+ outputStream
|
|
+ );
|
|
+ } catch (IOException ex) {
|
|
+ throw new RuntimeException(ex);
|
|
+ }
|
|
+ return outputStream.toByteArray();
|
|
+ }
|
|
+
|
|
+ private net.minecraft.nbt.CompoundTag deserializeNbtFromBytes(byte[] data) {
|
|
+ net.minecraft.nbt.CompoundTag compound;
|
|
+ try {
|
|
+ compound = net.minecraft.nbt.NbtIo.readCompressed(
|
|
+ new java.io.ByteArrayInputStream(data), net.minecraft.nbt.NbtAccounter.unlimitedHeap()
|
|
+ );
|
|
+ } catch (IOException ex) {
|
|
+ throw new RuntimeException(ex);
|
|
+ }
|
|
+ int dataVersion = compound.getInt("DataVersion");
|
|
+ Preconditions.checkArgument(dataVersion <= getDataVersion(), "Newer version! Server downgrades are not supported!");
|
|
+ return compound;
|
|
+ }
|
|
// Paper end
|
|
|
|
@Override
|