9
0
mirror of https://github.com/Samsuik/Sakura.git synced 2025-12-22 16:29:16 +00:00
Files
SakuraMC/patches/server/0055-Optimise-check-inside-blocks-and-fluids.patch
Samsuik 021078518d Updated Upstream (Paper)
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)
2024-10-02 19:14: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 eb90625e5a4b843877ba2f7b2510ba1c26d861ce..8237ed9645ccebc274d3e7bbb16444126638c7a2 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -1924,18 +1924,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);
@@ -4714,7 +4733,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);
@@ -4731,11 +4750,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));