9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-29 11:59:17 +00:00

Vanilla Fluid Pushing (#490) (#547)

This commit is contained in:
Fortern
2025-07-05 23:05:43 +08:00
parent c47f5411ab
commit d4854b69b2
2 changed files with 86 additions and 13 deletions

View File

@@ -5,19 +5,89 @@ Subject: [PATCH] Vanilla Fluid Pushing
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index 0dde70f12ede6da06a0b9f0e78272a963a167699..a0fc0613bbda652d439215d7d6282ac710c1461d 100644
index 75dbb580388bb31e0c0367d5595fd18b0d329709..6e7033ceb43acf8afd4c27a4d130e8a3dd8c1eef 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -4823,8 +4823,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
@@ -4730,8 +4730,82 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return Mth.lerp(partialTick, this.yRotO, this.yRot);
}
final Vec3 flow = fluidState.getFlow(world, mutablePos);
- if (diff < 0.4) {
- pushVector = pushVector.add(flow.scale(diff));
+ // Leaves start - Vanilla Fluid Pushing
+ if (maxHeightDiff < 0.4) {
+ pushVector = pushVector.add(flow.scale(maxHeightDiff));
+ // Leaves end - Vanilla Fluid Pushing
} else {
pushVector = pushVector.add(flow);
}
+ // Leaves start - vanilla fluid pushing
+ private boolean vanillaUpdateFluidHeightAndDoFluidPushing(final TagKey<Fluid> fluidTag, final double motionScale) {
+ if (this.touchingUnloadedChunk()) {
+ return false;
+ } else {
+ AABB aabb = this.getBoundingBox().deflate(0.001);
+ int floor = Mth.floor(aabb.minX);
+ int ceil = Mth.ceil(aabb.maxX);
+ int floor1 = Mth.floor(aabb.minY);
+ int ceil1 = Mth.ceil(aabb.maxY);
+ int floor2 = Mth.floor(aabb.minZ);
+ int ceil2 = Mth.ceil(aabb.maxZ);
+ double d = 0.0;
+ boolean isPushedByFluid = this.isPushedByFluid();
+ boolean flag = false;
+ Vec3 vec3 = Vec3.ZERO;
+ int i = 0;
+ BlockPos.MutableBlockPos mutableBlockPos = new BlockPos.MutableBlockPos();
+
+ for (int i1 = floor; i1 < ceil; i1++) {
+ for (int i2 = floor1; i2 < ceil1; i2++) {
+ for (int i3 = floor2; i3 < ceil2; i3++) {
+ mutableBlockPos.set(i1, i2, i3);
+ FluidState fluidState = this.level().getFluidState(mutableBlockPos);
+ if (fluidState.is(fluidTag)) {
+ double d1 = i2 + fluidState.getHeight(this.level(), mutableBlockPos);
+ if (d1 >= aabb.minY) {
+ flag = true;
+ d = Math.max(d1 - aabb.minY, d);
+ if (isPushedByFluid) {
+ Vec3 flow = fluidState.getFlow(this.level(), mutableBlockPos);
+ if (d < 0.4) {
+ flow = flow.scale(d);
+ }
+
+ vec3 = vec3.add(flow);
+ i++;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (vec3.length() > 0.0) {
+ if (i > 0) {
+ vec3 = vec3.scale(1.0 / i);
+ }
+
+ if (!(this instanceof Player)) {
+ vec3 = vec3.normalize();
+ }
+
+ Vec3 deltaMovement = this.getDeltaMovement();
+ vec3 = vec3.scale(motionScale);
+ double d2 = 0.003;
+ if (Math.abs(deltaMovement.x) < 0.003 && Math.abs(deltaMovement.z) < 0.003 && vec3.length() < 0.0045000000000000005) {
+ vec3 = vec3.normalize().scale(0.0045000000000000005);
+ }
+
+ this.setDeltaMovement(this.getDeltaMovement().add(vec3));
+ }
+
+ this.fluidHeight.put(fluidTag, d);
+ return flag;
+ }
+ }
+ // Leaves end - vanilla fluid pushing
+
// Paper start - optimise collisions
public boolean updateFluidHeightAndDoFluidPushing(final TagKey<Fluid> fluid, final double flowScale) {
+ // Leaves start - vanilla fluid pushing
+ if (org.leavesmc.leaves.LeavesConfig.fix.vanillaFluidPushing) {
+ return vanillaUpdateFluidHeightAndDoFluidPushing(fluid, flowScale);
+ }
+ // Leaves end - vanilla fluid pushing
if (this.touchingUnloadedChunk()) {
return false;
}

View File

@@ -1124,6 +1124,9 @@ public final class LeavesConfig {
@GlobalConfig("vanilla-portal-handle")
public boolean vanillaPortalHandle = false;
@GlobalConfig("vanilla-fluid-pushing")
public boolean vanillaFluidPushing = false;
@RemovedConfig(name = "collision-behavior", category = "fix")
@RemovedConfig(name = "spigot-EndPlatform-destroy", category = "fix")
private final boolean removed = false;