Some more porting/water movement work

Still broken, things are in an arbitrary state (debug prints left in, etc)
This commit is contained in:
Ryan Liptak 2020-11-02 17:22:57 -08:00
parent 0da195ebb5
commit 1e07dbda1c
10 changed files with 187 additions and 157 deletions

View File

@ -1,5 +1,5 @@
plugins { plugins {
id 'fabric-loom' version '0.2.5-SNAPSHOT' id 'fabric-loom' version '0.4-SNAPSHOT'
} }
sourceCompatibility = JavaVersion.VERSION_1_8 sourceCompatibility = JavaVersion.VERSION_1_8
@ -8,21 +8,15 @@ targetCompatibility = JavaVersion.VERSION_1_8
archivesBaseName = project.archives_base_name archivesBaseName = project.archives_base_name
group = project.maven_group group = project.maven_group
minecraft {
}
sourceSets.main.java.srcDirs += 'java' sourceSets.main.java.srcDirs += 'java'
sourceSets.main.resources.srcDirs += 'resources' sourceSets.main.resources.srcDirs += 'resources'
dependencies { dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}" minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modCompile "net.fabricmc:fabric-loader:${project.loader_version}" modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation "net.fabricmc.fabric-api:fabric-api-base:+" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
include "net.fabricmc.fabric-api:fabric-api-base:+"
modImplementation "net.fabricmc.fabric-api:fabric-keybindings-v0:+"
include "net.fabricmc.fabric-api:fabric-keybindings-v0:+"
} }
processResources { processResources {

View File

@ -3,10 +3,14 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/use # check these on https://fabricmc.net/use
minecraft_version=1.14.4 minecraft_version=1.16.1
yarn_mappings=1.14.4+build.5 yarn_mappings=1.16.1+build.1
loader_version=0.4.8+build.159 loader_version=0.8.8+build.202
# Mod Properties # Mod Properties
maven_group = squeek.quakemovement maven_group = squeek.quakemovement
archives_base_name = squake archives_base_name = squake
# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_version=0.13.1+build.370-1.16

Binary file not shown.

View File

@ -1,6 +1,5 @@
#Mon Aug 22 17:36:22 EDT 2016
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-bin.zip

68
gradlew vendored
View File

@ -1,4 +1,20 @@
#!/usr/bin/env bash #!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################################## ##############################################################################
## ##
@ -28,16 +44,16 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"` APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS="" DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum" MAX_FD="maximum"
warn ( ) { warn () {
echo "$*" echo "$*"
} }
die ( ) { die () {
echo echo
echo "$*" echo "$*"
echo echo
@ -109,8 +125,8 @@ if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi fi
# For Cygwin, switch paths to Windows format before running java # For Cygwin or MSYS, switch paths to Windows format before running java
if $cygwin ; then if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"` JAVACMD=`cygpath --unix "$JAVACMD"`
@ -138,32 +154,30 @@ if $cygwin ; then
else else
eval `echo args$i`="\"$arg\"" eval `echo args$i`="\"$arg\""
fi fi
i=$((i+1)) i=`expr $i + 1`
done done
case $i in case $i in
(0) set -- ;; 0) set -- ;;
(1) set -- "$args0" ;; 1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;; 2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;; 3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;; 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac esac
fi fi
# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules # Escape application args
function splitJvmOpts() { save () {
JVM_OPTS=("$@") for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
} }
eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS APP_ARGS=`save "$@"`
JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong # Collect all arguments for the java command, following the shell quoting and substitution rules
if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
cd "$(dirname "$0")"
fi
exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" exec "$JAVACMD" "$@"

21
gradlew.bat vendored
View File

@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@ -13,8 +29,11 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS= set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome

View File

@ -3,6 +3,7 @@ package squeek.quakemovement;
import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.platform.GlStateManager;
import net.fabricmc.api.ModInitializer; import net.fabricmc.api.ModInitializer;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@ -18,16 +19,14 @@ public class ModQuakeMovement implements ModInitializer
return 0.6f; return 0.6f;
} }
public static void drawSpeedometer() public static void drawSpeedometer(MatrixStack matrixStack)
{ {
GlStateManager.pushMatrix();
MinecraftClient mc = MinecraftClient.getInstance(); MinecraftClient mc = MinecraftClient.getInstance();
PlayerEntity player = mc.player; PlayerEntity player = mc.player;
double deltaX = player.x - player.prevX; double deltaX = player.getX() - player.prevX;
double deltaZ = player.z - player.prevZ; double deltaZ = player.getZ() - player.prevZ;
double speed = MathHelper.sqrt(deltaX * deltaX + deltaZ * deltaZ); double speed = MathHelper.sqrt(deltaX * deltaX + deltaZ * deltaZ);
String speedString = String.format("%.02f", speed); String speedString = String.format("%.02f", speed);
mc.textRenderer.drawWithShadow(speedString, 10, mc.window.getScaledHeight() - mc.textRenderer.fontHeight - 10, 0xFFDDDDDD); mc.textRenderer.drawWithShadow(matrixStack, speedString, 10, mc.getWindow().getScaledHeight() - mc.textRenderer.fontHeight - 10, 0xFFDDDDDD);
GlStateManager.popMatrix();
} }
} }

View File

@ -1,18 +1,25 @@
package squeek.quakemovement; package squeek.quakemovement;
import com.sun.istack.internal.Nullable;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Material; import net.minecraft.block.Material;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.MovementType; import net.minecraft.entity.MovementType;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.Fluid;
import net.minecraft.fluid.FluidState;
import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.tag.FluidTags;
import net.minecraft.tag.Tag;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box; import net.minecraft.util.math.Box;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.WorldView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -32,9 +39,9 @@ public class QuakeClientPlayer
return false; return false;
boolean didQuakeMovement; boolean didQuakeMovement;
double d0 = player.x; double d0 = player.getX();
double d1 = player.y; double d1 = player.getY();
double d2 = player.z; double d2 = player.getZ();
if ((player.abilities.flying || player.isFallFlying()) && !player.hasVehicle()) if ((player.abilities.flying || player.isFallFlying()) && !player.hasVehicle())
return false; return false;
@ -42,8 +49,9 @@ public class QuakeClientPlayer
didQuakeMovement = quake_travel(player, movementInput); didQuakeMovement = quake_travel(player, movementInput);
if (didQuakeMovement) if (didQuakeMovement)
player.method_7282(player.x - d0, player.y - d1, player.z - d2); player.increaseTravelMotionStats(player.getX() - d0, player.getY() - d1, player.getZ() - d2);
System.out.println("didQuakeMovement: " + didQuakeMovement);
return didQuakeMovement; return didQuakeMovement;
} }
@ -66,6 +74,11 @@ public class QuakeClientPlayer
return updateVelocityPlayer((PlayerEntity) entity, movementInput, movementSpeed); return updateVelocityPlayer((PlayerEntity) entity, movementInput, movementSpeed);
} }
public static boolean isInWater(PlayerEntity player) {
FluidState fluidState = player.world.getFluidState(player.getBlockPos());
return player.isTouchingWater() && player.method_29920() && !player.canWalkOnFluid(fluidState.getFluid());
}
public static boolean updateVelocityPlayer(PlayerEntity player, Vec3d movementInput, float movementSpeed) public static boolean updateVelocityPlayer(PlayerEntity player, Vec3d movementInput, float movementSpeed)
{ {
if (!player.world.isClient) if (!player.world.isClient)
@ -74,7 +87,7 @@ public class QuakeClientPlayer
if (!ModConfig.ENABLED) if (!ModConfig.ENABLED)
return false; return false;
if ((player.abilities.flying && !player.hasVehicle()) || player.isInsideWater() || player.isInLava() || !player.abilities.flying) if ((player.abilities.flying && !player.hasVehicle()) || isInWater(player) || player.isInLava() || !player.abilities.flying)
{ {
return false; return false;
} }
@ -119,15 +132,21 @@ public class QuakeClientPlayer
return MathHelper.sqrt(velocity.x * velocity.x + velocity.z * velocity.z); return MathHelper.sqrt(velocity.x * velocity.x + velocity.z * velocity.z);
} }
/// Assumes the player is on the ground
private static Block getGroundBlock(PlayerEntity player)
{
// copied from Entity.getVelocityAffectingPos
BlockPos groundPos = new BlockPos(player.getX(), player.getBoundingBox().minY - 0.5000001D, player.getZ());
return player.world.getBlockState(groundPos).getBlock();
}
private static float getSurfaceFriction(PlayerEntity player) private static float getSurfaceFriction(PlayerEntity player)
{ {
float f2 = 1.0F; float f2 = 1.0F;
if (player.onGround) if (player.isOnGround())
{ {
BlockPos groundPos = new BlockPos(MathHelper.floor(player.x), MathHelper.floor(player.getBoundingBox().minY) - 1, MathHelper.floor(player.z)); f2 = 1.0F - getGroundBlock(player).getSlipperiness();
Block ground = player.world.getBlockState(groundPos).getBlock();
f2 = 1.0F - ground.getSlipperiness();
} }
return f2; return f2;
@ -136,13 +155,9 @@ public class QuakeClientPlayer
private static float getSlipperiness(PlayerEntity player) private static float getSlipperiness(PlayerEntity player)
{ {
float f2 = 0.91F; float f2 = 0.91F;
if (player.onGround) if (player.isOnGround())
{ {
f2 = 0.54600006F; f2 = getGroundBlock(player).getSlipperiness() * 0.91F;
BlockPos groundPos = new BlockPos(MathHelper.floor(player.x), MathHelper.floor(player.getBoundingBox().minY) - 1, MathHelper.floor(player.z));
Block ground = player.world.getBlockState(groundPos).getBlock();
f2 = ground.getSlipperiness() * 0.91F;
} }
return f2; return f2;
} }
@ -197,16 +212,16 @@ public class QuakeClientPlayer
private static void spawnBunnyhopParticles(PlayerEntity player, int numParticles) private static void spawnBunnyhopParticles(PlayerEntity player, int numParticles)
{ {
// taken from sprint // taken from sprint
int j = MathHelper.floor(player.x); int j = MathHelper.floor(player.getX());
int i = MathHelper.floor(player.y - 0.20000000298023224D - player.getHeightOffset()); int i = MathHelper.floor(player.getY() - 0.20000000298023224D - player.getHeightOffset());
int k = MathHelper.floor(player.z); int k = MathHelper.floor(player.getZ());
BlockState blockState = player.world.getBlockState(new BlockPos(j, i, k)); BlockState blockState = player.world.getBlockState(new BlockPos(j, i, k));
if (blockState.getRenderType() != BlockRenderType.INVISIBLE) if (blockState.getRenderType() != BlockRenderType.INVISIBLE)
{ {
for (int iParticle = 0; iParticle < numParticles; iParticle++) for (int iParticle = 0; iParticle < numParticles; iParticle++)
{ {
player.world.addParticle(new BlockStateParticleEffect(ParticleTypes.BLOCK, blockState), player.x + (random.nextFloat() - 0.5D) * player.getWidth(), player.y + 0.1D, player.z + (random.nextFloat() - 0.5D) * player.getWidth(), -player.getVelocity().x * 4.0D, 1.5D, -player.getVelocity().z * 4.0D); player.world.addParticle(new BlockStateParticleEffect(ParticleTypes.BLOCK, blockState), player.getX() + (random.nextFloat() - 0.5D) * player.getWidth(), player.getY() + 0.1D, player.getZ() + (random.nextFloat() - 0.5D) * player.getWidth(), -player.getVelocity().x * 4.0D, 1.5D, -player.getVelocity().z * 4.0D);
} }
} }
} }
@ -233,11 +248,18 @@ public class QuakeClientPlayer
private static void minecraft_ApplyGravity(PlayerEntity player) private static void minecraft_ApplyGravity(PlayerEntity player)
{ {
BlockPos pos = new BlockPos((int) player.x, (int) player.y, (int) player.z);
double velocityY = player.getVelocity().y; double velocityY = player.getVelocity().y;
if (player.world.isClient && !player.world.isBlockLoaded(pos))
// TODO: SLOW_FALLING
if (player.hasStatusEffect(StatusEffects.LEVITATION))
{ {
if (player.y > 0.0D) velocityY += (0.05D * (double) (player.getStatusEffect(StatusEffects.LEVITATION).getAmplifier() + 1) - velocityY) * 0.2D;
player.fallDistance = 0.0F;
}
else if (player.world.isClient && !player.world.isChunkLoaded(player.getBlockPos()))
{
if (player.getY() > 0.0D)
{ {
velocityY = -0.1D; velocityY = -0.1D;
} }
@ -246,7 +268,7 @@ public class QuakeClientPlayer
velocityY = 0.0D; velocityY = 0.0D;
} }
} }
else else if (!player.hasNoGravity())
{ {
// gravity // gravity
velocityY -= 0.08D; velocityY -= 0.08D;
@ -262,72 +284,10 @@ public class QuakeClientPlayer
player.setVelocity(player.getVelocity().multiply(momentumRetention, 1, momentumRetention)); player.setVelocity(player.getVelocity().multiply(momentumRetention, 1, momentumRetention));
} }
/*
private static void minecraft_ApplyLadderPhysics(PlayerEntity player)
{
if (player.canClimb())
{
float f5 = 0.15F;
if (player.velocityX < (-f5))
{
player.velocityX = (-f5);
}
if (player.velocityX > f5)
{
player.velocityX = f5;
}
if (player.velocityZ < (-f5))
{
player.velocityZ = (-f5);
}
if (player.velocityZ > f5)
{
player.velocityZ = f5;
}
player.fallDistance = 0.0F;
if (player.velocityY < -0.15D)
{
player.velocityY = -0.15D;
}
boolean flag = player.isSneaking();
if (flag && player.velocityY < 0.0D)
{
player.velocityY = 0.0D;
}
}
}
private static void minecraft_ClimbLadder(PlayerEntity player)
{
if (player.horizontalCollision && player.canClimb())
{
player.velocityY = 0.2D;
}
}
*/
private static void minecraft_SwingLimbsBasedOnMovement(PlayerEntity player) private static void minecraft_SwingLimbsBasedOnMovement(PlayerEntity player)
{ {
player.lastLimbDistance = player.limbDistance; // this got extracted out in the Minecraft code, so just use that
double d0 = player.x - player.prevX; player.method_29242(player, false);
double d1 = player.z - player.prevZ;
float f6 = MathHelper.sqrt(d0 * d0 + d1 * d1) * 4.0F;
if (f6 > 1.0F)
{
f6 = 1.0F;
}
player.limbDistance += (f6 - player.limbDistance) * 0.4F;
player.limbAngle += player.limbDistance;
} }
private static void minecraft_WaterMove(PlayerEntity player, Vec3d movementInput) private static void minecraft_WaterMove(PlayerEntity player, Vec3d movementInput)
@ -405,21 +365,28 @@ public class QuakeClientPlayer
{ {
return false; return false;
} }
else if (player.isInsideWater() && !player.abilities.flying) else if (isInWater(player))
{ {
// if (ModConfig.SHARKING_ENABLED) if (ModConfig.SHARKING_ENABLED)
// quake_WaterMove(player, (float) movementInput.x, (float) movementInput.y, (float) movementInput.z); {
// else // fall back to Minecraft movement when we're not sharking
// { if (!quake_WaterMove(player, (float) movementInput.x, (float) movementInput.y, (float) movementInput.z))
return false; {
// } System.out.println("actually falling back");
return false;
}
}
else
{
return false;
}
} }
else else
{ {
// get all relevant movement values // get all relevant movement values
float wishspeed = (movementInput.x != 0.0D || movementInput.z != 0.0D) ? quake_getMoveSpeed(player) : 0.0F; float wishspeed = (movementInput.x != 0.0D || movementInput.z != 0.0D) ? quake_getMoveSpeed(player) : 0.0F;
double[] wishdir = getMovementDirection(player, movementInput.x, movementInput.z); double[] wishdir = getMovementDirection(player, movementInput.x, movementInput.z);
boolean onGroundForReal = player.onGround && !isJumping(player); boolean onGroundForReal = player.isOnGround() && !isJumping(player);
float momentumRetention = getSlipperiness(player); float momentumRetention = getSlipperiness(player);
// ground movement // ground movement
@ -458,7 +425,7 @@ public class QuakeClientPlayer
if (ModConfig.SHARKING_ENABLED && ModConfig.SHARKING_SURFACE_TENSION > 0.0D && isJumping(player) && player.getVelocity().y < 0.0F) if (ModConfig.SHARKING_ENABLED && ModConfig.SHARKING_SURFACE_TENSION > 0.0D && isJumping(player) && player.getVelocity().y < 0.0F)
{ {
Box axisalignedbb = player.getBoundingBox().offset(player.getVelocity()); Box axisalignedbb = player.getBoundingBox().offset(player.getVelocity());
boolean isFallingIntoWater = player.world.containsBlockWithMaterial(axisalignedbb, Material.WATER); boolean isFallingIntoWater = containsFluid(player.world, axisalignedbb, FluidTags.WATER);
if (isFallingIntoWater) if (isFallingIntoWater)
player.setVelocity(player.getVelocity().multiply(1.0D, ModConfig.SHARKING_SURFACE_TENSION, 1.0D)); player.setVelocity(player.getVelocity().multiply(1.0D, ModConfig.SHARKING_SURFACE_TENSION, 1.0D));
@ -478,6 +445,30 @@ public class QuakeClientPlayer
return true; return true;
} }
// copied from WorldView.containsFluid but with the ability to specify the fluid
static private boolean containsFluid(WorldView world, Box box, Tag<Fluid> tag) {
int i = MathHelper.floor(box.minX);
int j = MathHelper.ceil(box.maxX);
int k = MathHelper.floor(box.minY);
int l = MathHelper.ceil(box.maxY);
int m = MathHelper.floor(box.minZ);
int n = MathHelper.ceil(box.maxZ);
BlockPos.Mutable mutable = new BlockPos.Mutable();
for(int o = i; o < j; ++o) {
for(int p = k; p < l; ++p) {
for(int q = m; q < n; ++q) {
BlockState blockState = world.getBlockState(mutable.set(o, p, q));
if (blockState.getFluidState().isIn(tag)) {
return true;
}
}
}
}
return false;
}
private static void quake_Jump(PlayerEntity player) private static void quake_Jump(PlayerEntity player)
{ {
quake_ApplySoftCap(player, quake_getMaxMoveSpeed(player)); quake_ApplySoftCap(player, quake_getMaxMoveSpeed(player));
@ -521,6 +512,7 @@ public class QuakeClientPlayer
private static void quake_ApplyWaterFriction(PlayerEntity player, double friction) private static void quake_ApplyWaterFriction(PlayerEntity player, double friction)
{ {
System.out.println("quake_ApplyWaterFriction");
player.setVelocity(player.getVelocity().multiply(friction)); player.setVelocity(player.getVelocity().multiply(friction));
/* /*
@ -564,23 +556,27 @@ public class QuakeClientPlayer
} }
} }
private static void quake_WaterMove(PlayerEntity player, float sidemove, float upmove, float forwardmove) private static boolean quake_WaterMove(PlayerEntity player, float sidemove, float upmove, float forwardmove)
{ {
double lastPosY = player.y; double lastPosY = player.getY();
// get all relevant movement values // get all relevant movement values
float wishspeed = (sidemove != 0.0F || forwardmove != 0.0F) ? quake_getMaxMoveSpeed(player) : 0.0F; float wishspeed = (sidemove != 0.0F || forwardmove != 0.0F) ? quake_getMaxMoveSpeed(player) : 0.0F;
double[] wishdir = getMovementDirection(player, sidemove, forwardmove); double[] wishdir = getMovementDirection(player, sidemove, forwardmove);
boolean isOffsetInLiquid = player.world.getBlockState(new BlockPos(player.x, player.y + 1.0D, player.z)).getFluidState().isEmpty(); boolean isOffsetInLiquid = player.world.getBlockState(new BlockPos(player.getX(), player.getY() + 1.0D, player.getZ())).getFluidState().isEmpty();
boolean isSharking = isJumping(player) && isOffsetInLiquid; boolean isSharking = isJumping(player) && isOffsetInLiquid;
double curspeed = getSpeed(player); double curspeed = getSpeed(player);
if (!isSharking || curspeed < 0.078F) if (!isSharking || curspeed < 0.078F)
{ {
minecraft_WaterMove(player, new Vec3d(sidemove, upmove, forwardmove)); System.out.println("not sharking, falling back to minecraft");
// fallback to Minecraft default movement
return false;
} }
else else
{ {
System.out.println("sharking");
if (curspeed > 0.09) if (curspeed > 0.09)
quake_ApplyWaterFriction(player, ModConfig.SHARKING_WATER_FRICTION); quake_ApplyWaterFriction(player, ModConfig.SHARKING_WATER_FRICTION);
@ -595,13 +591,14 @@ public class QuakeClientPlayer
} }
// water jump // water jump
if (player.horizontalCollision && player.doesNotCollide(player.getVelocity().x, player.getVelocity().y + 0.6000000238418579D - player.y + lastPosY, player.getVelocity().z)) if (player.horizontalCollision && player.doesNotCollide(player.getVelocity().x, player.getVelocity().y + 0.6000000238418579D - player.getY() + lastPosY, player.getVelocity().z))
{ {
player.setVelocity(player.getVelocity().x, 0.30000001192092896D, player.getVelocity().z); player.setVelocity(player.getVelocity().x, 0.30000001192092896D, player.getVelocity().z);
} }
if (!baseVelocities.isEmpty()) if (!baseVelocities.isEmpty())
{ {
System.out.println("has a base velocity");
float speedMod = wishspeed / quake_getMaxMoveSpeed(player); float speedMod = wishspeed / quake_getMaxMoveSpeed(player);
// add in base velocities // add in base velocities
for (double[] baseVel : baseVelocities) for (double[] baseVel : baseVelocities)
@ -609,6 +606,8 @@ public class QuakeClientPlayer
player.setVelocity(player.getVelocity().add(baseVel[0] * speedMod, 0, baseVel[1] * speedMod)); player.setVelocity(player.getVelocity().add(baseVel[0] * speedMod, 0, baseVel[1] * speedMod));
} }
} }
return true;
} }
private static void quake_Accelerate(PlayerEntity player, float wishspeed, double wishX, double wishZ, double accel) private static void quake_Accelerate(PlayerEntity player, float wishspeed, double wishX, double wishZ, double accel)

View File

@ -6,6 +6,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import squeek.quakemovement.ModConfig; import squeek.quakemovement.ModConfig;
import squeek.quakemovement.QuakeClientPlayer; import squeek.quakemovement.QuakeClientPlayer;
import squeek.quakemovement.QuakeServerPlayer; import squeek.quakemovement.QuakeServerPlayer;
@ -35,14 +36,14 @@ public abstract class PlayerEntityMixin
QuakeClientPlayer.afterJump((PlayerEntity) (Object) this); QuakeClientPlayer.afterJump((PlayerEntity) (Object) this);
} }
@Inject(at = @At("HEAD"), method = "handleFallDamage(FF)V") @Inject(at = @At("HEAD"), method = "handleFallDamage")
private void beforeFall(float fallDistance, float damageMultiplier, CallbackInfo info) private void beforeFall(float fallDistance, float damageMultiplier, CallbackInfoReturnable<Boolean> info)
{ {
QuakeServerPlayer.beforeFall((PlayerEntity) (Object) this, fallDistance, damageMultiplier); QuakeServerPlayer.beforeFall((PlayerEntity) (Object) this, fallDistance, damageMultiplier);
} }
@Inject(at = @At("TAIL"), method = "handleFallDamage(FF)V") @Inject(at = @At("TAIL"), method = "handleFallDamage")
private void afterFall(float fallDistance, float damageMultiplier, CallbackInfo info) private void afterFall(float fallDistance, float damageMultiplier, CallbackInfoReturnable<Boolean> info)
{ {
QuakeServerPlayer.afterFall((PlayerEntity) (Object) this, fallDistance, damageMultiplier); QuakeServerPlayer.afterFall((PlayerEntity) (Object) this, fallDistance, damageMultiplier);
} }

View File

@ -1,6 +1,7 @@
package squeek.quakemovement.mixin; package squeek.quakemovement.mixin;
import net.minecraft.client.gui.hud.InGameHud; import net.minecraft.client.gui.hud.InGameHud;
import net.minecraft.client.util.math.MatrixStack;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
@ -10,10 +11,10 @@ import squeek.quakemovement.ModQuakeMovement;
@Mixin(InGameHud.class) @Mixin(InGameHud.class)
public class TestSpeedometerMixin public class TestSpeedometerMixin
{ {
@Inject(at = @At("HEAD"), method = "renderStatusEffectOverlay()V") @Inject(at = @At("HEAD"), method = "renderStatusEffectOverlay")
private void renderStatusEffectOverlay(CallbackInfo info) private void renderStatusEffectOverlay(MatrixStack matrixStack, CallbackInfo info)
{ {
ModQuakeMovement.drawSpeedometer(); ModQuakeMovement.drawSpeedometer(matrixStack);
} }
} }