mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 08:19:26 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@9aea240 Properly lookup plugin classes when looked up by spark PaperMC/Paper@7e91a2c Update the bundled spark version PaperMC/Paper@3a47518 Deprecate more Timings things for removal (#11126) PaperMC/Paper@aa36ae6 Fix EntityUnleashEvent cancellation on distance cause (#11131) PaperMC/Paper@73a863b Fix horse inventories indices (#11139) PaperMC/Paper@5512af7 [ci skip] remove timings from issue templates (#11127) PaperMC/Paper@5a5035b Fix a couple of ItemMeta related NPEs (#11149) PaperMC/Paper@e1462a9 Bump MCUtils#asyncExecutor core size PaperMC/Paper@645a677 Make max interaction range configurable (#11164) PaperMC/Paper@66165f7 Fix PickupStatus getting reset (#11154) PaperMC/Paper@dcbd99d Fix Owen's typos (#11179) PaperMC/Paper@f82bea6 Add argument for FinePosition to brig API (#11094) PaperMC/Paper@694b120 Remove Entity tracker field PaperMC/Paper@f774787 Copy missed changes to chunk system from Folia PaperMC/Paper@50bdfc3 Null check tracker in Entity#resendPossiblyDesyncedEntityData PaperMC/Paper@3234b20 Do not allow chunk unloading outside of the regular tick loop PaperMC/Paper@0246a9d Add mob bucket items to item id to entity map in DataConverter PaperMC/Paper@438863c Shutdown L4J cordially if the server stops before it's even started (#11172) PaperMC/Paper@100d75a Don't entirely die just because a plugin jar was bad PaperMC/Paper@227544c Move TickThread changes from Moonrise patch to MCUtils PaperMC/Paper@67d414a Allow plugin aliases to override vanilla commands (#11186) PaperMC/Paper@58c7ea3 Preserve command node when re-registering modern commands through old API (#11184) PaperMC/Paper@0a1be9a Make loadChunksForMoveAsync use new chunk system load calls PaperMC/Paper@df3b654 ConcurrentUtil: Fix concurrent long map resize chain pull function PaperMC/Paper@5a5c3a4 Remove chunk unload trace debug PaperMC/Paper@7e44684 Fix wrong assumption about locale being null in the login phase (#11204) PaperMC/Paper@042f15f [ci skip] chore: fix incorrect commit hash in PR builds (#11198) PaperMC/Paper@4e6a2a1 Check for block type in SculkSensorBlock#canActivate
149 lines
9.5 KiB
Diff
149 lines
9.5 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/src/main/java/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java b/src/main/java/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
|
|
index 748ab4d637ce463272bae4fdbab6842a27385126..ea6e252053b8910141aacd5bb82108d6abf3fb96 100644
|
|
--- a/src/main/java/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
|
|
+++ b/src/main/java/ca/spottedleaf/moonrise/patches/collisions/CollisionUtil.java
|
|
@@ -1574,6 +1574,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 net.minecraft.world.level.Level world, final net.minecraft.world.entity.Entity entity, final net.minecraft.world.phys.AABB aabb,
|
|
final java.util.List<net.minecraft.world.phys.shapes.VoxelShape> intoVoxel, final java.util.List<net.minecraft.world.phys.AABB> intoAABB,
|
|
@@ -1624,6 +1625,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
|
|
final net.minecraft.world.level.chunk.ChunkSource chunkSource = world.getChunkSource();
|
|
|
|
for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
|
|
@@ -1642,6 +1644,14 @@ 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().getChunkHolderManager().addTicketAtLevel(net.minecraft.server.level.TicketType.ENTITY_MOVEMENT, currChunkX, currChunkZ, 31, chunkKey);
|
|
+ chunk.updatedMovementTicket();
|
|
+ }
|
|
+ // Sakura end - load chunks on movement
|
|
+
|
|
final net.minecraft.world.level.chunk.LevelChunkSection[] sections = chunk.getSections();
|
|
|
|
// bound y
|
|
diff --git a/src/main/java/net/minecraft/server/level/TicketType.java b/src/main/java/net/minecraft/server/level/TicketType.java
|
|
index f56e5c0f53f9b52a9247b9be9265b949494fc924..f8e0746433057297c88f0237502da85622297cef 100644
|
|
--- a/src/main/java/net/minecraft/server/level/TicketType.java
|
|
+++ b/src/main/java/net/minecraft/server/level/TicketType.java
|
|
@@ -25,6 +25,7 @@ public class TicketType<T> {
|
|
public static final TicketType<ChunkPos> UNKNOWN = TicketType.create("unknown", Comparator.comparingLong(ChunkPos::toLong), 1);
|
|
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<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> argumentComparator) {
|
|
return new TicketType<>(name, argumentComparator, 0L);
|
|
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
index 84be48a2fb7d99fac15f2f71576e82503a84da79..6e9d9d7938049734b06a30f88e4a657dfa01265a 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -553,6 +553,20 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
public boolean isPrimedTNT;
|
|
public boolean isFallingBlock;
|
|
// Sakura end - visibility api and command
|
|
+ // 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 world) {
|
|
this.id = Entity.ENTITY_COUNTER.incrementAndGet();
|
|
@@ -1502,7 +1516,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
|
|
ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.getCollisions(
|
|
world, (Entity)(Object)this, collisionBox, potentialCollisionsVoxel, potentialCollisionsBB,
|
|
- ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER,
|
|
+ ca.spottedleaf.moonrise.patches.collisions.CollisionUtil.COLLISION_FLAG_CHECK_BORDER | this.getExtraCollisionFlags(), // Sakura - load chunks on movement
|
|
null, null
|
|
);
|
|
|
|
@@ -4870,12 +4884,12 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
|
|
|
|
@Override
|
|
public boolean shouldBeSaved() {
|
|
- return this.removalReason != null && !this.removalReason.shouldSave() ? false : (this.isPassenger() ? false : !this.isVehicle() || !((ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity)this).moonrise$hasAnyPlayerPassengers()); // Paper - rewrite chunk system
|
|
+ return this.removalReason != null && !this.removalReason.shouldSave() ? false : (this.loadChunks || this.isPassenger() ? false : !this.isVehicle() || !((ca.spottedleaf.moonrise.patches.chunk_system.entity.ChunkSystemEntity)this).moonrise$hasAnyPlayerPassengers()); // Sakura - load chunks on movement; used to determine whether a chunk should unload // 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(Level world, BlockPos pos) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
index 1bfdebe6c1057ee19fb96d8f0f571c9d20d14cc6..eaafd4905229d111381c188d5373196a9f9288ab 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/FallingBlockEntity.java
|
|
@@ -79,6 +79,7 @@ public class FallingBlockEntity extends Entity {
|
|
this.dropItem = true;
|
|
this.fallDamageMax = 40;
|
|
this.isFallingBlock = true; // Sakura
|
|
+ this.loadChunks = world.sakuraConfig().cannons.loadChunks; // Sakura - load chunks on movement
|
|
}
|
|
|
|
public FallingBlockEntity(Level world, double x, double y, double z, BlockState block) {
|
|
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
index ef245198ce6385c66f58e0dbcdebffbe6d2b625e..b7c8c2335d59853dbc97d3b9496b5e3a63f0d9ab 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
|
|
@@ -58,6 +58,7 @@ public class PrimedTnt extends Entity implements TraceableEntity {
|
|
super(type, world);
|
|
this.blocksBuilding = true;
|
|
this.isPrimedTNT = true; // Sakura
|
|
+ this.loadChunks = world.sakuraConfig().cannons.loadChunks; // Sakura - load chunks on movement
|
|
}
|
|
|
|
public PrimedTnt(Level world, double x, double y, double z, @Nullable LivingEntity igniter) {
|
|
diff --git a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
|
index 75c8125e20b70433fe9d143a3193d821043327c3..77071ef825951cbdcbad79f4496add9dc499e856 100644
|
|
--- a/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
|
+++ b/src/main/java/net/minecraft/world/level/chunk/ChunkAccess.java
|
|
@@ -140,6 +140,17 @@ public abstract class ChunkAccess implements BlockGetter, BiomeManager.NoiseBiom
|
|
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.currentTickLong - this.lastMovementLoadTicket >= 100;
|
|
+ }
|
|
+
|
|
+ public final void updatedMovementTicket() {
|
|
+ this.lastMovementLoadTicket = net.minecraft.server.MinecraftServer.currentTickLong;
|
|
+ }
|
|
+ // Sakura end - load chunks on movement
|
|
|
|
public ChunkAccess(ChunkPos pos, UpgradeData upgradeData, LevelHeightAccessor heightLimitView, Registry<Biome> biomeRegistry, long inhabitedTime, @Nullable LevelChunkSection[] sectionArray, @Nullable BlendingData blendingData) {
|
|
this.locX = pos.x; this.locZ = pos.z; // Paper - reduce need for field lookups
|