mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-24 01:09:16 +00:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@7e70636 Initial 1.21.9 update (squashed) PaperMC/Paper@0a28816 Add Server#getRespawnWorld and Server#setRespawnWorld(World) PaperMC/Paper@b67fa6d move todos txt content into tracking issue PaperMC/Paper@68f26a1 Drop no-longer-needed packet diffs PaperMC/Paper@f9434d2 Use pitch when setting spawn position with Location PaperMC/Paper@810b3c6 Deprecate the Conversation API (for removal), Metadata API, and PlayerSpawnLocationEvent (for removal) PaperMC/Paper@1870261 Update Moonrise to 1.21.9-pre1 PaperMC/Paper@1141058 Shift feature patch #s for Moonrise being first PaperMC/Paper@510aa9b Update 'Optimize Network Manager and add advanced packet support' PaperMC/Paper@89cc24a Update 'Allow Saving of Oversized Chunks' PaperMC/Paper@bcd75d8 Update EAR 2.0 patch and enable oldPaperCommit for better 3-way merges PaperMC/Paper@6b44820 Update 'Use Velocity compression and cipher natives' PaperMC/Paper@87f3e2f Update 'Optimize GoalSelector Goal.Flag Set operations' PaperMC/Paper@5323486 Update 'Optimize Voxel Shape Merging' PaperMC/Paper@5aac8b4 Update 'Handle Oversized block entities in chunks' PaperMC/Paper@f0b3d62 Update 'optimize dirt and snow spreading' and drop 'Optimise getChunkAt calls for loaded chunks' patch to code replaced by Moonrise PaperMC/Paper@92f822d Update 'Optimize Bit Operations by inlining', 'Remove streams from hot code' PaperMC/Paper@98e745a Update 'Optimize Pathfinder - Remove Streams / Optimized collections' PaperMC/Paper@49e49d0 Update 'Fix entity tracker desync when new players are added to the tracker' PaperMC/Paper@87e0525 Update alternate redstone impls PaperMC/Paper@35e973d Update 'Improve exact choice recipe ingredients', 'Only write chunk data to disk if it serializes without throwing' PaperMC/Paper@181f9bb Update 'Entity load/save limit per chunk', 'Attempt to recalculate regionfile header if it is corrupt' PaperMC/Paper@b31ca18 Update 'Incremental chunk and player saving', 'Optimise general POI access' PaperMC/Paper@9b69cc5 Add some more Mannequin API PaperMC/Paper@8bb12cb Fix compile PaperMC/Paper@e3aca92 Replace ConcurrentUtil's Validate with Objects PaperMC/Paper@9a626dd Rewrite ticket counter system PaperMC/Paper@65250cb Drop "Optimize Collision to not load chunks" PaperMC/Paper@55d56d9 Apply "Flush regionfiles on save configuration option" PaperMC/Paper@920e8d3 Apply "Optimise collision checking in player move packet handling" PaperMC/Paper@ec492d3 Apply "Improve keepalive ping system" PaperMC/Paper@8f65947 Apply "Optimise EntityScheduler ticking" PaperMC/Paper@086b4fd Apply "Optional per player mob spawns" PaperMC/Paper@2f4211e Apply "Improve cancelling PreCreatureSpawnEvent with per player mob spawns" PaperMC/Paper@b6d9557 Apply "Optimize Hoppers" PaperMC/Paper@388e693 update generator PaperMC/Paper@a3c89a8 add javadocs for new api PaperMC/Paper@fcc763a Call BlockRedstoneEvent for the shelf PaperMC/Paper@03eb18b replace requireNonNull by checkArgument and deprecate MCUtil#toLocation PaperMC/Paper@6b7bf01 bump built-in datapack version PaperMC/Paper@2779a53 deprecate #lanterns material tag in favour of vanilla tag PaperMC/Paper@6f9957e Mannequin#createDefaultProfile -> Mannequin#defaultProfile PaperMC/Paper@24874e5 Also rename Mannequin profile getter/setters for consistency PaperMC/Paper@bc2ae10 Fix default respawn dimension being null for new worlds PaperMC/Paper@eb42158 Use 0.0.4 release of ConcurrentUtil PaperMC/Paper@bb01745 1.21.9-pre2 PaperMC/Paper@0249204 1.21.9-pre2 feature patches PaperMC/Paper@9360ba4 Identifying comments for MinecraftServer PaperMC/Paper@5d3aa53 Some diff improvements in prepare spawn task PaperMC/Paper@22ad451 Move some stuff to ATs PaperMC/Paper@0ea15c9 Drop no longer applicable ATs PaperMC/Paper@cf78f2a bump api-version/datapack format and add a copper torch tag PaperMC/Paper@60cb0df generate ClientOption enums and mark CraftBlockData impl as null marked PaperMC/Paper@4025289 Add pre2 to api version PaperMC/Paper@f2cb073 Set build channel to alpha PaperMC/Paper@90b29c4 Port most of the anti-xray patch PaperMC/Paper@4a8e88d Disable oldPaperCommit to fix CI build PaperMC/Paper@121ac2e Port the last Anti-XRay hunk PaperMC/Paper@f43641f Use ConcurrentUtil 0.0.5 PaperMC/Paper@1f79388 fix end portal teleportation PaperMC/Paper@2efb400 [ci skip] Adjust spawn location event docs PaperMC/Paper@cb9fc05 simplify overloads PaperMC/Paper@25ecc59 Enable Anti-Xray PaperMC/Paper@4d7185f Add AsyncPlayerSpawnLocationEvent#isNewPlayer (#13081) PaperMC/Paper@dc474a8 Fixup vanilla code for Anti-Xray changes PaperMC/Paper@0e23b02 Add back null check for chunkPacketBlockController PaperMC/Paper@e6f1483 Update to 1.21.9-pre3 PaperMC/Paper@44259ea Add ResolvableProfile.SkinPatch (#13091) PaperMC/Paper@634f51e Update to 1.21.9-pre4 PaperMC/Paper@fada3a7 Update DataConverter to 1.21.9-pre4 PaperMC/Paper@037179f Update Starlight stored version PaperMC/Paper@6b0b29a Update publishing endpoint PaperMC/Paper@f6fabc5 Call EntityChangeBlockEvent for copper golem statue changes (#13090) PaperMC/Paper@1d6ee7d Update adventure PaperMC/Paper@404e49f Update to 1.21.9-rc1 PaperMC/Paper@4055274 Fix empty SkinPatch initialization and swapped dynamic/static heuristic in ResolvableProfile build method PaperMC/Paper@51fe7aa Fixed modern forwarding support (#13098) PaperMC/Paper@5613a35 fix PlayerGameModeChangeEvent#cancelMessage PaperMC/Paper@673abf4 use PlayerShieldDisableEvent#getCooldown PaperMC/Paper@3a0dc7f Fix a couple PlayerProfile mutability issues PaperMC/Paper@e97fb40 Remove parallel generation config option PaperMC/Paper@c3a60b8 Use ThreadLocal for Starlight and ticket level propagator cache PaperMC/Paper@e16b369 Resize propagator queues less aggressively
129 lines
7.7 KiB
Diff
129 lines
7.7 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Samsuik <kfian294ma4@gmail.com>
|
|
Date: Fri, 8 Nov 2024 19:35:49 +0000
|
|
Subject: [PATCH] Optimise check inside blocks and traverse blocks
|
|
|
|
|
|
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
|
|
index 5a8fdf9af5b64d2e365151c178b2fbe4468f9a2a..bc6e2cd985f28a79c843efe93e8b847a3adb7756 100644
|
|
--- a/net/minecraft/world/entity/Entity.java
|
|
+++ b/net/minecraft/world/entity/Entity.java
|
|
@@ -1935,6 +1935,7 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
|
|
if (this.isAffectedByBlocks()) {
|
|
LongSet set = this.visitedBlocks;
|
|
final me.samsuik.sakura.mechanics.MinecraftMechanicsTarget mechanicsTarget = this.mechanicsTarget; // Sakura - configure server mechanics
|
|
+ final net.minecraft.world.level.chunk.ChunkAccess[] chunkCache = new net.minecraft.world.level.chunk.ChunkAccess[4]; // Sakura - optimise check inside blocks
|
|
|
|
for (Entity.Movement movement : movements) {
|
|
Vec3 vec3 = movement.from;
|
|
@@ -1952,7 +1953,7 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
|
|
double d = vec31.get(axis);
|
|
if (d != 0.0) {
|
|
Vec3 vec32 = vec3.relative(axis.getPositive(), d);
|
|
- final int stepsTaken = this.checkInsideBlocks(vec3, vec32, stepBasedCollector, set, i);
|
|
+ final int stepsTaken = this.checkInsideBlocks(vec3, vec32, stepBasedCollector, set, i, chunkCache); // Sakura - optimise check inside blocks
|
|
if (mechanicsTarget.atLeast(me.samsuik.sakura.mechanics.MechanicVersion.v1_21_9)) {
|
|
i -= stepsTaken;
|
|
}
|
|
@@ -1960,12 +1961,12 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
|
|
}
|
|
}
|
|
} else if (mechanicsTarget.atLeast(me.samsuik.sakura.mechanics.MechanicVersion.v1_21_2)) {
|
|
- i -= this.checkInsideBlocks(movement.from(), movement.to(), stepBasedCollector, set, 16);
|
|
+ i -= this.checkInsideBlocks(movement.from(), movement.to(), stepBasedCollector, set, 16, chunkCache); // Sakura - optimise check inside blocks
|
|
}
|
|
|
|
if (i <= 0 || mechanicsTarget.before(me.samsuik.sakura.mechanics.MechanicVersion.v1_21_2)) {
|
|
// Sakura end - configure server mechanics
|
|
- this.checkInsideBlocks(movement.to(), movement.to(), stepBasedCollector, set, 1);
|
|
+ this.checkInsideBlocks(movement.to(), movement.to(), stepBasedCollector, set, 1, chunkCache); // Sakura - optimise check inside blocks
|
|
}
|
|
}
|
|
|
|
@@ -1973,7 +1974,16 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
|
|
}
|
|
}
|
|
|
|
- private int checkInsideBlocks(Vec3 from, Vec3 to, InsideBlockEffectApplier.StepBasedCollector stepBasedCollector, LongSet visited, int maxSteps) {
|
|
+ // Sakura start - optimise check inside blocks
|
|
+ private int checkInsideBlocks(
|
|
+ final Vec3 from,
|
|
+ final Vec3 to,
|
|
+ final InsideBlockEffectApplier.StepBasedCollector stepBasedCollector,
|
|
+ final LongSet visited,
|
|
+ final int maxSteps,
|
|
+ final net.minecraft.world.level.chunk.ChunkAccess[] chunkCache
|
|
+ ) {
|
|
+ // Sakura end - optimise check inside blocks
|
|
// Sakura start - configure server mechanics
|
|
final double margin;
|
|
if (this.mechanicsTarget.atLeast(me.samsuik.sakura.mechanics.MechanicVersion.v1_21_2)) {
|
|
@@ -2000,7 +2010,20 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
|
|
return false;
|
|
} else {
|
|
atomicInteger.set(index);
|
|
- BlockState blockState = this.level().getBlockState(pos);
|
|
+ // Sakura start - optimise check inside blocks
|
|
+ final int chunkX = pos.getX() >> 4;
|
|
+ final int chunkZ = pos.getZ() >> 4;
|
|
+ final int chunkKey = ((chunkX << 2) | chunkZ) & 3;
|
|
+ net.minecraft.world.level.chunk.ChunkAccess chunk = chunkCache[chunkKey];
|
|
+ if (chunk == null || chunk.locX != chunkX || chunk.locZ != chunkZ) {
|
|
+ chunk = this.level().getChunkIfLoadedImmediately(chunkX, chunkZ);
|
|
+ if (chunk == null) {
|
|
+ return true;
|
|
+ }
|
|
+ chunkCache[chunkKey] = chunk;
|
|
+ }
|
|
+ final BlockState blockState = chunk.getBlockState(pos);
|
|
+ // Sakura end - optimise check inside blocks
|
|
if (blockState.isAir()) {
|
|
if (flag) {
|
|
this.debugBlockIntersection((ServerLevel)this.level(), pos.immutable(), false, false);
|
|
diff --git a/net/minecraft/world/level/BlockGetter.java b/net/minecraft/world/level/BlockGetter.java
|
|
index ba2e7efe147b26bea5d73eac1f4b2fe6ee4bd5c2..b9ed6671edc98fe7a4bb30fdd25a6629e852da4f 100644
|
|
--- a/net/minecraft/world/level/BlockGetter.java
|
|
+++ b/net/minecraft/world/level/BlockGetter.java
|
|
@@ -231,7 +231,7 @@ public interface BlockGetter extends LevelHeightAccessor {
|
|
: 0.99999F;
|
|
if (vec3.lengthSqr() < Mth.square(margin) || mechanicsTarget != null && mechanicsTarget.before(me.samsuik.sakura.mechanics.MechanicVersion.v1_21_2)) {
|
|
// Sakura end - configure server mechanics
|
|
- for (BlockPos blockPos : BlockPos.betweenClosed(boundingBox)) {
|
|
+ for (final BlockPos blockPos : me.samsuik.sakura.utils.BlockPosIterator.iterable(boundingBox)) { // Sakura - optimise check inside blocks
|
|
if (!visitor.visit(blockPos, 0)) {
|
|
return false;
|
|
}
|
|
@@ -239,9 +239,22 @@ public interface BlockGetter extends LevelHeightAccessor {
|
|
|
|
return true;
|
|
} else {
|
|
+ // Sakura start - optimise check inside blocks
|
|
+ final boolean xZero = vec3.x() == 0.0;
|
|
+ final boolean yZero = vec3.y() == 0.0;
|
|
+ final boolean zZero = vec3.z() == 0.0;
|
|
+ if (xZero && yZero || yZero && zZero || xZero && zZero) {
|
|
+ for (final BlockPos blockPos : me.samsuik.sakura.utils.BlockPosIterator.traverseArea(vec3, boundingBox)) {
|
|
+ if (!visitor.visit(blockPos, 0)) {
|
|
+ return false;
|
|
+ }
|
|
+ }
|
|
+ return true;
|
|
+ }
|
|
+ // Sakura end - optimise check inside blocks
|
|
LongSet set = new LongOpenHashSet();
|
|
|
|
- for (BlockPos blockPos1 : BlockPos.betweenCornersInDirection(boundingBox.move(vec3.scale(-1.0)), vec3)) {
|
|
+ for (final BlockPos blockPos1 : me.samsuik.sakura.utils.BlockPosIterator.iterable(boundingBox.move(vec3.scale(-1.0)))) { // Sakura - optimise check inside blocks
|
|
if (!visitor.visit(blockPos1, 0)) {
|
|
return false;
|
|
}
|
|
@@ -253,7 +266,7 @@ public interface BlockGetter extends LevelHeightAccessor {
|
|
if (i < 0) {
|
|
return false;
|
|
} else {
|
|
- for (BlockPos blockPos2 : BlockPos.betweenCornersInDirection(boundingBox, vec3)) {
|
|
+ for (final BlockPos blockPos2 : me.samsuik.sakura.utils.BlockPosIterator.iterable(boundingBox)) { // Sakura - optimise check inside blocks
|
|
if (set.add(blockPos2.asLong()) && !visitor.visit(blockPos2, i + 1)) {
|
|
return false;
|
|
}
|