mirror of
https://github.com/Samsuik/Sakura.git
synced 2025-12-21 15:59:26 +00:00
94 lines
5.1 KiB
Diff
94 lines
5.1 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 f2dab7d69cd26474de88eae95b47f68414232cf6..80dfd159f8f71f9a6de38334d9ec5a50120ed324 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/Entity.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
|
|
@@ -1763,14 +1763,34 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
BlockPos blockposition = new BlockPos(axisalignedbb.minX + 0.001D, axisalignedbb.minY + 0.001D, axisalignedbb.minZ + 0.001D);
|
|
BlockPos blockposition1 = new BlockPos(axisalignedbb.maxX - 0.001D, axisalignedbb.maxY - 0.001D, axisalignedbb.maxZ - 0.001D);
|
|
|
|
- if (this.level.hasChunksAt(blockposition, blockposition1)) {
|
|
+ // Sakura start - optimise check inside blocks
|
|
+ if (blockposition1.getY() >= this.level.getMinBuildHeight() || blockposition.getY() < this.level.getMaxBuildHeight()) {
|
|
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
|
|
|
|
+ net.minecraft.server.level.ServerChunkCache chunkSource = ((net.minecraft.server.level.ServerLevel) this.level).getChunkSource();
|
|
+ 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) {
|
|
+ int chunkX = i >> 4;
|
|
+ for (int k = blockposition.getZ(); k <= blockposition1.getZ(); ++k) {
|
|
+ int chunkZ = k >> 4;
|
|
+
|
|
+ if (lastChunkX != chunkX || lastChunkZ != chunkZ) {
|
|
+ chunk = chunkSource.getChunkAtIfLoadedMainThread(chunkX, chunkZ);
|
|
+ lastChunkX = chunkX;
|
|
+ lastChunkZ = chunkZ;
|
|
+ }
|
|
+
|
|
+ if (chunk == null) {
|
|
+ continue;
|
|
+ }
|
|
+
|
|
+ for (int j = blockposition.getY(); j <= blockposition1.getY(); ++j) {
|
|
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);
|
|
@@ -4245,7 +4265,7 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
}
|
|
|
|
public boolean updateFluidHeightAndDoFluidPushing(TagKey<Fluid> tag, double speed) {
|
|
- if (this.touchingUnloadedChunk()) {
|
|
+ if (false) { // Sakura
|
|
return false;
|
|
} else {
|
|
AABB axisalignedbb = this.getBoundingBox().deflate(0.001D);
|
|
@@ -4262,11 +4282,31 @@ public abstract class Entity implements Nameable, EntityAccess, CommandSource {
|
|
int k1 = 0;
|
|
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
|
|
|
|
+ // Sakura start
|
|
+ net.minecraft.server.level.ServerChunkCache chunkSource = ((net.minecraft.server.level.ServerLevel) this.level).getChunkSource();
|
|
+ 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) {
|
|
+ int chunkX = l1 >> 4;
|
|
+ for (int j2 = i1; j2 < j1; ++j2) {
|
|
+ int chunkZ = j2 >> 4;
|
|
+
|
|
+ if (chunkX != lastChunkX || chunkZ != lastChunkZ) {
|
|
+ chunk = chunkSource.getChunkAtIfLoadedMainThread(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));
|