9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2026-01-03 22:16:38 +00:00
Files
SakuraMC/sakura-server/minecraft-patches/features/0002-Load-Chunks-on-Movement.patch
Samsuik 240a18f319 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@3af5e77 Add Player#give (#11995)
PaperMC/Paper@7e21cb8 fix PlayerChangedMainHandEvent javadoc (#12020)
PaperMC/Paper@5a34bf0 Correctly retrun true for empty input shapes in EntityGetter#isUnobstructed
PaperMC/Paper@a392d47 Make Watchdog thread extend TickThread
PaperMC/Paper@1004374 Add further information to thread check errors
PaperMC/Paper@e2f0efd Remove nms.Entity#isChunkLoaded
PaperMC/Paper@54b2e9d Add buffer to CraftWorld#warnUnsafeChunk
PaperMC/Paper@d4a9578 Experimental annotation changes (#12028)
PaperMC/Paper@5bcfb12 Fix activation range config and water animal status (#12047)
PaperMC/Paper@e0711af Deprecate UnsafeValues#getSpawnEggLayerColor (#12041)
PaperMC/Paper@8927091 Do not record movement for vehicles/players unaffected by blocks
PaperMC/Paper@5395ae3 Fix composter block setting bukkit owner twice (#12058)
2025-02-03 08:58:45 +00:00

149 lines
8.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Sat, 11 Sep 2021 19:19:41 +0100
Subject: [PATCH] Load Chunks on Movement
diff --git a/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java b/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
index e04bd54744335fb5398c6e4f7ce8b981f35bfb7d..651a45b795818bd7b1364b95c52570fd99dd35e4 100644
--- a/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
+++ b/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
@@ -1885,6 +1885,7 @@ public final class CollisionUtil {
public static final int COLLISION_FLAG_COLLIDE_WITH_UNLOADED_CHUNKS = 1 << 1;
public static final int COLLISION_FLAG_CHECK_BORDER = 1 << 2;
public static final int COLLISION_FLAG_CHECK_ONLY = 1 << 3;
+ public static final int COLLISION_FLAG_ADD_TICKET = 1 << 4; // Sakura - load chunks on movement
public static boolean getCollisionsForBlocksOrWorldBorder(final Level world, final Entity entity, final AABB aabb,
final List<VoxelShape> intoVoxel, final List<AABB> intoAABB,
@@ -1936,6 +1937,7 @@ public final class CollisionUtil {
final int maxChunkZ = maxBlockZ >> 4;
final boolean loadChunks = (collisionFlags & COLLISION_FLAG_LOAD_CHUNKS) != 0;
+ final boolean addTicket = (collisionFlags & COLLISION_FLAG_ADD_TICKET) != 0; // Sakura - load chunks on movement
final ChunkSource chunkSource = world.getChunkSource();
for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
@@ -1954,6 +1956,13 @@ public final class CollisionUtil {
continue;
}
+ // Sakura start - load chunks on movement
+ if (addTicket && chunk.movementTicketNeedsUpdate() && chunkSource instanceof net.minecraft.server.level.ServerChunkCache chunkCache) {
+ final long chunkKey = ca.spottedleaf.moonrise.common.util.CoordinateUtils.getChunkKey(currChunkX, currChunkZ);
+ chunkCache.chunkMap.getDistanceManager().moonrise$getChunkHolderManager().addTicketAtLevel(net.minecraft.server.level.TicketType.ENTITY_MOVEMENT, currChunkX, currChunkZ, 31, chunkKey);
+ chunk.updatedMovementTicket();
+ }
+ // Sakura end - load chunks on movement
final LevelChunkSection[] sections = chunk.getSections();
// bound y
diff --git a/net/minecraft/server/level/TicketType.java b/net/minecraft/server/level/TicketType.java
index 8f12a4df5d63ecd11e6e615d910b6e3f6dde5f3c..56beffa0c5cdb0d6a4836a0ee496bd638432b143 100644
--- a/net/minecraft/server/level/TicketType.java
+++ b/net/minecraft/server/level/TicketType.java
@@ -21,6 +21,7 @@ public class TicketType<T> {
public static final TicketType<Unit> PLUGIN = TicketType.create("plugin", (a, b) -> 0); // CraftBukkit
public static final TicketType<org.bukkit.plugin.Plugin> PLUGIN_TICKET = TicketType.create("plugin_ticket", (plugin1, plugin2) -> plugin1.getClass().getName().compareTo(plugin2.getClass().getName())); // CraftBukkit
public static final TicketType<Integer> POST_TELEPORT = TicketType.create("post_teleport", Integer::compare, 5); // Paper - post teleport ticket type
+ public static final TicketType<Long> ENTITY_MOVEMENT = TicketType.create("entity_movement", Long::compareTo, 10*20); // Sakura - load chunks on movement
public static <T> TicketType<T> create(String name, Comparator<T> comparator) {
return new TicketType<>(name, comparator, 0L);
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index d0107d42212ddff92b5637205417e98ac76dfd69..2208f8c2176451eb65eeba05d47703f58e5d3e29 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -526,6 +526,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
public boolean isPrimedTNT;
public boolean isFallingBlock;
// Sakura end - client visibility settings
+ // Sakura start - load chunks on movement
+ protected boolean loadChunks = false;
+
+ private int getExtraCollisionFlags() {
+ int flags = 0;
+
+ if (this.loadChunks) {
+ flags |= ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_LOAD_CHUNKS;
+ flags |= ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_ADD_TICKET;
+ }
+
+ return flags;
+ }
+ // Sakura end - load chunks on movement
public Entity(EntityType<?> entityType, Level level) {
this.type = entityType;
@@ -1465,7 +1479,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.getCollisionsForBlocksOrWorldBorder(
this.level, (Entity)(Object)this, initialCollisionBox, potentialCollisionsVoxel, potentialCollisionsBB,
- ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER, null
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER | this.getExtraCollisionFlags(), null // Sakura - load chunks on movement
);
potentialCollisionsBB.addAll(entityAABBs);
final Vec3 collided = ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.performCollisions(movement, currentBox, potentialCollisionsVoxel, potentialCollisionsBB);
@@ -4957,13 +4971,14 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@Override
public boolean shouldBeSaved() {
return (this.removalReason == null || this.removalReason.shouldSave())
+ && !this.loadChunks // Sakura - load chunks on movement; this is used to check if the chunk the entity is in can be unloaded
&& !this.isPassenger()
&& (!this.isVehicle() || !((ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity)this).moonrise$hasAnyPlayerPassengers()); // Paper - rewrite chunk system
}
@Override
public boolean isAlwaysTicking() {
- return false;
+ return this.loadChunks; // Sakura - load chunks on movement; always tick in unloaded & lazy chunks
}
public boolean mayInteract(ServerLevel level, BlockPos pos) {
diff --git a/net/minecraft/world/entity/item/FallingBlockEntity.java b/net/minecraft/world/entity/item/FallingBlockEntity.java
index bf5f3db9d62c063e8b880b831edb2f3a43d7005a..fcb7b396db2605146be99f2b14da6806cdaa0f44 100644
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -74,6 +74,7 @@ public class FallingBlockEntity extends Entity {
super(entityType, level);
this.heightParity = level.sakuraConfig().cannons.mechanics.fallingBlockParity; // Sakura - configure cannon mechanics
this.isFallingBlock = true; // Sakura - client visibility settings
+ this.loadChunks = level.sakuraConfig().cannons.loadChunks; // Sakura - load chunks on movement
}
public FallingBlockEntity(Level level, double x, double y, double z, BlockState state) {
diff --git a/net/minecraft/world/entity/item/PrimedTnt.java b/net/minecraft/world/entity/item/PrimedTnt.java
index c5b9ebbd159284ae2650b0698e06011104d4b70f..3c74cb8d4b71fcfa600742c21d6ad8e3942a2ab7 100644
--- a/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
@@ -62,6 +62,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
super(entityType, level);
this.blocksBuilding = true;
this.isPrimedTNT = true; // Sakura - client visibility settings
+ this.loadChunks = level.sakuraConfig().cannons.loadChunks; // Sakura - load chunks on movement
}
public PrimedTnt(Level level, double x, double y, double z, @Nullable LivingEntity owner) {
diff --git a/net/minecraft/world/level/chunk/ChunkAccess.java b/net/minecraft/world/level/chunk/ChunkAccess.java
index 6d565b52552534ce9cacfc35ad1bf4adcb69eac3..9b42bd1afb9a6c1729cb56e3c232f46112ba57d3 100644
--- a/net/minecraft/world/level/chunk/ChunkAccess.java
+++ b/net/minecraft/world/level/chunk/ChunkAccess.java
@@ -138,6 +138,17 @@ public abstract class ChunkAccess implements BiomeManager.NoiseBiomeSource, Ligh
private final int minSection;
private final int maxSection;
// Paper end - get block chunk optimisation
+ // Sakura start - load chunks on movement
+ private long lastMovementLoadTicket = 0;
+
+ public final boolean movementTicketNeedsUpdate() {
+ return net.minecraft.server.MinecraftServer.currentTick - this.lastMovementLoadTicket >= 100;
+ }
+
+ public final void updatedMovementTicket() {
+ this.lastMovementLoadTicket = net.minecraft.server.MinecraftServer.currentTick;
+ }
+ // Sakura end - load chunks on movement
public ChunkAccess(
ChunkPos chunkPos,