Skip to content

Commit

Permalink
Speed and bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Oct 2, 2022
1 parent 5669ebf commit 2c20501
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 29 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Significant improvements to the banking physics
- Hold W to go faster
- Hopefully fixed the world disappearing sometimes
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ minecraft_version=1.19
yarn_mappings=1.19+build.4
loader_version=0.14.8

mod_version = 1.3.1
mod_version = 1.3.2
maven_group = nl.enjarai
archives_base_name = do-a-barrel-roll

Expand Down
40 changes: 21 additions & 19 deletions src/main/java/nl/enjarai/doabarrelroll/DoABarrelRollClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class DoABarrelRollClient implements ClientModInitializer {
public static double landingLerp = 1;
public static Vec3d left;
public static Vec2f mouseTurnVec = Vec2f.ZERO;
public static double throttle = 0;


@Override
Expand Down Expand Up @@ -111,7 +112,7 @@ public static void onWorldRender(MinecraftClient client, float tickDelta, long l
if (client.player != null && landingLerp < 1) {

// calculate the camera angle and apply it
double angle = -Math.acos(left.dotProduct(ElytraMath.getAssumedLeft(client.player.getYaw()))) * ElytraMath.TODEG;
double angle = -Math.acos(MathHelper.clamp(left.dotProduct(ElytraMath.getAssumedLeft(client.player.getYaw())), -1, 1)) * ElytraMath.TODEG;
if (left.getY() < 0) angle *= -1;
matrix.multiply(Vec3f.POSITIVE_Z.getDegreesQuaternion((float) angle));

Expand All @@ -131,6 +132,7 @@ private static void clearValues() {
rollSmoother.clear();
mouseTurnVec = Vec2f.ZERO;
lastLookUpdate = GlfwUtil.getTime();
throttle = 0;
}

/**
Expand Down Expand Up @@ -164,6 +166,7 @@ public static void changeElytraLook(double pitch, double yaw, double roll, Sensi
var rotDelta = new RotationInstant(pitch, yaw, roll, delta);

ElytraMath.changeElytraLookDirectly(player, rotDelta
.useModifier(DoABarrelRollClient::manageThrottle)
.useModifier(DoABarrelRollClient::strafeButtons)
.applySensitivity(sensitivity)
.applyConfig(ModConfig.INSTANCE)
Expand Down Expand Up @@ -209,24 +212,23 @@ public static RotationInstant banking(RotationInstant rotationInstant) {
return rotationInstant.addAbsolute(dX * delta, dY * delta, currentRoll);
}

// public static RotationInstant yawBanking(RotationInstant rotationInstant) {
// if (!ModConfig.INSTANCE.enableBanking) return rotationInstant;
//
// var client = MinecraftClient.getInstance();
// var player = client.player;
// if (player == null) return rotationInstant;
//
// var delta = rotationInstant.getRenderDelta();
// var currentRoll = ElytraMath.getRoll(player.getYaw(), left) * ElytraMath.TORAD;
// var yawMod = Math.sin(currentRoll) * 10 * ModConfig.INSTANCE.bankingStrength * delta;
//
// // check if we accidentally got NaN, for some reason this happens sometimes
// if (Double.isNaN(yawMod)) {
// yawMod = 0;
// }
//
// return rotationInstant.add(0, yawMod, 0);
// }
public static RotationInstant manageThrottle(RotationInstant rotationInstant) {
var client = MinecraftClient.getInstance();

var delta = rotationInstant.getRenderDelta();

if (client.options.forwardKey.isPressed()) {
throttle += 0.1 * delta;
} else if (client.options.backKey.isPressed()) {
throttle -= 0.1 * delta;
} else {
throttle -= throttle * 0.95 * delta;
}

throttle = MathHelper.clamp(throttle, 0, ModConfig.INSTANCE.maxThrust);

return rotationInstant;
}

public static boolean isFallFlying() {
var player = MinecraftClient.getInstance().player;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/nl/enjarai/doabarrelroll/ElytraMath.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package nl.enjarai.doabarrelroll;

import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import nl.enjarai.doabarrelroll.config.RotationInstant;

Expand Down Expand Up @@ -79,7 +80,7 @@ public static Vec3d rotateAxisAngle(Vec3d v, Vec3d axis, double angle) {
}

public static double getRoll(float yaw, Vec3d left) {
double angle = -Math.acos(left.dotProduct(getAssumedLeft(yaw))) * TODEG;
double angle = -Math.acos(MathHelper.clamp(left.dotProduct(getAssumedLeft(yaw)), -1, 1)) * TODEG;
if (left.getY() < 0) angle *= -1;
return angle;
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/nl/enjarai/doabarrelroll/config/ModConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ public static void init() {

public float bankingStrength = 20;

@ConfigEntry.Gui.Tooltip(count = 4)
public boolean enableThrust = false;

@ConfigEntry.Gui.Tooltip
public float maxThrust = 1;

@ConfigEntry.Gui.CollapsibleObject
public Sensitivity desktopSensitivity = new Sensitivity();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity
method = "<init>(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/client/network/ClientPlayNetworkHandler;Lnet/minecraft/stat/StatHandler;Lnet/minecraft/client/recipebook/ClientRecipeBook;ZZ)V",
at = @At("RETURN")
)
public void init(MinecraftClient client, ClientWorld world, ClientPlayNetworkHandler networkHandler, StatHandler stats, ClientRecipeBook recipeBook, boolean lastSneaking, boolean lastSprinting, CallbackInfo ci) {
public void doABarrelRoll$init(MinecraftClient client, ClientWorld world, ClientPlayNetworkHandler networkHandler, StatHandler stats, ClientRecipeBook recipeBook, boolean lastSneaking, boolean lastSprinting, CallbackInfo ci) {
DoABarrelRollClient.left = ElytraMath.getAssumedLeft(getYaw());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public abstract class GameRendererMixin {
@Final @Shadow private MinecraftClient client;

@Inject(at = @At("HEAD"), method = "renderWorld")
public void renderWorld(float tickDelta, long limitTime, MatrixStack matrix, CallbackInfo ci) {
public void doABarrelRoll$renderWorld(float tickDelta, long limitTime, MatrixStack matrix, CallbackInfo ci) {
DoABarrelRollClient.onWorldRender(client, tickDelta, limitTime, matrix);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public abstract class InGameHudMixin extends DrawableHelper {
method = "renderCrosshair(Lnet/minecraft/client/util/math/MatrixStack;)V",
at = @At(value = "HEAD")
)
private void renderCrosshairHead(MatrixStack matrices, CallbackInfo ci) {
private void doABarrelRoll$renderCrosshairHead(MatrixStack matrices, CallbackInfo ci) {
matrices.push();
DoABarrelRollClient.onRenderCrosshair(matrices, scaledWidth, scaledHeight);
}
Expand All @@ -29,7 +29,7 @@ private void renderCrosshairHead(MatrixStack matrices, CallbackInfo ci) {
method = "renderCrosshair(Lnet/minecraft/client/util/math/MatrixStack;)V",
at = @At(value = "RETURN")
)
private void renderCrosshairReturn(MatrixStack matrices, CallbackInfo ci) {
private void doABarrelRoll$renderCrosshairReturn(MatrixStack matrices, CallbackInfo ci) {
matrices.pop();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package nl.enjarai.doabarrelroll.mixin;

import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import nl.enjarai.doabarrelroll.DoABarrelRollClient;
import nl.enjarai.doabarrelroll.config.ModConfig;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;

@Mixin(LivingEntity.class)
public abstract class LivingEntityMixin extends Entity {

public LivingEntityMixin(EntityType<?> type, World world) {
super(type, world);
}

@ModifyArg(
method = "travel(Lnet/minecraft/util/math/Vec3d;)V",
at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/LivingEntity;setVelocity(Lnet/minecraft/util/math/Vec3d;)V",
ordinal = 6
)
)
private Vec3d doABarrelRoll$wrapElytraVelocity(Vec3d original) {
if (!(((LivingEntity) (Object) this) instanceof ClientPlayerEntity) || !ModConfig.INSTANCE.enableThrust) return original;

Vec3d rotation = getRotationVector();
Vec3d velocity = getVelocity();

int particleDensity = (int) MathHelper.clamp(DoABarrelRollClient.throttle * 10, 0, 10);
if (DoABarrelRollClient.throttle > 0.1 && world.getTime() % (11 - particleDensity) == 0) {
var pPos = getPos().add(velocity.multiply(0.5).negate());
world.addParticle(
ParticleTypes.CAMPFIRE_SIGNAL_SMOKE,
pPos.getX(), pPos.getY(), pPos.getZ(),
random.nextGaussian() * 0.05, -velocity.y * 0.5, random.nextGaussian() * 0.05
);
}

return original.add(
(rotation.x * 0.1 + (rotation.x * 1.5 - velocity.x) * 0.5) * DoABarrelRollClient.throttle,
(rotation.y * 0.1 + (rotation.y * 1.5 - velocity.y) * 0.5) * DoABarrelRollClient.throttle,
(rotation.z * 0.1 + (rotation.z * 1.5 - velocity.z) * 0.5) * DoABarrelRollClient.throttle
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class MouseMixin {
target = "Lnet/minecraft/client/network/ClientPlayerEntity;changeLookDirection(DD)V"
)
)
private boolean changeLookDirection(ClientPlayerEntity player, double cursorDeltaX, double cursorDeltaY) {
private boolean doABarrelRoll$changeLookDirection(ClientPlayerEntity player, double cursorDeltaX, double cursorDeltaY) {
return DoABarrelRollClient.updateMouse(player, cursorDeltaX, cursorDeltaY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class PlayerEntityRendererMixin {
method = "setupTransforms(Lnet/minecraft/client/network/AbstractClientPlayerEntity;Lnet/minecraft/client/util/math/MatrixStack;FFF)V",
at = @At("HEAD")
)
private void capturePlayer(AbstractClientPlayerEntity abstractClientPlayerEntity, MatrixStack matrixStack, float f, float g, float h, CallbackInfo ci) {
private void doABarrelRoll$capturePlayer(AbstractClientPlayerEntity abstractClientPlayerEntity, MatrixStack matrixStack, float f, float g, float h, CallbackInfo ci) {
player = abstractClientPlayerEntity;
}

Expand All @@ -36,7 +36,7 @@ private void capturePlayer(AbstractClientPlayerEntity abstractClientPlayerEntity
),
index = 0
)
private Quaternion modifyRoll(Quaternion original) {
private Quaternion doABarrelRoll$modifyRoll(Quaternion original) {
if (!(player instanceof ClientPlayerEntity)) return original;

var roll = ElytraMath.getRoll(player.getYaw(), DoABarrelRollClient.left);
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/assets/do-a-barrel-roll/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"text.autoconfig.do-a-barrel-roll.option.enableBanking": "Enable banking",
"text.autoconfig.do-a-barrel-roll.option.enableBanking.@Tooltip": "Banking slightly yaws the camera when rolling, creating a more realistic, plane-like feeling.",
"text.autoconfig.do-a-barrel-roll.option.bankingStrength": "Banking strength",
"text.autoconfig.do-a-barrel-roll.option.enableThrust": "Enable thrusting",
"text.autoconfig.do-a-barrel-roll.option.enableThrust.@Tooltip[0]": "Enables you to use the forward and back keys (W and S by default)",
"text.autoconfig.do-a-barrel-roll.option.enableThrust.@Tooltip[1]": "to infinitely accelerate when using an elytra.",
"text.autoconfig.do-a-barrel-roll.option.enableThrust.@Tooltip[2]": "This is a very cheaty feature, and can be used to fly very fast.",
"text.autoconfig.do-a-barrel-roll.option.enableThrust.@Tooltip[3]": "§4Use this on servers at your own risk, or just don't.",
"text.autoconfig.do-a-barrel-roll.option.maxThrust": "Max thrusting speed",
"text.autoconfig.do-a-barrel-roll.option.maxThrust.@Tooltip": "Be careful with this one, for some reason things tend to get weird above 3-4.",
"text.autoconfig.do-a-barrel-roll.option.desktopSensitivity": "Mouse and keyboard sensitivity",
"text.autoconfig.do-a-barrel-roll.option.desktopSensitivity.pitch": "Pitch",
"text.autoconfig.do-a-barrel-roll.option.desktopSensitivity.yaw": "Yaw",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/do-a-barrel-roll.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"defaultRequire": 1
},
"mixins": [
"LivingEntityMixin"
]
}

0 comments on commit 2c20501

Please sign in to comment.