diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml new file mode 100644 index 0000000..7ebf7ed --- /dev/null +++ b/.github/workflows/gradle.yml @@ -0,0 +1,31 @@ +# This workflow will build a Java project with Gradle +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle + +name: Java CI with Gradle + +on: + push: + branches: [ master ] + pull_request: + branches: [ master ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 1.8 + - name: Grant execute permission for gradlew + run: chmod +x gradlew + - name: Build with Gradle + run: ./gradlew build + - name: Upload a Build Artifact + uses: actions/upload-artifact@v2 + with: + name: Artifacts + path: build/libs/ diff --git a/build.gradle b/build.gradle index 7cf8350..b8d2272 100644 --- a/build.gradle +++ b/build.gradle @@ -1,22 +1,39 @@ plugins { - id 'fabric-loom' version '0.4-SNAPSHOT' + id 'fabric-loom' version '0.5-SNAPSHOT' + id 'maven-publish' } sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 archivesBaseName = project.archives_base_name +version = project.mod_version group = project.maven_group sourceSets.main.java.srcDirs += 'java' sourceSets.main.resources.srcDirs += 'resources' +repositories { + maven { + name = "ModMenu" + url = "https://maven.terraformersmc.com/releases/" + } + maven { url "https://maven.shedaniel.me/" } +} + dependencies { minecraft "com.mojang:minecraft:${project.minecraft_version}" mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" - modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + modCompile "net.fabricmc:fabric-loader:${project.loader_version}" - modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}" + modApi("me.shedaniel.cloth:cloth-config:${project.cloth_version}:fabric") { + exclude(group: "net.fabricmc.fabric-api") + } + + implementation("me.shedaniel.cloth:basic-math:0.5.1") // Cloth Config's Packaging is strange + + modImplementation "com.terraformersmc:modmenu:${project.modmenu_version}" } processResources { diff --git a/gradle.properties b/gradle.properties index 28d7577..114a4f4 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,14 +3,15 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://fabricmc.net/use -minecraft_version=1.16.1 -yarn_mappings=1.16.1+build.1 -loader_version=0.8.8+build.202 +minecraft_version=1.16.5 +yarn_mappings=1.16.5+build.4 +loader_version=0.11.1 -# Mod Properties +mod_version = 2.0.0 maven_group = squeek.quakemovement 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 \ No newline at end of file +modmenu_version=1.16.7 +cloth_version=4.9.5 +autoconfig_version=3.2.0-unstable +fabric_api_version=0.30.0+1.16 \ No newline at end of file diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/java/squeek/quakemovement/KeyBindInitializer.java b/java/squeek/quakemovement/KeyBindInitializer.java index c701854..f5974ff 100644 --- a/java/squeek/quakemovement/KeyBindInitializer.java +++ b/java/squeek/quakemovement/KeyBindInitializer.java @@ -3,30 +3,18 @@ package squeek.quakemovement; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; -import net.fabricmc.fabric.api.client.keybinding.KeyBindingRegistry; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; +import net.minecraft.client.options.KeyBinding; import net.minecraft.client.util.InputUtil; -import net.minecraft.util.Identifier; import org.lwjgl.glfw.GLFW; @Environment(EnvType.CLIENT) -public class KeyBindInitializer implements ClientModInitializer -{ - public static FabricKeyBinding ENABLE; - public static String CATEGORY = "fabric.mods." + ModInfo.MODID; +public class KeyBindInitializer implements ClientModInitializer { + public static final String CATEGORY = "fabric.mods." + ModInfo.MODID; + public static final KeyBinding ENABLE = new KeyBinding(CATEGORY + "." + "enable", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, CATEGORY); @Override - public void onInitializeClient() - { - KeyBindingRegistry.INSTANCE.addCategory(CATEGORY); - ENABLE = registerKey("enable", GLFW.GLFW_KEY_UNKNOWN, CATEGORY); - } - - public static FabricKeyBinding registerKey(String name, Integer code, String category) - { - FabricKeyBinding key = FabricKeyBinding.Builder.create(new Identifier(ModInfo.MODID, name), InputUtil.Type.KEYSYM, code, category).build(); - KeyBindingRegistry.INSTANCE.register(key); - - return key; + public void onInitializeClient() { + KeyBindingHelper.registerKeyBinding(ENABLE); } } diff --git a/java/squeek/quakemovement/ModConfig.java b/java/squeek/quakemovement/ModConfig.java index 5d70fab..99ab73b 100644 --- a/java/squeek/quakemovement/ModConfig.java +++ b/java/squeek/quakemovement/ModConfig.java @@ -1,61 +1,114 @@ package squeek.quakemovement; -public class ModConfig -{ - public static final String CATEGORY_MOVEMENT = "movement"; +import me.shedaniel.autoconfig.AutoConfig; +import me.shedaniel.autoconfig.ConfigData; +import me.shedaniel.autoconfig.ConfigManager; +import me.shedaniel.autoconfig.annotation.Config; - private static final double TRIMP_MULTIPLIER_DEFAULT = 1.4D; - public static float TRIMP_MULTIPLIER = (float)TRIMP_MULTIPLIER_DEFAULT; - private static final String TRIMP_MULTIPLIER_NAME = "trimpMultiplier"; +@Config(name = "squake") +public class ModConfig implements ConfigData { - private static final double HARD_CAP_DEFAULT = 2.0D; - public static float HARD_CAP = (float)HARD_CAP_DEFAULT; - private static final String HARD_CAP_NAME = "hardCapThreshold"; + private SpeedometerPosition speedometerPosition = SpeedometerPosition.BOTTOM_LEFT; - private static final double SOFT_CAP_DEFAULT = 1.4D; - public static float SOFT_CAP = (float)SOFT_CAP_DEFAULT; - private static final String SOFT_CAP_NAME = "softCapThreshold"; + private float trimpMultiplier = 1.4f; - public static float SOFT_CAP_DEGEN; - private static final String SOFT_CAP_DEGEN_NAME = "softCapDegen"; - private static final double SOFT_CAP_DEGEN_DEFAULT = 0.65D; // 0.65 + private float hardCapThreshold = 2f; - private static final boolean SHARKING_ENABLED_DEFAULT = true; - public static boolean SHARKING_ENABLED = SHARKING_ENABLED_DEFAULT; - private static final String SHARKING_ENABLED_NAME = "sharkingEnabled"; + private float softCapThreshold = 1.4f; - private static final double SHARKING_SURFACE_TENSION_DEFAULT = 0.2D; - public static double SHARKING_SURFACE_TENSION = SHARKING_SURFACE_TENSION_DEFAULT; - private static final String SHARKING_SURFACE_TENSION_NAME = "sharkingSurfaceTension"; + private float softCapDegen = 0.65f; - private static final double SHARKING_WATER_FRICTION_DEFAULT = 0.1D; - public static double SHARKING_WATER_FRICTION = SHARKING_WATER_FRICTION_DEFAULT; - private static final String SHARKING_WATER_FRICTION_NAME = "sharkingWaterFriction"; + private boolean sharkingEnabled = true; - private static final double ACCELERATE_DEFAULT = 10.0D; - public static double ACCELERATE = ACCELERATE_DEFAULT; - private static final String ACCELERATE_NAME = "groundAccelerate"; + private double sharkingSurfaceTension = 0.2d; - private static final double AIR_ACCELERATE_DEFAULT = 14.0D; - public static double AIR_ACCELERATE = AIR_ACCELERATE_DEFAULT; - private static final String AIR_ACCELERATE_NAME = "airAccelerate"; + private double sharkingWaterFriction = 0.99d; - private static final boolean UNCAPPED_BUNNYHOP_ENABLED_DEFAULT = true; - public static boolean UNCAPPED_BUNNYHOP_ENABLED = UNCAPPED_BUNNYHOP_ENABLED_DEFAULT; - private static final String UNCAPPED_BUNNYHOP_ENABLED_NAME = "uncappedBunnyhopEnabled"; + private double groundAccelerate = 10d; - private static final boolean TRIMPING_ENABLED_DEFAULT = true; - public static boolean TRIMPING_ENABLED = TRIMPING_ENABLED_DEFAULT; - private static final String TRIMPING_ENABLED_NAME = "trimpEnabled"; + private double airAccelerate = 14d; - private static final double INCREASED_FALL_DISTANCE_DEFAULT = 0.0D; - public static double INCREASED_FALL_DISTANCE = INCREASED_FALL_DISTANCE_DEFAULT; - private static final String INCREASED_FALL_DISTANCE_NAME = "fallDistanceThresholdIncrease"; + private boolean uncappedBunnyhopEnabled = true; - private static final double MAX_AIR_ACCEL_PER_TICK_DEFAULT = 0.045D; - public static double MAX_AIR_ACCEL_PER_TICK = MAX_AIR_ACCEL_PER_TICK_DEFAULT; - private static final String MAX_AIR_ACCEL_PER_TICK_NAME = "maxAirAccelerationPerTick"; + private boolean trimpEnabled = true; + + private double fallDistanceThresholdIncrease = 0.0d; + + private double maxAirAccelerationPerTick = 0.045d; + + private boolean enabled = true; + + public enum SpeedometerPosition { + TOP_LEFT, + TOP_RIGHT, + BOTTOM_LEFT, + BOTTOM_RIGHT, + OFF + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + ((ConfigManager)AutoConfig.getConfigHolder(ModConfig.class)).save(); + } + + public SpeedometerPosition getSpeedometerPosition() { + return speedometerPosition; + } + + public float getTrimpMultiplier() { + return this.trimpMultiplier; + } + + public float getHardCapThreshold() { + return this.hardCapThreshold; + } + + public float getSoftCapThreshold() { + return this.softCapThreshold; + } + + public float getSoftCapDegen() { + return this.softCapDegen; + } + + public boolean isSharkingEnabled() { + return this.sharkingEnabled; + } + + public double getSharkingSurfaceTension() { + return this.sharkingSurfaceTension; + } + + public double getSharkingWaterFriction() { + return this.sharkingWaterFriction; + } + + public double getGroundAccelerate() { + return this.groundAccelerate; + } + + public double getAirAccelerate() { + return this.airAccelerate; + } + + public boolean isUncappedBunnyhopEnabled() { + return this.uncappedBunnyhopEnabled; + } + + public boolean isTrimpEnabled() { + return this.trimpEnabled; + } + + public double getFallDistanceThresholdIncrease() { + return this.fallDistanceThresholdIncrease; + } + + public double getMaxAirAccelerationPerTick() { + return this.maxAirAccelerationPerTick; + } + + public boolean isEnabled() { + return this.enabled; + } - private static final boolean ENABLED_DEFAULT = true; - public static boolean ENABLED = ENABLED_DEFAULT; } diff --git a/java/squeek/quakemovement/ModMenuIntegration.java b/java/squeek/quakemovement/ModMenuIntegration.java new file mode 100644 index 0000000..f5ed55d --- /dev/null +++ b/java/squeek/quakemovement/ModMenuIntegration.java @@ -0,0 +1,12 @@ +package squeek.quakemovement; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; +import me.shedaniel.autoconfig.AutoConfig; + +public class ModMenuIntegration implements ModMenuApi { + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return parent -> AutoConfig.getConfigScreen(ModConfig.class, parent).get(); + } +} \ No newline at end of file diff --git a/java/squeek/quakemovement/ModQuakeMovement.java b/java/squeek/quakemovement/ModQuakeMovement.java index aeadd27..de019ed 100644 --- a/java/squeek/quakemovement/ModQuakeMovement.java +++ b/java/squeek/quakemovement/ModQuakeMovement.java @@ -1,22 +1,27 @@ package squeek.quakemovement; import com.mojang.blaze3d.platform.GlStateManager; + +import me.shedaniel.autoconfig.AutoConfig; +import me.shedaniel.autoconfig.serializer.GsonConfigSerializer; import net.fabricmc.api.ModInitializer; import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.MathHelper; +import squeek.quakemovement.ModConfig.SpeedometerPosition; -public class ModQuakeMovement implements ModInitializer -{ - @Override - public void onInitialize() - { +public class ModQuakeMovement implements ModInitializer { + public static final ModConfig CONFIG; + + static { + AutoConfig.register(ModConfig.class, GsonConfigSerializer::new); + CONFIG = AutoConfig.getConfigHolder(ModConfig.class).getConfig(); } - public static float getFriction() - { - return 0.6f; + @Override + public void onInitialize() { + //Cause this class to be loaded so the config loads on startup } public static void drawSpeedometer(MatrixStack matrixStack) @@ -27,6 +32,20 @@ public class ModQuakeMovement implements ModInitializer double deltaZ = player.getZ() - player.prevZ; double speed = MathHelper.sqrt(deltaX * deltaX + deltaZ * deltaZ); String speedString = String.format("%.02f", speed); - mc.textRenderer.drawWithShadow(matrixStack, speedString, 10, mc.getWindow().getScaledHeight() - mc.textRenderer.fontHeight - 10, 0xFFDDDDDD); + int x; + int y; + if (CONFIG.getSpeedometerPosition() == SpeedometerPosition.BOTTOM_LEFT || CONFIG.getSpeedometerPosition() == SpeedometerPosition.TOP_LEFT) { + x = 10; + } else { + x = mc.getWindow().getScaledWidth() - mc.textRenderer.getWidth(speedString) - 10; + } + if (CONFIG.getSpeedometerPosition() == SpeedometerPosition.TOP_RIGHT || CONFIG.getSpeedometerPosition() == SpeedometerPosition.TOP_LEFT) { + y = 10; + } else { + y = mc.getWindow().getScaledHeight() - mc.textRenderer.fontHeight - 10; + } + GlStateManager.pushMatrix(); + mc.textRenderer.drawWithShadow(matrixStack, speedString, x, y, 0xFFDDDDDD); + GlStateManager.popMatrix(); } } \ No newline at end of file diff --git a/java/squeek/quakemovement/QuakeClientPlayer.java b/java/squeek/quakemovement/QuakeClientPlayer.java index 18652ae..8513eb6 100644 --- a/java/squeek/quakemovement/QuakeClientPlayer.java +++ b/java/squeek/quakemovement/QuakeClientPlayer.java @@ -1,41 +1,41 @@ package squeek.quakemovement; -import com.sun.istack.internal.Nullable; import net.minecraft.block.Block; import net.minecraft.block.BlockRenderType; import net.minecraft.block.BlockState; -import net.minecraft.block.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.MovementType; import net.minecraft.entity.effect.StatusEffects; 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.ParticleTypes; -import net.minecraft.tag.FluidTags; -import net.minecraft.tag.Tag; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; -import net.minecraft.world.WorldView; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.world.World; import java.util.ArrayList; import java.util.List; import java.util.Random; +import org.apache.commons.lang3.mutable.MutableBoolean; + public class QuakeClientPlayer { + private QuakeClientPlayer(){} + private static Random random = new Random(); - private static List baseVelocities = new ArrayList(); + private static List baseVelocities = new ArrayList<>(); public static boolean travel(PlayerEntity player, Vec3d movementInput) { if (!player.world.isClient) return false; - if (!ModConfig.ENABLED) + if (!ModQuakeMovement.CONFIG.isEnabled()) return false; boolean didQuakeMovement; @@ -51,7 +51,6 @@ public class QuakeClientPlayer if (didQuakeMovement) player.increaseTravelMotionStats(player.getX() - d0, player.getY() - d1, player.getZ() - d2); - System.out.println("didQuakeMovement: " + didQuakeMovement); return didQuakeMovement; } @@ -74,20 +73,15 @@ public class QuakeClientPlayer 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) { if (!player.world.isClient) return false; - if (!ModConfig.ENABLED) + if (!ModQuakeMovement.CONFIG.isEnabled()) return false; - if ((player.abilities.flying && !player.hasVehicle()) || isInWater(player) || player.isInLava() || !player.abilities.flying) + if ((player.abilities.flying && !player.hasVehicle()) || player.isTouchingWater() || player.isInLava() || !player.abilities.flying) { return false; } @@ -107,7 +101,7 @@ public class QuakeClientPlayer if (!player.world.isClient) return; - if (!ModConfig.ENABLED) + if (!ModQuakeMovement.CONFIG.isEnabled()) return; // undo this dumb thing @@ -132,21 +126,15 @@ public class QuakeClientPlayer 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) { float f2 = 1.0F; if (player.isOnGround()) { - f2 = 1.0F - getGroundBlock(player).getSlipperiness(); + BlockPos groundPos = new BlockPos(MathHelper.floor(player.getX()), MathHelper.floor(player.getBoundingBox().minY) - 1, MathHelper.floor(player.getZ())); + Block ground = player.world.getBlockState(groundPos).getBlock(); + f2 = 1.0F - ground.getSlipperiness(); } return f2; @@ -157,7 +145,10 @@ public class QuakeClientPlayer float f2 = 0.91F; if (player.isOnGround()) { - f2 = getGroundBlock(player).getSlipperiness() * 0.91F; + BlockPos groundPos = new BlockPos(MathHelper.floor(player.getX()), MathHelper.floor(player.getBoundingBox().minY) - 1, MathHelper.floor(player.getZ())); + Block ground = player.world.getBlockState(groundPos).getBlock(); + + f2 = ground.getSlipperiness() * 0.91F; } return f2; } @@ -236,6 +227,24 @@ public class QuakeClientPlayer return ((IsJumpingGetter) player).isJumping(); } + private static boolean isInWater(Box box, World world) { + return BlockPos.stream(box).anyMatch(pos -> { + FluidState fluidState = world.getFluidState(pos); + return intersects(fluidState.getShape(world, pos), box); + }); + } + + public static boolean intersects(VoxelShape shape, Box box) { + if (shape.isEmpty()) return false; + MutableBoolean result = new MutableBoolean(false); + shape.forEachBox((minX, minY, minZ, maxX, maxY, maxZ) -> { + if (box.intersects(minX, minY, minZ, maxX, maxY, maxZ)) { + result.setTrue(); + } + }); + return result.booleanValue(); + } + /* ================================================= * END HELPERS * ================================================= @@ -248,16 +257,15 @@ public class QuakeClientPlayer private static void minecraft_ApplyGravity(PlayerEntity player) { + BlockPos pos = new BlockPos((int) player.getX(), (int) player.getY(), (int) player.getZ()); double velocityY = player.getVelocity().y; - - // TODO: SLOW_FALLING - - if (player.hasStatusEffect(StatusEffects.LEVITATION)) - { - velocityY += (0.05D * (double) (player.getStatusEffect(StatusEffects.LEVITATION).getAmplifier() + 1) - velocityY) * 0.2D; + if (player.hasStatusEffect(StatusEffects.LEVITATION)) { + velocityY += (0.05D * (double)(player.getStatusEffect(StatusEffects.LEVITATION).getAmplifier() + 1) - /*vec3d6.y*/ velocityY) * 0.2D; player.fallDistance = 0.0F; - } - else if (player.world.isClient && !player.world.isChunkLoaded(player.getBlockPos())) + } else if (player.hasStatusEffect(StatusEffects.SLOW_FALLING) && velocityY < 0) { + velocityY = -0.01D; + player.fallDistance = 0.0F; + } else if (player.world.isClient && !player.world.isChunkLoaded(pos)) { if (player.getY() > 0.0D) { @@ -268,7 +276,7 @@ public class QuakeClientPlayer velocityY = 0.0D; } } - else if (!player.hasNoGravity()) + else { // gravity velocityY -= 0.08D; @@ -286,59 +294,36 @@ public class QuakeClientPlayer private static void minecraft_SwingLimbsBasedOnMovement(PlayerEntity player) { - // this got extracted out in the Minecraft code, so just use that - player.method_29242(player, false); + player.lastLimbDistance = player.limbDistance; + double d0 = player.getX() - player.prevX; + double d1 = player.getZ() - 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) { - // double d0 = player.y; - // player.updateVelocity(0.04F, movementInput); - // player.move(MovementType.SELF, player.getVelocity()); - // Vec3d velocity = player.getVelocity().multiply(0.800000011920929D).add(0, 0.02D, 0); - // player.setVelocity(velocity); - // - // if (player.horizontalCollision && player.method_5654(velocity.x, velocity.y + 0.6000000238418579D - player.y + d0, velocity.z)) - // { - // player.setVelocity(velocity.x, 0.30000001192092896D, velocity.z); - // } - } - - /* - public static void minecraft_moveEntityWithHeading(PlayerEntity player, float sidemove, float upmove, float forwardmove) - { - // take care of water and lava movement using default code - if ((player.isInWater() && !player.abilities.flying) - || (player.isTouchingLava() && !player.abilities.flying)) - { - player.travel(sidemove, upmove, forwardmove); + double d0 = player.getY(); + player.updateVelocity(0.04F, movementInput); + player.move(MovementType.SELF, player.getVelocity()); + Vec3d velocity = player.getVelocity().multiply(0.800000011920929D); + if (!player.isSwimming()) { + velocity = velocity.add(0, -0.01, 0); } - else + player.setVelocity(velocity); + + if (player.horizontalCollision && player.doesNotCollide(velocity.x, velocity.y + 0.6000000238418579D - player.getY() + d0, velocity.z)) { - // get friction - float momentumRetention = getSlipperiness(player); - - // alter motionX/motionZ based on desired movement - player.moveRelative(sidemove, upmove, forwardmove, minecraft_getMoveSpeed(player)); - - // make adjustments for ladder interaction - minecraft_ApplyLadderPhysics(player); - - // do the movement - player.move(MovementType.field_6308, player.velocityX, player.velocityY, player.velocityZ); - - // climb ladder here for some reason - minecraft_ClimbLadder(player); - - // gravity + friction - minecraft_ApplyGravity(player); - minecraft_ApplyFriction(player, momentumRetention); - - // swing them arms - minecraft_SwingLimbsBasedOnMovement(player); + player.setVelocity(velocity.x, 0.30000001192092896D, velocity.z); } } - */ /* ================================================= * END MINECRAFT PHYSICS @@ -365,17 +350,10 @@ public class QuakeClientPlayer { return false; } - else if (isInWater(player)) + else if (player.isTouchingWater() && !player.abilities.flying) { - if (ModConfig.SHARKING_ENABLED) - { - // fall back to Minecraft movement when we're not sharking - if (!quake_WaterMove(player, (float) movementInput.x, (float) movementInput.y, (float) movementInput.z)) - { - System.out.println("actually falling back"); - return false; - } - } + if (ModQuakeMovement.CONFIG.isSharkingEnabled()) + quake_WaterMove(player, (float) movementInput.x, (float) movementInput.y, (float) movementInput.z); else { return false; @@ -396,7 +374,7 @@ public class QuakeClientPlayer //quake_Friction(); // buggy because material-based friction uses a totally different format minecraft_ApplyFriction(player, momentumRetention); - double sv_accelerate = ModConfig.ACCELERATE; + double sv_accelerate = ModQuakeMovement.CONFIG.getGroundAccelerate(); if (wishspeed != 0.0F) { @@ -419,16 +397,17 @@ public class QuakeClientPlayer // air movement else { - double sv_airaccelerate = ModConfig.AIR_ACCELERATE; + double sv_airaccelerate = ModQuakeMovement.CONFIG.getAirAccelerate(); quake_AirAccelerate(player, wishspeed, wishdir[0], wishdir[1], sv_airaccelerate); - if (ModConfig.SHARKING_ENABLED && ModConfig.SHARKING_SURFACE_TENSION > 0.0D && isJumping(player) && player.getVelocity().y < 0.0F) + if (ModQuakeMovement.CONFIG.isSharkingEnabled() && ModQuakeMovement.CONFIG.getSharkingSurfaceTension() > 0.0D && isJumping(player) && player.getVelocity().y < 0.0F) { Box axisalignedbb = player.getBoundingBox().offset(player.getVelocity()); - boolean isFallingIntoWater = containsFluid(player.world, axisalignedbb, FluidTags.WATER); + boolean isFallingIntoWater = isInWater(axisalignedbb, player.world); - if (isFallingIntoWater) - player.setVelocity(player.getVelocity().multiply(1.0D, ModConfig.SHARKING_SURFACE_TENSION, 1.0D)); + if (isFallingIntoWater) { + player.setVelocity(player.getVelocity().multiply(1.0D, ModQuakeMovement.CONFIG.getSharkingSurfaceTension(), 1.0D)); + } } } @@ -445,30 +424,6 @@ public class QuakeClientPlayer return true; } - // copied from WorldView.containsFluid but with the ability to specify the fluid - static private boolean containsFluid(WorldView world, Box box, Tag 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) { quake_ApplySoftCap(player, quake_getMaxMoveSpeed(player)); @@ -483,7 +438,7 @@ public class QuakeClientPlayer private static boolean quake_DoTrimp(PlayerEntity player) { - if (ModConfig.TRIMPING_ENABLED && player.isSneaking()) + if (ModQuakeMovement.CONFIG.isTrimpEnabled() && player.isSneaking()) { double curspeed = getSpeed(player); float movespeed = quake_getMaxMoveSpeed(player); @@ -493,11 +448,11 @@ public class QuakeClientPlayer if (speedbonus > 1.0F) speedbonus = 1.0F; - player.setVelocity(player.getVelocity().add(0, speedbonus * curspeed * ModConfig.TRIMP_MULTIPLIER, 0)); + player.setVelocity(player.getVelocity().add(0, speedbonus * curspeed * ModQuakeMovement.CONFIG.getTrimpMultiplier(), 0)); - if (ModConfig.TRIMP_MULTIPLIER > 0) + if (ModQuakeMovement.CONFIG.getTrimpMultiplier() > 0) { - float mult = 1.0f / ModConfig.TRIMP_MULTIPLIER; + float mult = 1.0f / ModQuakeMovement.CONFIG.getTrimpMultiplier(); player.setVelocity(player.getVelocity().multiply(mult, 1, mult)); } @@ -512,31 +467,7 @@ public class QuakeClientPlayer private static void quake_ApplyWaterFriction(PlayerEntity player, double friction) { - System.out.println("quake_ApplyWaterFriction"); player.setVelocity(player.getVelocity().multiply(friction)); - - /* - float speed = (float)(player.getSpeed()); - float newspeed = 0.0F; - if (speed != 0.0F) - { - newspeed = speed - 0.05F * speed * friction; //* player->m_surfaceFriction; - - float mult = newspeed/speed; - player.velocityX *= mult; - player.velocityY *= mult; - player.velocityZ *= mult; - } - - return newspeed; - */ - - /* - // slow in water - player.velocityX *= 0.800000011920929D; - player.velocityY *= 0.800000011920929D; - player.velocityZ *= 0.800000011920929D; - */ } @SuppressWarnings("unused") @@ -556,7 +487,7 @@ public class QuakeClientPlayer } } - private static boolean quake_WaterMove(PlayerEntity player, float sidemove, float upmove, float forwardmove) + private static void quake_WaterMove(PlayerEntity player, float sidemove, float upmove, float forwardmove) { double lastPosY = player.getY(); @@ -569,25 +500,26 @@ public class QuakeClientPlayer if (!isSharking || curspeed < 0.078F) { - System.out.println("not sharking, falling back to minecraft"); - // fallback to Minecraft default movement - return false; + minecraft_WaterMove(player, new Vec3d(sidemove, upmove, forwardmove)); } else { - System.out.println("sharking"); - if (curspeed > 0.09) - quake_ApplyWaterFriction(player, ModConfig.SHARKING_WATER_FRICTION); + quake_ApplyWaterFriction(player, ModQuakeMovement.CONFIG.getSharkingWaterFriction()); if (curspeed > 0.098) - quake_AirAccelerate(player, wishspeed, wishdir[0], wishdir[1], ModConfig.ACCELERATE); + quake_AirAccelerate(player, wishspeed, wishdir[0], wishdir[1], ModQuakeMovement.CONFIG.getGroundAccelerate()); else - quake_Accelerate(player, .0980F, wishdir[0], wishdir[1], ModConfig.ACCELERATE); + quake_Accelerate(player, .0980F, wishdir[0], wishdir[1], ModQuakeMovement.CONFIG.getGroundAccelerate()); player.move(MovementType.SELF, player.getVelocity()); player.setVelocity(player.getVelocity().x, 0, player.getVelocity().z); + Box axisalignedbb = player.getBoundingBox().offset(player.getVelocity()); + BlockPos.stream(axisalignedbb).forEach(pos -> { + FluidState fluidState = player.world.getFluidState(pos); + player.setVelocity(player.getVelocity().add(fluidState.getVelocity(player.world, pos).multiply(0.002))); + }); } // water jump @@ -598,7 +530,6 @@ public class QuakeClientPlayer if (!baseVelocities.isEmpty()) { - System.out.println("has a base velocity"); float speedMod = wishspeed / quake_getMaxMoveSpeed(player); // add in base velocities for (double[] baseVel : baseVelocities) @@ -606,8 +537,6 @@ public class QuakeClientPlayer 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) @@ -641,7 +570,7 @@ public class QuakeClientPlayer double addspeed, accelspeed, currentspeed; float wishspd = wishspeed; - float maxAirAcceleration = (float) ModConfig.MAX_AIR_ACCEL_PER_TICK; + float maxAirAcceleration = (float) ModQuakeMovement.CONFIG.getMaxAirAccelerationPerTick(); if (wishspd > maxAirAcceleration) wishspd = maxAirAcceleration; @@ -717,10 +646,10 @@ public class QuakeClientPlayer private static void quake_ApplySoftCap(PlayerEntity player, float movespeed) { - float softCapPercent = ModConfig.SOFT_CAP; - float softCapDegen = ModConfig.SOFT_CAP_DEGEN; + float softCapPercent = ModQuakeMovement.CONFIG.getSoftCapThreshold(); + float softCapDegen = ModQuakeMovement.CONFIG.getSoftCapDegen(); - if (ModConfig.UNCAPPED_BUNNYHOP_ENABLED) + if (ModQuakeMovement.CONFIG.isUncappedBunnyhopEnabled()) { softCapPercent = 1.0F; softCapDegen = 1.0F; @@ -745,10 +674,10 @@ public class QuakeClientPlayer private static void quake_ApplyHardCap(PlayerEntity player, float movespeed) { - if (ModConfig.UNCAPPED_BUNNYHOP_ENABLED) + if (ModQuakeMovement.CONFIG.isUncappedBunnyhopEnabled()) return; - float hardCapPercent = ModConfig.HARD_CAP; + float hardCapPercent = ModQuakeMovement.CONFIG.getHardCapThreshold(); float speed = (float) (getSpeed(player)); float hardCap = movespeed * hardCapPercent; diff --git a/java/squeek/quakemovement/QuakeServerPlayer.java b/java/squeek/quakemovement/QuakeServerPlayer.java deleted file mode 100644 index 82cb325..0000000 --- a/java/squeek/quakemovement/QuakeServerPlayer.java +++ /dev/null @@ -1,26 +0,0 @@ -package squeek.quakemovement; - -import net.minecraft.entity.player.PlayerEntity; - -public class QuakeServerPlayer -{ - // we can get away with a single static variable here instead of a map - // because we only care about the state before it has any possibility of changing - private static boolean wasVelocityChangedBeforeFall = false; - - public static void beforeFall(PlayerEntity player, float fallDistance, float damageMultiplier) - { - if (player.world.isClient) - return; - - wasVelocityChangedBeforeFall = player.velocityModified; - } - - public static void afterFall(PlayerEntity player, float fallDistance, float damageMultiplier) - { - if (player.world.isClient) - return; - - player.velocityModified = wasVelocityChangedBeforeFall; - } -} diff --git a/java/squeek/quakemovement/mixin/EntityMixin.java b/java/squeek/quakemovement/mixin/EntityMixin.java deleted file mode 100644 index 640286b..0000000 --- a/java/squeek/quakemovement/mixin/EntityMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package squeek.quakemovement.mixin; - -import net.minecraft.entity.Entity; -import net.minecraft.util.math.Vec3d; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import squeek.quakemovement.ModConfig; -import squeek.quakemovement.QuakeClientPlayer; - -@Mixin(Entity.class) -public abstract class EntityMixin -{ - @Inject(at = @At("HEAD"), method = "updateVelocity(FLnet/minecraft/util/math/Vec3d;)V", cancellable = true) - private void updateVelocity(float movementSpeed, Vec3d movementInput, CallbackInfo info) - { - if (!ModConfig.ENABLED) - return; - - if (QuakeClientPlayer.updateVelocity((Entity) (Object) this, movementInput, movementSpeed)) - info.cancel(); - } -} diff --git a/java/squeek/quakemovement/mixin/KeyPressMixin.java b/java/squeek/quakemovement/mixin/KeyPressMixin.java index 082baf0..bf739bf 100644 --- a/java/squeek/quakemovement/mixin/KeyPressMixin.java +++ b/java/squeek/quakemovement/mixin/KeyPressMixin.java @@ -1,27 +1,23 @@ package squeek.quakemovement.mixin; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.resource.language.I18n; +import net.minecraft.text.TranslatableText; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import squeek.quakemovement.KeyBindInitializer; -import squeek.quakemovement.ModConfig; -import squeek.quakemovement.ModInfo; +import squeek.quakemovement.ModQuakeMovement; @Mixin(MinecraftClient.class) public class KeyPressMixin { @Inject(method = "handleInputEvents", at=@At("HEAD")) - public void handleInputEvents(CallbackInfo info) - { - if (KeyBindInitializer.ENABLE.wasPressed()) - { - ModConfig.ENABLED = !ModConfig.ENABLED; - - String feedback = ModConfig.ENABLED ? I18n.translate("squake.key.toggle.enabled") : I18n.translate("squake.key.toggle.disabled"); - MinecraftClient.getInstance().player.sendChatMessage("[" + ModInfo.MODID + "] " + feedback); + public void handleInputEvents(CallbackInfo info) { + if (KeyBindInitializer.ENABLE.wasPressed()) { + ModQuakeMovement.CONFIG.setEnabled(!ModQuakeMovement.CONFIG.isEnabled()); + MinecraftClient.getInstance().player.sendMessage(ModQuakeMovement.CONFIG.isEnabled() ? new TranslatableText("squake.key.toggle.enabled") : new TranslatableText("squake.key.toggle.disabled"), true); } } } diff --git a/java/squeek/quakemovement/mixin/LivingEntityMixin.java b/java/squeek/quakemovement/mixin/LivingEntityMixin.java deleted file mode 100644 index 501e2a3..0000000 --- a/java/squeek/quakemovement/mixin/LivingEntityMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -package squeek.quakemovement.mixin; - -import net.minecraft.entity.LivingEntity; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import squeek.quakemovement.QuakeClientPlayer; - -@Mixin(LivingEntity.class) -public class LivingEntityMixin implements QuakeClientPlayer.IsJumpingGetter -{ - @Shadow - boolean jumping; - - @Override - public boolean isJumping() - { - return this.jumping; - } -} diff --git a/java/squeek/quakemovement/mixin/PlayerEntityMixin.java b/java/squeek/quakemovement/mixin/PlayerEntityMixin.java index f35c660..87409b3 100644 --- a/java/squeek/quakemovement/mixin/PlayerEntityMixin.java +++ b/java/squeek/quakemovement/mixin/PlayerEntityMixin.java @@ -1,23 +1,30 @@ package squeek.quakemovement.mixin; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.Vec3d; +import net.minecraft.world.World; + import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import squeek.quakemovement.ModConfig; +import squeek.quakemovement.ModQuakeMovement; import squeek.quakemovement.QuakeClientPlayer; -import squeek.quakemovement.QuakeServerPlayer; +import squeek.quakemovement.QuakeClientPlayer.IsJumpingGetter; @Mixin(PlayerEntity.class) -public abstract class PlayerEntityMixin -{ +public abstract class PlayerEntityMixin extends LivingEntity implements IsJumpingGetter { + private PlayerEntityMixin(EntityType entityType, World world) { + super(entityType, world); + } + @Inject(at = @At("HEAD"), method = "travel(Lnet/minecraft/util/math/Vec3d;)V", cancellable = true) private void travel(Vec3d movementInput, CallbackInfo info) { - if (!ModConfig.ENABLED) + if (!ModQuakeMovement.CONFIG.isEnabled()) return; if (QuakeClientPlayer.travel((PlayerEntity) (Object) this, movementInput)) @@ -36,15 +43,35 @@ public abstract class PlayerEntityMixin QuakeClientPlayer.afterJump((PlayerEntity) (Object) this); } - @Inject(at = @At("HEAD"), method = "handleFallDamage") - private void beforeFall(float fallDistance, float damageMultiplier, CallbackInfoReturnable info) - { - QuakeServerPlayer.beforeFall((PlayerEntity) (Object) this, fallDistance, damageMultiplier); + @Override + public void updateVelocity(float speed, Vec3d movementInput) { + if (!ModQuakeMovement.CONFIG.isEnabled() || !world.isClient) { + super.updateVelocity(speed, movementInput); + return; + } + + if (QuakeClientPlayer.updateVelocity(this, movementInput, speed)) { + return; + } + super.updateVelocity(speed, movementInput); } - @Inject(at = @At("TAIL"), method = "handleFallDamage") - private void afterFall(float fallDistance, float damageMultiplier, CallbackInfoReturnable info) + @Override + public boolean isJumping() { - QuakeServerPlayer.afterFall((PlayerEntity) (Object) this, fallDistance, damageMultiplier); + return this.jumping; + } + + //Fixes Fall Damage Negating Speed See: https://github.com/CoolMineman/Squake/commit/61c4622bca4209d60c7e7d61a59e5a5933ae844a#commitcomment-41109936 + boolean velocityHack = false; + + @Inject(at = @At("HEAD"), method = "handleFallDamage") + private void preHandleFallDamage(float fallDistance, float damageMultiplier, CallbackInfoReturnable info) { + velocityHack = velocityModified; + } + + @Inject(at = @At("RETURN"), method = "handleFallDamage") + private void postHandleFallDamage(float fallDistance, float damageMultiplier, CallbackInfoReturnable info) { + if (!world.isClient) velocityModified = velocityHack; } } diff --git a/java/squeek/quakemovement/mixin/TestBlockMixin.java b/java/squeek/quakemovement/mixin/TestBlockMixin.java deleted file mode 100644 index 7f6e228..0000000 --- a/java/squeek/quakemovement/mixin/TestBlockMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -package squeek.quakemovement.mixin; - -import net.minecraft.block.Block; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; -import squeek.quakemovement.ModQuakeMovement; - -@Mixin(Block.class) -public abstract class TestBlockMixin -{ -// @Overwrite -// public float getSlipperiness() { -// return ModQuakeMovement.getFriction(); -// } -} diff --git a/resources/assets/squake/lang/en_US.lang b/resources/assets/squake/lang/en_US.lang deleted file mode 100644 index 231358b..0000000 --- a/resources/assets/squake/lang/en_US.lang +++ /dev/null @@ -1,4 +0,0 @@ -# Keybinds -squake.key.toggle=Toggle Movement System On/Off -squake.key.toggle.enabled=Movement system enabled -squake.key.toggle.disabled=Movement system disabled \ No newline at end of file diff --git a/resources/assets/squake/lang/en_us.json b/resources/assets/squake/lang/en_us.json new file mode 100644 index 0000000..949ecbe --- /dev/null +++ b/resources/assets/squake/lang/en_us.json @@ -0,0 +1,24 @@ +{ + "text.autoconfig.squake.title": "Squake Options", + "text.autoconfig.squake.option.speedometerPosition": "Speedometer", + "text.autoconfig.squake.option.trimpMultiplier": "Trimp Multiplier", + "text.autoconfig.squake.option.hardCapThreshold": "Hard Cap Threshold", + "text.autoconfig.squake.option.softCapThreshold": "Soft Cap Threshold", + "text.autoconfig.squake.option.softCapDegen": "Soft Cap Degeneration", + "text.autoconfig.squake.option.sharkingEnabled": "Sharking Enabled", + "text.autoconfig.squake.option.sharkingSurfaceTension": "Sharking Surface Tension", + "text.autoconfig.squake.option.sharkingWaterFriction": "Sharking Water Friction", + "text.autoconfig.squake.option.groundAccelerate": "Ground Accelerate", + "text.autoconfig.squake.option.airAccelerate": "Air Accelerate", + "text.autoconfig.squake.option.uncappedBunnyhopEnabled": "Uncapped Bunny Hop Enabled", + "text.autoconfig.squake.option.trimpEnabled": "Trimp Enabled", + "text.autoconfig.squake.option.fallDistanceThresholdIncrease": "Fall Distance Threshold Increase", + "text.autoconfig.squake.option.maxAirAccelerationPerTick": "Max Air Acceleration Per Tick", + "text.autoconfig.squake.option.enabled": "Enabled", + + "fabric.mods.squake": "Squake", + "fabric.mods.squake.enable": "Toggle Squake Movement", + + "squake.key.toggle.enabled": "Squake Movement: Enabled", + "squake.key.toggle.disabled": "Squake Movement: Disabled" +} \ No newline at end of file diff --git a/resources/fabric.mod.json b/resources/fabric.mod.json index e41f1b3..b398732 100644 --- a/resources/fabric.mod.json +++ b/resources/fabric.mod.json @@ -6,7 +6,8 @@ "name": "Squake", "description": "Quake-style movement (bunnyhopping, etc) in Minecraft", "authors": [ - "squeek502" + "squeek502", + "ThatTrollzer/CoolMineman" ], "contact": { "sources": "https://github.com/squeek502/Squake" @@ -22,6 +23,9 @@ ], "client": [ "squeek.quakemovement.KeyBindInitializer" + ], + "modmenu" : [ + "squeek.quakemovement.ModMenuIntegration" ] }, "mixins": [ diff --git a/resources/squake.mixins.json b/resources/squake.mixins.json index 7d7649d..55ed824 100644 --- a/resources/squake.mixins.json +++ b/resources/squake.mixins.json @@ -3,12 +3,9 @@ "package": "squeek.quakemovement.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "PlayerEntityMixin", - "TestBlockMixin" + "PlayerEntityMixin" ], "client": [ - "LivingEntityMixin", - "EntityMixin", "KeyPressMixin", "TestSpeedometerMixin" ],