mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-22 16:29:16 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@20ec622 use correct types for preloading CraftRegistry PaperMC/Paper@627cc64 Adjust HAProxy's existance to log for console masters (#11433) PaperMC/Paper@01c4820 Call EntityDropItemEvent when a container item drops its contents (#11441) PaperMC/Paper@9c76642 Deprecate for removal Block#isValidTool (#11439) PaperMC/Paper@dd6d184 Remove redundant fillUsableCommands call (#11425) PaperMC/Paper@f33611c fix ItemStack#removeEnchantments creating non-stackable items (#11442) PaperMC/Paper@8f56db8 Add enchantWithLevels with tag specification (#11438) PaperMC/Paper@b7ab22d Fix console completions on invalid commands (#7603) PaperMC/Paper@41bc31b Update paperweight to 1.7.3 (#11445) PaperMC/Paper@e17eb6b Improve entity effect API (#11444) PaperMC/Paper@7b03141 Add startingBrewTime (#11406) PaperMC/Paper@355b1cb Add API for explosions to damage the explosion cause (#11180) PaperMC/Paper@6d7a438 Call bucket events for cauldrons (#7486) PaperMC/Paper@f9c7f2a Begin switching to JSpecify annotations (#11448) PaperMC/Paper@e3c8a8e Add PlayerInsertLecternBookEvent [1.20 port] (#7305) PaperMC/Paper@b410fe8 Configurable per-world void damage offset/damage(#11436) PaperMC/Paper@ea00be3 Do not NPE on uuid resolution in player profile (#11449) PaperMC/Paper@ba3c29b Finish converting all events to jspecify annotations PaperMC/Paper@e7e1ab5 Finish converting most of the undeprecated api to jspecify PaperMC/Paper@69ffbec Fix hex color check PaperMC/Paper@709f0f2 Use components properly in ProfileWhitelistVerifyEvent (#11456) PaperMC/Paper@fb76840 [ci skip] Add section on nullability annotations (#11461)
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 d2e91843df93753a78bb9bd6839de287dc2ce4e5..87a117c74dcee2e58126e133b853a56a7965e55f 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();
|
|
@@ -1504,7 +1518,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
|
|
);
|
|
|
|
@@ -4874,12 +4888,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..20764fba3c7cfe26cf622c3ee4848839408fa6af 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.currentTick - this.lastMovementLoadTicket >= 100;
|
|
+ }
|
|
+
|
|
+ public final void updatedMovementTicket() {
|
|
+ this.lastMovementLoadTicket = net.minecraft.server.MinecraftServer.currentTick;
|
|
+ }
|
|
+ // 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
|