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

Paper Changes:
PaperMC/Paper@056268e [ci skip] Correct javadoc for Weapon Component (#13096)
PaperMC/Paper@a0ea729 Fix minimum tick time reporting and off thread reading
PaperMC/Paper@ba2fb8c Update spark-paper dependency version (#13171)
PaperMC/Paper@ce983d7 Misc fixes to tick reporting (#13174)
PaperMC/Paper@9d95cd5 Use BUILD_STARTED_AT instead of Instant.now() for build timestamp (#13175)
PaperMC/Paper@610f1d2 Update fill-gradle to v1.0.9
PaperMC/Paper@ffcb7b2 Update Parchment (#13177)
PaperMC/Paper@c33a9ce Fix incorrect variable use in Entity#startRiding
PaperMC/Paper@c710b66 Add MapPalette.getNearestColor (#13104)
PaperMC/Paper@b57d641 Expose isReplaceable on BlockData (#13180)
PaperMC/Paper@af1823d Reduce impact of tick time calculations (#13188)
PaperMC/Paper@89ca94a [ci skip] Rebuild patches
PaperMC/Paper@e5cc256 [ci skip] Update CONTRIBUTING.md for Gradle and Windows Docs (#13190)
PaperMC/Paper@ab99393 Fix charged creeper explosions not dropping mob skulls (#13167)
2025-10-16 13:58:47 +01:00

157 lines
9.6 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 2082b7506a403ed6815076cbd0d3b7eecd7225a0..82dac4fbaf3572391dad61356ba5351b725194ff 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,
@@ -1919,6 +1920,7 @@ public final class CollisionUtil {
final BlockPos.MutableBlockPos mutablePos = new BlockPos.MutableBlockPos();
final CollisionContext collisionShape = new LazyEntityCollisionContext(entity);
final boolean useEntityCollisionShape = LazyEntityCollisionContext.useEntityCollisionShape(world, entity);
+ final long gameTime = world.getGameTime(); // Sakura - load chunks on movement
// special cases:
if (minBlockY > maxBlockY) {
@@ -1936,6 +1938,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 +1957,16 @@ public final class CollisionUtil {
continue;
}
+ // Sakura start - load chunks on movement
+ if (addTicket && chunk.refreshMovementTicket(gameTime) && chunkSource instanceof net.minecraft.server.level.ServerChunkCache chunkCache) {
+ final net.minecraft.world.level.ChunkPos chunkPos = new net.minecraft.world.level.ChunkPos(currChunkX, currChunkZ);
+ chunkCache.addTicketAtLevel(
+ net.minecraft.server.level.TicketType.ENTITY_MOVEMENT,
+ chunkPos,
+ net.minecraft.server.level.ChunkLevel.ENTITY_TICKING_LEVEL
+ );
+ }
+ // 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 25ea504fa93f78b43237e1c79f8b5685a2aa6d7c..5395b3e0491f197ffea3910d3f172dcdef881758 100644
--- a/net/minecraft/server/level/TicketType.java
+++ b/net/minecraft/server/level/TicketType.java
@@ -62,6 +62,7 @@ public final class TicketType<T> implements ca.spottedleaf.moonrise.patches.chun
public static final TicketType PLUGIN_TICKET = register("plugin_ticket", NO_TIMEOUT, FLAG_LOADING | FLAG_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", NO_TIMEOUT, FLAG_LOADING | FLAG_SIMULATION); // Paper
public static final TicketType CHUNK_LOAD = register("chunk_load", NO_TIMEOUT, FLAG_LOADING); // Paper - moonrise
+ public static final TicketType ENTITY_MOVEMENT = register("entity_movement", 200L, FLAG_LOADING | FLAG_SIMULATION); // Sakura - load chunks on movement
private static TicketType register(String name, long timeout, int flags) {
return Registry.register(BuiltInRegistries.TICKET_TYPE, name, new TicketType(timeout, flags));
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index e9c536a11e403e1c979e01d21bfd3d167e439903..e8f262dd220e07a8b70e931274535f3c474d24a4 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -539,6 +539,19 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
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<?> type, Level level) {
this.type = type;
@@ -1540,7 +1553,7 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
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);
@@ -5242,13 +5255,14 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
@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 8150b567c05d2c8e87f4b65d616d5c0c01bc2e19..d1f806f950707091d02788117c1f8cffe5b2de04 100644
--- a/net/minecraft/world/entity/item/FallingBlockEntity.java
+++ b/net/minecraft/world/entity/item/FallingBlockEntity.java
@@ -80,6 +80,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 71071899443fdb02beb0321f271430c732178e26..dd4e2419892a8879106eaaccbf406bec12bbd017 100644
--- a/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/net/minecraft/world/entity/item/PrimedTnt.java
@@ -64,6 +64,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
super(type, 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 98b7e1e3b8592824c69a9647a82621755526c71a..6c997cb573a489f9ca0b7ffe278de5f66e667aa8 100644
--- a/net/minecraft/world/level/chunk/ChunkAccess.java
+++ b/net/minecraft/world/level/chunk/ChunkAccess.java
@@ -137,6 +137,15 @@ 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 refreshMovementTicket(final long gameTime) {
+ final boolean refresh = gameTime - this.lastMovementLoadTicket >= 100;
+ this.lastMovementLoadTicket = gameTime;
+ return refresh;
+ }
+ // Sakura end - load chunks on movement
public ChunkAccess(
ChunkPos chunkPos,