9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-19 14:59:30 +00:00
Files
SakuraMC/sakura-server/minecraft-patches/features/0003-Load-Chunks-on-Movement.patch
Samsuik dc3793b1c6 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@4eda045 Backport fix for MC-296337 (Fixes #12617) (#12619)
PaperMC/Paper@7ebc94c Add Registry#getTagValues (#12603)
PaperMC/Paper@e87320d Fix UOE when using generateTree with pale oak (#12616)
PaperMC/Paper@94f2903 Do not blow up accessing unregistered memories from API (Fixes #12618) (#12639)
PaperMC/Paper@03efecf Do not fire PlayerDropItemEvent for /give command
PaperMC/Paper@3527ccd feat: expose updateDemand and restock on Villager (#12608)
PaperMC/Paper@320f25c fix sponge-absorb deleting chest content (#12647)
PaperMC/Paper@95565e0 Add missing attribute serialization updater
PaperMC/Paper@519e422 Fix infinite loop in RegionFile IO
PaperMC/Paper@ba7fb23 Finish moving over to Holderable (#12646)
PaperMC/Paper@39203a6 [ci skip] Publish PR API and dev bundles (#12672)
PaperMC/Paper@a1b3058 Provide env environment variable and copy spigots sys prop for overriding default repository
2025-06-23 10:47:22 +01:00

149 lines
9.4 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 a97a2a8492f3858e3b622d26768b4d819c9b47a7..44aaaa87d63a2a2287f89feaa431ca0e80da3dab 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 f91eed907ffc61a4092aabaa0a1b061c2c453673..0159517f425491ce490d982a09e40efd4ce7868c 100644
--- a/net/minecraft/server/level/TicketType.java
+++ b/net/minecraft/server/level/TicketType.java
@@ -51,6 +51,7 @@ public final class TicketType<T> implements ca.spottedleaf.moonrise.patches.chun
public static final TicketType PLUGIN_TICKET = register("plugin_ticket", TicketType.NO_TIMEOUT, false, TicketType.TicketUse.LOADING_AND_SIMULATION); static { ((TicketType<org.bukkit.plugin.Plugin>)PLUGIN_TICKET).moonrise$setIdentifierComparator((org.bukkit.plugin.Plugin p1, org.bukkit.plugin.Plugin p2) -> p1.getName().compareTo(p2.getName())); } // Paper // Paper - rewrite chunk system
public static final TicketType FUTURE_AWAIT = register("future_await", TicketType.NO_TIMEOUT, false, TicketType.TicketUse.LOADING_AND_SIMULATION); // Paper
public static final TicketType CHUNK_LOAD = register("chunk_load", TicketType.NO_TIMEOUT, false, TicketType.TicketUse.LOADING); // Paper - moonrise
+ public static final TicketType ENTITY_MOVEMENT = register("entity_movement", 200L, false, TicketUse.LOADING_AND_SIMULATION); // Sakura - load chunks on movement
public static TicketType register(String name, long timeout, boolean persist, TicketType.TicketUse use) {
return Registry.register(BuiltInRegistries.TICKET_TYPE, name, new TicketType(timeout, persist, use));
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 92fd4bb2b2473a0630cd5edf8d301dc7c60b2998..ccd0497ec6587086e6d2f8da0f8d0ae606449d37 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -520,6 +520,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;
@@ -1491,7 +1505,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);
@@ -4952,13 +4966,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 6660e6c78303db5585a06d6836b035d0e8582922..b6a2da9d6db99f107fa8d9703b77515cf112a604 100644
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -77,6 +77,7 @@ public class FallingBlockEntity extends Entity {
this.dropItem = level.sakuraConfig().cannons.sand.dropItems; // Sakura - configure falling blocks dropping items
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 7e3d7d5b47557e57bf661aa8d3eefcb416cb408b..55dbe5baf2df0111d03a43d32208798d7ec670a1 100644
--- a/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
@@ -65,6 +65,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 3b7f0d5fe40bdda65ab859a0c22bf0d369dc0f01..dd50e4867b16127355243acdb9ba647a4b50baae 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,