Skip to content

Commit 914fb08

Browse files
committed
Fix Entity#updateFluidHeightAndDoFluidPushing inconsistency with Vanilla
See Tuinity/Moonrise@57982e2
1 parent 8483163 commit 914fb08

File tree

2 files changed

+61
-67
lines changed

2 files changed

+61
-67
lines changed

paper-server/patches/features/0001-Moonrise-optimisation-patches.patch

Lines changed: 59 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -28050,7 +28050,7 @@ index 8cc5c0716392ba06501542ff5cbe71ee43979e5d..09fd99c9cbd23b5f3c899bfb00c9b896
2805028050
+ // Paper end - block counting
2805128051
}
2805228052
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
28053-
index 5ee3dc10cb4755fca83d8f7cad55d26b07afd6ff..346d9dfafab6dfe6f8253552d0e89ecd7e190312 100644
28053+
index 5ee3dc10cb4755fca83d8f7cad55d26b07afd6ff..454f588b166e412a6da9d7991607418d7e100b59 100644
2805428054
--- a/net/minecraft/world/entity/Entity.java
2805528055
+++ b/net/minecraft/world/entity/Entity.java
2805628056
@@ -149,7 +149,7 @@ import net.minecraft.world.waypoints.WaypointTransmitter;
@@ -28551,7 +28551,7 @@ index 5ee3dc10cb4755fca83d8f7cad55d26b07afd6ff..346d9dfafab6dfe6f8253552d0e89ecd
2855128551
}
2855228552

2855328553
public int countPlayerPassengers() {
28554-
@@ -4478,77 +4717,136 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
28554+
@@ -4478,77 +4717,126 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
2855528555
return Mth.lerp(partialTick, this.yRotO, this.yRot);
2855628556
}
2855728557

@@ -28591,7 +28591,17 @@ index 5ee3dc10cb4755fca83d8f7cad55d26b07afd6ff..346d9dfafab6dfe6f8253552d0e89ecd
2859128591
- flow = flow.scale(d);
2859228592
- }
2859328593
+ }
28594-
+
28594+
28595+
- vec3 = vec3.add(flow);
28596+
- i++;
28597+
- }
28598+
- // CraftBukkit start - store last lava contact location
28599+
- if (fluidTag == FluidTags.LAVA) {
28600+
- this.lastLavaContact = mutableBlockPos.immutable();
28601+
- }
28602+
- // CraftBukkit end
28603+
- }
28604+
- }
2859528605
+ final AABB boundingBox = this.getBoundingBox().deflate(1.0E-3);
2859628606
+
2859728607
+ final Level world = this.level;
@@ -28617,81 +28627,65 @@ index 5ee3dc10cb4755fca83d8f7cad55d26b07afd6ff..346d9dfafab6dfe6f8253552d0e89ecd
2861728627
+ final int minChunkX = minBlockX >> 4;
2861828628
+ final int maxChunkX = maxBlockX >> 4;
2861928629
+
28620-
+ final int minChunkY = minBlockY >> 4;
28621-
+ final int maxChunkY = maxBlockY >> 4;
28622-
+
2862328630
+ final int minChunkZ = minBlockZ >> 4;
2862428631
+ final int maxChunkZ = maxBlockZ >> 4;
2862528632
+
2862628633
+ final net.minecraft.world.level.chunk.ChunkSource chunkSource = world.getChunkSource();
2862728634
+
28635+
+ final int chunkLenX = maxChunkX - minChunkX + 1;
28636+
+ // chunk index = (x - minX) + (maxX-minX+1)*(z - minZ)
28637+
+ // = x + (maxX-minX+1)*z - (minX + (maxX-minX+1)*minZ)
28638+
+ final int chunkOffset = -(minChunkX + chunkLenX*minChunkZ);
28639+
+ // = x + (maxX-minX+1)*z + chunkOffset
28640+
+ final net.minecraft.world.level.chunk.LevelChunkSection[][] sections = new net.minecraft.world.level.chunk.LevelChunkSection[chunkLenX * (maxChunkZ - minChunkZ + 1)][];
28641+
+
28642+
+ // init chunks
2862828643
+ for (int currChunkZ = minChunkZ; currChunkZ <= maxChunkZ; ++currChunkZ) {
2862928644
+ for (int currChunkX = minChunkX; currChunkX <= maxChunkX; ++currChunkX) {
28630-
+ final net.minecraft.world.level.chunk.LevelChunkSection[] sections = chunkSource.getChunk(currChunkX, currChunkZ, net.minecraft.world.level.chunk.status.ChunkStatus.FULL, false).getSections();
28645+
+ sections[currChunkX + chunkLenX*currChunkZ + chunkOffset] = chunkSource.getChunk(currChunkX, currChunkZ, net.minecraft.world.level.chunk.status.ChunkStatus.FULL, false).getSections();
28646+
+ }
28647+
+ }
2863128648
+
28632-
+ // bound y
28633-
+ for (int currChunkY = minChunkY; currChunkY <= maxChunkY; ++currChunkY) {
28634-
+ final int sectionIdx = currChunkY - minSection;
28635-
+ if (sectionIdx < 0 || sectionIdx >= sections.length) {
28636-
+ continue;
28637-
+ }
28638-
+ final net.minecraft.world.level.chunk.LevelChunkSection section = sections[sectionIdx];
28639-
+ if (section.hasOnlyAir()) {
28640-
+ // empty
28649+
+ for (int currX = minBlockX; currX <= maxBlockX; ++currX) {
28650+
+ for (int currY = minBlockY; currY <= maxBlockY; ++currY) {
28651+
+ for (int currZ = minBlockZ; currZ <= maxBlockZ; ++currZ) {
28652+
+ final FluidState fluidState = sections[(currX >> 4) + chunkLenX*(currZ >> 4) + chunkOffset][(currY >> 4) - minSection]
28653+
+ .states.get((currX & 15) | ((currZ & 15) << 4) | ((currY & 15) << 8)).getFluidState();
28654+
+
28655+
+ if (fluidState.isEmpty() || !fluidState.is(fluid)) {
2864128656
+ continue;
2864228657
+ }
2864328658
+
28644-
+ final net.minecraft.world.level.chunk.PalettedContainer<net.minecraft.world.level.block.state.BlockState> blocks = section.states;
28659+
+ mutablePos.set(currX, currY, currZ);
2864528660
+
28646-
+ final int minXIterate = currChunkX == minChunkX ? (minBlockX & 15) : 0;
28647-
+ final int maxXIterate = currChunkX == maxChunkX ? (maxBlockX & 15) : 15;
28648-
+ final int minZIterate = currChunkZ == minChunkZ ? (minBlockZ & 15) : 0;
28649-
+ final int maxZIterate = currChunkZ == maxChunkZ ? (maxBlockZ & 15) : 15;
28650-
+ final int minYIterate = currChunkY == minChunkY ? (minBlockY & 15) : 0;
28651-
+ final int maxYIterate = currChunkY == maxChunkY ? (maxBlockY & 15) : 15;
28652-
28653-
- vec3 = vec3.add(flow);
28654-
- i++;
28655-
+ for (int currY = minYIterate; currY <= maxYIterate; ++currY) {
28656-
+ for (int currZ = minZIterate; currZ <= maxZIterate; ++currZ) {
28657-
+ for (int currX = minXIterate; currX <= maxXIterate; ++currX) {
28658-
+ final FluidState fluidState = blocks.get((currX) | (currZ << 4) | ((currY) << 8)).getFluidState();
28659-
+
28660-
+ if (fluidState.isEmpty() || !fluidState.is(fluid)) {
28661-
+ continue;
28662-
}
28663-
- // CraftBukkit start - store last lava contact location
28664-
- if (fluidTag == FluidTags.LAVA) {
28665-
- this.lastLavaContact = mutableBlockPos.immutable();
28666-
+
28667-
+ mutablePos.set(currX | (currChunkX << 4), currY | (currChunkY << 4), currZ | (currChunkZ << 4));
28661+
+ // CraftBukkit start - store last lava contact location
28662+
+ if (fluid == FluidTags.LAVA) {
28663+
+ this.lastLavaContact = mutablePos.immutable();
28664+
+ }
28665+
+ // CraftBukkit end
2866828666
+
28669-
+ final double height = (double)((float)mutablePos.getY() + fluidState.getHeight(world, mutablePos));
28670-
+ final double diff = height - boundingBox.minY;
28667+
+ final double height = (double)((float)currY + fluidState.getHeight(world, mutablePos));
28668+
+ final double diff = height - boundingBox.minY;
2867128669
+
28672-
+ if (diff < 0.0) {
28673-
+ continue;
28674-
+ }
28670+
+ if (diff < 0.0) {
28671+
+ continue;
28672+
+ }
2867528673
+
28676-
+ inFluid = true;
28677-
+ maxHeightDiff = Math.max(maxHeightDiff, diff);
28674+
+ inFluid = true;
28675+
+ maxHeightDiff = Math.max(maxHeightDiff, diff);
2867828676
+
28679-
+ if (!isPushable) {
28680-
+ continue;
28681-
+ }
28677+
+ if (!isPushable) {
28678+
+ continue;
28679+
+ }
2868228680
+
28683-
+ ++totalPushes;
28681+
+ ++totalPushes;
2868428682
+
28685-
+ final Vec3 flow = fluidState.getFlow(world, mutablePos);
28683+
+ final Vec3 flow = fluidState.getFlow(world, mutablePos);
2868628684
+
28687-
+ if (diff < 0.4) {
28688-
+ pushVector = pushVector.add(flow.scale(diff));
28689-
+ } else {
28690-
+ pushVector = pushVector.add(flow);
28691-
}
28692-
- // CraftBukkit end
28693-
}
28694-
}
28685+
+ if (maxHeightDiff < 0.4) {
28686+
+ pushVector = pushVector.add(flow.scale(maxHeightDiff));
28687+
+ } else {
28688+
+ pushVector = pushVector.add(flow);
2869528689
}
2869628690
}
2869728691
}
@@ -28706,7 +28700,7 @@ index 5ee3dc10cb4755fca83d8f7cad55d26b07afd6ff..346d9dfafab6dfe6f8253552d0e89ecd
2870628700
- if (!(this instanceof Player)) {
2870728701
- vec3 = vec3.normalize();
2870828702
- }
28709-
+ if (pushVector.lengthSqr() == 0.0) {
28703+
+ if (pushVector == Vec3.ZERO) {
2871028704
+ return inFluid;
2871128705
+ }
2871228706

@@ -28716,7 +28710,7 @@ index 5ee3dc10cb4755fca83d8f7cad55d26b07afd6ff..346d9dfafab6dfe6f8253552d0e89ecd
2871628710
- if (Math.abs(deltaMovement.x) < 0.003 && Math.abs(deltaMovement.z) < 0.003 && vec3.length() < 0.0045000000000000005) {
2871728711
- vec3 = vec3.normalize().scale(0.0045000000000000005);
2871828712
- }
28719-
+ // note: totalPushes != 0 as pushVector != 0
28713+
+ // note: totalPushes != 0 as pushVector was changed
2872028714
+ pushVector = pushVector.scale(1.0 / totalPushes);
2872128715
+ final Vec3 currMovement = this.getDeltaMovement();
2872228716

@@ -28742,7 +28736,7 @@ index 5ee3dc10cb4755fca83d8f7cad55d26b07afd6ff..346d9dfafab6dfe6f8253552d0e89ecd
2874228736

2874328737
public boolean touchingUnloadedChunk() {
2874428738
AABB aabb = this.getBoundingBox().inflate(1.0);
28745-
@@ -4704,6 +5002,15 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
28739+
@@ -4704,6 +4992,15 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
2874628740
}
2874728741

2874828742
public final void setPosRaw(double x, double y, double z, boolean forceBoundingBoxUpdate) {
@@ -28758,7 +28752,7 @@ index 5ee3dc10cb4755fca83d8f7cad55d26b07afd6ff..346d9dfafab6dfe6f8253552d0e89ecd
2875828752
if (!checkPosition(this, x, y, z)) {
2875928753
return;
2876028754
}
28761-
@@ -4855,6 +5162,12 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
28755+
@@ -4855,6 +5152,12 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
2876228756

2876328757
@Override
2876428758
public final void setRemoved(Entity.RemovalReason removalReason, @Nullable org.bukkit.event.entity.EntityRemoveEvent.Cause cause) { // CraftBukkit - add Bukkit remove cause
@@ -28771,7 +28765,7 @@ index 5ee3dc10cb4755fca83d8f7cad55d26b07afd6ff..346d9dfafab6dfe6f8253552d0e89ecd
2877128765
org.bukkit.craftbukkit.event.CraftEventFactory.callEntityRemoveEvent(this, cause); // CraftBukkit
2877228766
final boolean alreadyRemoved = this.removalReason != null; // Paper - Folia schedulers
2877328767
if (this.removalReason == null) {
28774-
@@ -4865,7 +5178,7 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
28768+
@@ -4865,7 +5168,7 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
2877528769
this.stopRiding();
2877628770
}
2877728771

@@ -28780,7 +28774,7 @@ index 5ee3dc10cb4755fca83d8f7cad55d26b07afd6ff..346d9dfafab6dfe6f8253552d0e89ecd
2878028774
this.levelCallback.onRemove(removalReason);
2878128775
this.onRemoval(removalReason);
2878228776
// Paper start - Folia schedulers
28783-
@@ -4899,7 +5212,7 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
28777+
@@ -4899,7 +5202,7 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
2878428778
public boolean shouldBeSaved() {
2878528779
return (this.removalReason == null || this.removalReason.shouldSave())
2878628780
&& !this.isPassenger()

paper-server/patches/features/0026-Optimise-EntityScheduler-ticking.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,10 @@ index 4b98ac1a7423d9fe569727ef2ce553b1bdc8464a..18a380f11f2f5b5dffb1cfcfe8b7bbae
6767
io.papermc.paper.adventure.providers.ClickCallbackProviderImpl.DIALOG_CLICK_MANAGER.handleQueue(this.tickCount); // Paper
6868
profilerFiller.push("commandFunctions");
6969
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
70-
index 681a4d7c0a40466997595d32cfb8aa902991e86b..2d74876cd072e0fd0380bc53ed34da1cb1bc3a29 100644
70+
index 35ec35dfbcb0d136d06d8440d1e359bcf26522cd..87f9a7c5fbd98644dd44a86ce1efca6ce62f771e 100644
7171
--- a/net/minecraft/world/entity/Entity.java
7272
+++ b/net/minecraft/world/entity/Entity.java
73-
@@ -5229,6 +5229,11 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
73+
@@ -5219,6 +5219,11 @@ public abstract class Entity implements SyncedDataHolder, DebugValueSource, Name
7474
this.getBukkitEntity().taskScheduler.retire();
7575
}
7676
// Paper end - Folia schedulers

0 commit comments

Comments
 (0)