Created
February 18, 2021 22:07
-
-
Save Lanse505/1c3fda9c6f3783708068f2b1f1e64b3e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* TODO: Clean-up Javadocs | |
* Default Implementation mimicking water. | |
* | |
* @param entity Entity whose motion is being scaled. | |
* @param motionScale The motion scale. | |
* @return Returns if it could scale the motion. | |
*/ | |
default boolean handleFluidAcceleration(FluidState state, Entity entity, double motionScale) { | |
AxisAlignedBB axisalignedbb = entity.getBoundingBox().shrink(0.001D); | |
int i = MathHelper.floor(axisalignedbb.minX); | |
int j = MathHelper.ceil(axisalignedbb.maxX); | |
int k = MathHelper.floor(axisalignedbb.minY); | |
int l = MathHelper.ceil(axisalignedbb.maxY); | |
int i1 = MathHelper.floor(axisalignedbb.minZ); | |
int j1 = MathHelper.ceil(axisalignedbb.maxZ); | |
if (!entity.world.isAreaLoaded(i, k, i1, j, l, j1)) { | |
return false; | |
} else { | |
double d0 = 0.0D; | |
boolean flag = entity.isPushedByWater(); | |
boolean flag1 = false; | |
Vector3d vector3d = Vector3d.ZERO; | |
int k1 = 0; | |
BlockPos.Mutable blockpos$mutable = new BlockPos.Mutable(); | |
for (int l1 = i; l1 < j; ++l1) { | |
for (int i2 = k; i2 < l; ++i2) { | |
for (int j2 = i1; j2 < j1; ++j2) { | |
blockpos$mutable.setPos(l1, i2, j2); | |
double d1 = (float) i2 + state.getActualHeight(entity.world, blockpos$mutable); | |
if (d1 >= axisalignedbb.minY) { | |
flag1 = true; | |
d0 = Math.max(d1 - axisalignedbb.minY, d0); | |
if (flag) { | |
Vector3d vector3d1 = state.getFlow(entity.world, blockpos$mutable); | |
if (d0 < 0.4D) { | |
vector3d1 = vector3d1.scale(d0); | |
} | |
vector3d = vector3d.add(vector3d1); | |
++k1; | |
} | |
} | |
} | |
} | |
} | |
if (vector3d.length() > 0.0D) { | |
if (k1 > 0) { | |
vector3d = vector3d.scale(1.0D / (double) k1); | |
} | |
if (!(this instanceof PlayerEntity)) { | |
vector3d = vector3d.normalize(); | |
} | |
Vector3d vector3d2 = entity.getMotion(); | |
vector3d = vector3d.scale(motionScale * 1.0D); | |
double d2 = 0.003D; | |
if (Math.abs(vector3d2.x) < d2 && Math.abs(vector3d2.z) < d2 && vector3d.length() < 0.0045000000000000005D) { | |
vector3d = vector3d.normalize().scale(0.0045000000000000005D); | |
} | |
entity.setMotion(entity.getMotion().add(vector3d)); | |
} | |
entity.fluidInsideOf = entity.world.getFluidState(entity.getPosition()); | |
return flag1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment