Paper/patches/server/0806-Freeze-Tick-Lock-API.patch
Spottedleaf 01a13871de
Rewrite chunk system (#8177)
Patch documentation to come

Issues with the old system that are fixed now:
- World generation does not scale with cpu cores effectively.
- Relies on the main thread for scheduling and maintaining chunk state, dropping chunk load/generate rates at lower tps.
- Unreliable prioritisation of chunk gen/load calls that block the main thread.
- Shutdown logic is utterly unreliable, as it has to wait for all chunks to unload - is it guaranteed that the chunk system is in a state on shutdown that it can reliably do this? Watchdog shutdown also typically failed due to thread checks, which is now resolved.
- Saving of data is not unified (i.e can save chunk data without saving entity data, poses problems for desync if shutdown is really abnormal.
- Entities are not loaded with chunks. This caused quite a bit of headache for Chunk#getEntities API, but now the new chunk system loads entities with chunks so that they are ready whenever the chunk loads in. Effectively brings the behavior back to 1.16 era, but still storing entities in their own separate regionfiles.

The above list is not complete. The patch documentation will complete it.

New chunk system hard relies on starlight and dataconverter, and most importantly the new concurrent utilities in ConcurrentUtil.

Some of the old async chunk i/o interface (i.e the old file io thread reroutes _some_ calls to the new file io thread) is kept for plugin compat reasons. It will be removed in the next major version of minecraft.

The old legacy chunk system patches have been moved to the removed folder in case we need them again.
2022-09-26 01:02:51 -07:00

83 lines
4.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Owen1212055 <23108066+Owen1212055@users.noreply.github.com>
Date: Sun, 26 Dec 2021 20:27:43 -0500
Subject: [PATCH] Freeze Tick Lock API
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 8958c95105394601ca91b4318b598e45ced9e706..fd536e670036a365f6d0e8c168ef4b5fdf597615 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -397,6 +397,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
private org.bukkit.util.Vector origin;
@javax.annotation.Nullable
private UUID originWorld;
+ public boolean freezeLocked = false; // Paper - Freeze Tick Lock API
public void setOrigin(@javax.annotation.Nonnull Location location) {
this.origin = location.toVector();
@@ -826,7 +827,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
this.setRemainingFireTicks(this.remainingFireTicks - 1);
}
- if (this.getTicksFrozen() > 0) {
+ if (this.getTicksFrozen() > 0 && !freezeLocked) { // Paper - Freeze Tick Lock API
this.setTicksFrozen(0);
this.level.levelEvent((Player) null, 1009, this.blockPosition, 1);
}
@@ -2262,6 +2263,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
if (fromNetherPortal) {
nbt.putBoolean("Paper.FromNetherPortal", true);
}
+ if (freezeLocked) {
+ nbt.putBoolean("Paper.FreezeLock", true);
+ }
// Paper end
return nbt;
} catch (Throwable throwable) {
@@ -2426,6 +2430,9 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
if (spawnReason == null) {
spawnReason = org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.DEFAULT;
}
+ if (nbt.contains("Paper.FreezeLock")) {
+ freezeLocked = nbt.getBoolean("Paper.FreezeLock");
+ }
// Paper end
} catch (Throwable throwable) {
diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java
index d6ecdeab398d7bfde3d760ada0374245f03014b3..73d931489c76f2effe71362a46a69087a1a09463 100644
--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java
+++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java
@@ -3376,7 +3376,7 @@ public abstract class LivingEntity extends Entity {
boolean flag1 = this.getType().is(EntityTypeTags.FREEZE_HURTS_EXTRA_TYPES);
int i;
- if (!this.level.isClientSide && !this.isDeadOrDying()) {
+ if (!this.level.isClientSide && !this.isDeadOrDying() && !freezeLocked) { // Paper - Freeze Tick Lock API
i = this.getTicksFrozen();
if (this.isInPowderSnow && this.canFreeze()) {
this.setTicksFrozen(Math.min(this.getTicksRequiredToFreeze(), i + 1));
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
index 385368d0c6a13f9b1b907bcc48d1fb2a845262ef..c4ffccddce33cf461d9b04ccbb90026544f16b7d 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java
@@ -644,6 +644,17 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity {
return this.getHandle().isFullyFrozen();
}
+ // Paper Start - Freeze Tick Lock API
+ @Override
+ public boolean isFreezeTickingLocked() {
+ return this.entity.freezeLocked;
+ }
+
+ @Override
+ public void lockFreezeTicks(boolean locked) {
+ this.entity.freezeLocked = locked;
+ }
+ // Paper end - Freeze Tick Lock API
@Override
public void remove() {
this.entity.discard();