9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-21 15:59:26 +00:00
Files
SakuraMC/patches/server/0055-Optimise-check-inside-blocks-and-fluids.patch
Samsuik 264bf21712 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@b4f04ff Add Plugin#getDataPath (#11080)
PaperMC/Paper@05e5865 Add ItemType#getItemRarity (#11049)
PaperMC/Paper@aa929d6 Call PlayerLaunchProjectileEvent for wind charge (#10911)
PaperMC/Paper@8b23018 Avoid collision shapes outside world border in findFreePosition
PaperMC/Paper@3b45454 Port random ticking optimisation from Moonrise
PaperMC/Paper@77fcb29 Apply incremental player/level saving patch
PaperMC/Paper@9fd7710 Apply automatic regionfile header recalculation patch
PaperMC/Paper@b57b24d Do not try to stop main thread during watchdog shutdown
PaperMC/Paper@2cd8c46 Add OMINOUS_ITEM_SPAWNER SpawnReason (#10897)
PaperMC/Paper@ef96a69 Fire EntityChangeBlockEvent for weaving potion effect (#11087)
PaperMC/Paper@a6ceda1 distinguish between null and empty map in API (#10829)
PaperMC/Paper@506f165 Don't store removed components in multiple places (#11091)
PaperMC/Paper@ceeb8c1 Disable timings by default (#11095)
PaperMC/Paper@05ed6a6 Fix priority scheduling logic
PaperMC/Paper@967f98a Optimise chunk tick checking during chunk tick
PaperMC/Paper@00b949f Remove Moonrise utils to MCUtils, remove duplicated/unused utils
PaperMC/Paper@4efd24b Remove unused chunk system hooks in MCUtils
PaperMC/Paper@b653276 Finish chunk tick iteration optimisation port from Moonrise
PaperMC/Paper@2df5bba Log throwable when failing to save chunk/poi/entity data
PaperMC/Paper@44c3dd0 fix exact choice shapeless recipes (#10973)
PaperMC/Paper@dd11ef8 Updated Upstream (Bukkit/CraftBukkit/Spigot) (#11102)
PaperMC/Paper@3c8a7fe Re-add missing chunk event calls (#11104)
PaperMC/Paper@a8db527 Even more cleanup of mcutil patch
PaperMC/Paper@d08e8d1 Add total time to done message (#11109)
PaperMC/Paper@2a39276 Add CrafterCraftEvent (#11082)
PaperMC/Paper@75af62b Split rewriting flag into `paper.disableOldApiSupport` and `paper.disablePluginRemapping` (#11108)
PaperMC/Paper@7ea4039 Fixup startup time log message
PaperMC/Paper@e71c1df Call PlayerChunkUnloadEvent
PaperMC/Paper@968bdeb Make CraftComplexRecipe extend CraftingRecipe (#11114)
PaperMC/Paper@f1f01a1 Adjust done message again (#11118)
2024-07-20 00:57:24 +01:00

96 lines
4.8 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samsuik <kfian294ma4@gmail.com>
Date: Sun, 24 Dec 2023 16:54:07 +0000
Subject: [PATCH] Optimise check inside blocks and fluids
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 4e0c83c251f362ef5b2d6fce6348d2469793a173..4918625c61b506a5e5a36de025a1502774cc47de 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1922,18 +1922,37 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
BlockPos blockposition1 = BlockPos.containing(axisalignedbb.maxX - offset, axisalignedbb.maxY - offset, axisalignedbb.maxZ - offset);
// Sakura end - physics version api
- if (this.level().hasChunksAt(blockposition, blockposition1)) {
+ // Sakura start - optimise check inside blocks
+ if (blockposition1.getY() >= level.getMinBuildHeight() || blockposition.getY() < level.getMaxBuildHeight()) {
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
+ net.minecraft.world.level.chunk.ChunkAccess chunk = null;
+ int lastChunkX = Integer.MIN_VALUE;
+ int lastChunkZ = Integer.MIN_VALUE;
+
for (int i = blockposition.getX(); i <= blockposition1.getX(); ++i) {
- for (int j = blockposition.getY(); j <= blockposition1.getY(); ++j) {
- for (int k = blockposition.getZ(); k <= blockposition1.getZ(); ++k) {
+ final int chunkX = i >> 4;
+ for (int k = blockposition.getZ(); k <= blockposition1.getZ(); ++k) {
+ final int chunkZ = k >> 4;
+
+ if (lastChunkX != chunkX || lastChunkZ != chunkZ) {
+ chunk = level.getChunkIfLoadedImmediately(chunkX, chunkZ);
+ lastChunkX = chunkX;
+ lastChunkZ = chunkZ;
+ }
+
+ if (chunk == null) {
+ continue;
+ }
+
+ for (int j = blockposition.getY(); j <= blockposition1.getY(); ++j) {
if (!this.isAlive()) {
return;
}
blockposition_mutableblockposition.set(i, j, k);
- BlockState iblockdata = this.level().getBlockState(blockposition_mutableblockposition);
+ BlockState iblockdata = chunk.getBlockState(blockposition_mutableblockposition);
+ // Sakura end
try {
iblockdata.entityInside(this.level(), blockposition_mutableblockposition, this);
@@ -4710,7 +4729,7 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
}
public boolean updateFluidHeightAndDoFluidPushing(TagKey<Fluid> tag, double speed) {
- if (this.touchingUnloadedChunk()) {
+ if (false) { // Sakura
return false;
} else {
AABB axisalignedbb = this.getBoundingBox().deflate(0.001D);
@@ -4727,11 +4746,30 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
int k1 = 0;
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
+ // Sakura start
+ net.minecraft.world.level.chunk.ChunkAccess chunk = null;
+ int lastChunkX = Integer.MIN_VALUE;
+ int lastChunkZ = Integer.MIN_VALUE;
+
for (int l1 = i; l1 < j; ++l1) {
- for (int i2 = k; i2 < l; ++i2) {
- for (int j2 = i1; j2 < j1; ++j2) {
+ final int chunkX = l1 >> 4;
+ for (int j2 = i1; j2 < j1; ++j2) {
+ final int chunkZ = j2 >> 4;
+
+ if (chunkX != lastChunkX || chunkZ != lastChunkZ) {
+ chunk = level.getChunkIfLoadedImmediately(chunkX, chunkZ);
+ lastChunkX = chunkX;
+ lastChunkZ = chunkZ;
+ }
+
+ if (chunk == null) {
+ return false;
+ }
+
+ for (int i2 = k; i2 < l; ++i2) {
blockposition_mutableblockposition.set(l1, i2, j2);
- FluidState fluid = this.level().getFluidState(blockposition_mutableblockposition);
+ FluidState fluid = chunk.getFluidState(blockposition_mutableblockposition);
+ // Sakura end
if (fluid.is(tag)) {
double d2 = (double) ((float) i2 + fluid.getHeight(this.level(), blockposition_mutableblockposition));