9
0
mirror of https://github.com/LeavesMC/Leaves.git synced 2025-12-19 14:59:32 +00:00
Files
LeavesMC/leaves-server/minecraft-patches/features/0126-Vanilla-Fluid-Pushing.patch
2025-08-16 22:08:16 +08:00

94 lines
4.0 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Fortern <blueten.ki@gmail.com>
Date: Thu, 19 Jun 2025 00:49:24 +0800
Subject: [PATCH] Vanilla Fluid Pushing
diff --git a/net/minecraft/world/entity/Entity.java b/net/minecraft/world/entity/Entity.java
index fadce8b3073dc67534a4830b40fc2e84fdbd687b..e5f1939c9f998e56a5b99ab8319315e3645535ea 100644
--- a/net/minecraft/world/entity/Entity.java
+++ b/net/minecraft/world/entity/Entity.java
@@ -4729,8 +4729,82 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess
return Mth.lerp(partialTick, this.yRotO, this.yRot);
}
+ // 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;
}