mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-23 16:59:16 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@deaccd2 [ci skip] Add file reference url to help.yml (#12481) PaperMC/Paper@f86b435 Add vault change state event (#12069) PaperMC/Paper@3e3b42c Update player chat session sync (#12382) PaperMC/Paper@f8fa4f6 Add method to retrieve FishHook (#12310) PaperMC/Paper@b9d3147 Use correct placed block position for sound (#12410) PaperMC/Paper@952338b [ci skip] Add missing exception docs to Player#listPlayer (#12488) PaperMC/Paper@1db3785 [ci skip] improve javadoc for off-hand swaps through getHotbarButton (#12489) PaperMC/Paper@d1810f2 Allow Server#getDefaultGameMode before worlds are initialized (#12490) PaperMC/Paper@02d20ff Fix NPE in Server#getMap before worlds are loaded (#12492) PaperMC/Paper@9e873f5 Fix inconsistencies between offline/online spawn position getter (#11960) PaperMC/Paper@fc0c371 Fix handling of resultant crafting container from craftItemResult (#12307) PaperMC/Paper@a7a76c8 Add methods for Armadillo (#12031) PaperMC/Paper@a74400d Update adventure to 4.21.0 (#12499) PaperMC/Paper@1e93076 Fix ipv6 loopback addresses being able to get connection throttled (#12155) PaperMC/Paper@646b80c Fix unnecessary map data saves (#12296) PaperMC/Paper@e663f99 Add combat tracker API (#11853) PaperMC/Paper@cd4fe5b [ci skip] Drop non-applicable ATs (#12498) PaperMC/Paper@5acfdd6 Fix save/load NaN Entity Motion (#12269) PaperMC/Paper@2754d7c Add Throw EntityChangeBlockEvent for BrushableBlockEntity#brush (#12133) PaperMC/Paper@567f63a Parity for respawn events (#11792) PaperMC/Paper@bc3d946 Normalizes CraftEntity#toString/getHandle (#12170) PaperMC/Paper@0e9b94d Fix ItemStack amount issues with Chat Components (#12216) PaperMC/Paper@835b955 Add a method on InventoryView to get the MenuType (#12193) PaperMC/Paper@c9411bf Fix min ItemStack amount check for asHoverEvent (#12505) PaperMC/Paper@1acf3b3 Infer block entity data in brigadier blockstate argument (#12197) PaperMC/Paper@b9b3cd6 Use components instead of ChatColor in more places (#12507) PaperMC/Paper@ec42171 Add missing spaces back (#12508) PaperMC/Paper@51345a1 Correct nullable fall location type PaperMC/Paper@93246a0 Fix errors when loading raid files without a PDC PaperMC/Paper@cb3ffd0 Don't store empty PDCs on raids PaperMC/Paper@d637ae8 Fix NoSuchElementException in EntityTransformEvent for slimes (#12510) PaperMC/Paper@1074237 Pass correct draw strength for EntityShootBowEvent (#12308) PaperMC/Paper@825685f Add PlayerPickBlockEvent and PlayerPickEntityEvent (#12425) PaperMC/Paper@2bd84f6 Expand PotionMeta Api to allow getting effective potion colour and effects (#12390) PaperMC/Paper@6f1f5b6 Fix ArmorStand items for canceled EntityDeathEvent (#12288)
149 lines
9.4 KiB
Diff
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 ca2939dcc380989d87bed516c4b7a73be90ebf06..98664677c90564c2bd454ad408ed832f3ec289b5 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -516,6 +516,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;
|
|
@@ -1487,7 +1501,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);
|
|
@@ -4932,13 +4946,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,
|