Skip to content

Commit

Permalink
Merge branch 'arch/1.20.4' into arch/1.20
Browse files Browse the repository at this point in the history
# Conflicts:
#	build.gradle
#	gradle.properties
  • Loading branch information
enjarai committed May 26, 2024
2 parents e89b320 + 74fd537 commit 8f8c752
Show file tree
Hide file tree
Showing 15 changed files with 215 additions and 108 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fixed a very elusive bug causing the mod to sometimes just not work.
- Added an automatic righting option in the config.
- Fixed compatibility with Controlify 2.0 beta 9.
12 changes: 8 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
plugins {
id 'dev.architectury.loom' version '1.6-SNAPSHOT' apply(false)
id 'me.fallenbreath.yamlang' version '1.2.1' apply(false)
id "me.modmuss50.mod-publish-plugin" version "0.4.4"
id 'me.fallenbreath.yamlang' version '1.3.1' apply(false)
id "me.modmuss50.mod-publish-plugin" version "0.4.4" apply(false)
id 'maven-publish'
}

version = "${mod_version}+${minecraft_version}"

subprojects {
apply plugin: 'java'
apply plugin: 'dev.architectury.loom'
apply plugin: 'me.fallenbreath.yamlang'
apply plugin: "me.modmuss50.mod-publish-plugin"
apply plugin: 'maven-publish'

version = "${mod_version}+${minecraft_version}"

Expand All @@ -18,6 +21,9 @@ subprojects {
maven { url "https://maven.enjarai.dev/mirrors" }
maven { url "https://maven.enjarai.dev/releases" }

// NeoForge
maven { url 'https://maven.neoforged.net/releases/' }

// Mod Menu.
maven { url 'https://maven.terraformersmc.com' }

Expand Down Expand Up @@ -100,8 +106,6 @@ subprojects {

fabric_version : fabric_version,
fabric_loader_version : fabric_loader_version,
forge_fabric_version : forge_fabric_version,
forge_fabric_loader_version : forge_fabric_loader_version,

mod_id : mod_id,
mod_name : mod_name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static void init() {
PITCH_SMOOTHER, YAW_SMOOTHER, ROLL_SMOOTHER,
ModConfig.INSTANCE.getSmoothing()
))
.useModifier(RotationModifiers::banking, ModConfig.INSTANCE::getEnableBanking),
.useModifier(RotationModifiers::banking, ModConfig.INSTANCE::getEnableBanking)
.useModifier(RotationModifiers::reorient, ModConfig.INSTANCE::getAutomaticRighting),
1000, FALL_FLYING_GROUP);

ClientEvents.SERVER_CONFIG_UPDATE.register(ModConfig.INSTANCE::notifyPlayerOfServerConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,21 @@ public static Screen generateConfigScreen(Screen parent) {
.option(getBooleanOption("banking", "simulate_control_surface_efficacy", true, false)
.binding(false, () -> ModConfig.INSTANCE.getSimulateControlSurfaceEfficacy(), value -> ModConfig.INSTANCE.setSimulateControlSurfaceEfficacy(value))
.build())
.option(getBooleanOption("banking", "automatic_righting", true, false)
.binding(false, () -> ModConfig.INSTANCE.getAutomaticRighting(), value -> ModConfig.INSTANCE.setAutomaticRighting(value))
.build())
.option(getOption(Double.class, "banking", "righting_strength", false, false)
.controller(option -> getDoubleSlider(option, 0.0, 100.0, 1.0))
.binding(50.0, () -> ModConfig.INSTANCE.getRightingStrength(), value -> ModConfig.INSTANCE.setRightingStrength(value))
.build())
.build())
.group(OptionGroup.createBuilder()
.name(getText("thrust"))
.collapsed(true)
.option(thrustingAllowed.add(getBooleanOption("thrust", "enable_thrust", true, false)
.option(thrustingAllowed.add(getBooleanOption("thrust", "enable_thrust", false, false)
.description(OptionDescription.of(Text.translatable(
"config.do_a_barrel_roll.thrust.enable_thrust.description",
ModKeybindings.THRUST_FORWARD.getBoundKeyLocalizedText())))
.binding(false, () -> ModConfig.INSTANCE.getEnableThrustClient(), value -> ModConfig.INSTANCE.setEnableThrust(value))))
.option(thrustingAllowed.add(getOption(Double.class, "thrust", "max_thrust", true, false)
.controller(option -> getDoubleSlider(option, 0.1, 10.0, 0.1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ static class Banking {
boolean enable_banking = true;
double banking_strength = 20.0;
boolean simulate_control_surface_efficacy = false;
boolean automatic_righting = false;
double righting_strength = 50.0;
}

Thrust thrust = new Thrust();
Expand Down Expand Up @@ -160,6 +162,14 @@ public boolean getSimulateControlSurfaceEfficacy() {
return general.banking.simulate_control_surface_efficacy;
}// = false;

public boolean getAutomaticRighting() {
return general.banking.automatic_righting;
}

public double getRightingStrength() {
return general.banking.righting_strength;
}

public boolean getEnableThrust() {
if (general.thrust.enable_thrust) {
ClientPlayerEntity player;
Expand Down Expand Up @@ -312,6 +322,14 @@ public void setSimulateControlSurfaceEfficacy(boolean enabled) {
general.banking.simulate_control_surface_efficacy = enabled;
}

public void setAutomaticRighting(boolean enabled) {
general.banking.automatic_righting = enabled;
}

public void setRightingStrength(double strength) {
general.banking.righting_strength = strength;
}

public void setEnableThrust(boolean enabled) {
general.thrust.enable_thrust = enabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.Map;

public class RotationModifiers {
public static final double ROLL_REORIENT_CUTOFF = Math.sqrt(10.0 / 3.0);

public static RollContext.ConfiguresRotation buttonControls(double power) {
return (rotationInstant, context) -> {
var delta = power * context.getRenderDelta();
Expand Down Expand Up @@ -76,6 +78,20 @@ public static RotationInstant banking(RotationInstant rotationInstant, RollConte
return rotationInstant.addAbsolute(dX * delta, dY * delta, currentRoll);
}

public static RotationInstant reorient(RotationInstant rotationInstant, RollContext context) {
var delta = context.getRenderDelta();
var currentRoll = context.getCurrentRotation().roll() * MagicNumbers.TORAD;
var strength = 10 * ModConfig.INSTANCE.getRightingStrength();

var cutoff = ROLL_REORIENT_CUTOFF;
double rollDelta = 0;
if (-cutoff < currentRoll && currentRoll < cutoff) {
rollDelta = -Math.pow(currentRoll, 3) / 3.0 + currentRoll; //0.1 * Math.pow(currentRoll, 5);
}

return rotationInstant.add(0, 0, -rollDelta * strength * delta);
}

public static RotationInstant manageThrottle(RotationInstant rotationInstant, RollContext context) {
var delta = context.getRenderDelta();

Expand Down
16 changes: 11 additions & 5 deletions common/src/main/resources/assets/do_a_barrel_roll/lang/en_us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,28 @@ config.do_a_barrel_roll:
simulate_control_surface_efficacy.description: >
Makes... an attempt to simulate the variable authority of different control surfaces based on your current angle of attack.
This is experimental and subject to change in the future, but might improve your flight experience.
automatic_righting: Automatic Righting
automatic_righting.description: >
Applies an artificial roll input to reorient the camera to be right side up when it is rolled by 90 degrees or less in either direction.
Enabling this together with switching the roll and yaw axes will make flight more vanilla-like, while still allowing manual rolling and loop-de-loops.
You may also find this option helpful in reducing motion sickness.
righting_strength: Righting Strength
thrust:
.: Thrusting Options
enable_thrust: Enable Thrusting
enable_thrust.description: >
Enables you to use the forward and back keys (W and S by default)
to infinitely accelerate and decelerate respectively.
Enables you to use the %1$s key
to infinitely accelerate while flying with an Elytra.
§4This feature is disabled on any server that does not explicitly allow it.
max_thrust: Max Thrusting Speed
max_thrust.description: >
The maximum speed that can be reached by thrusting.
The maximum speed that can be reached by thrusting in blocks per tick.
Setting this to anything above 2-3 might cause
problems with chunks not loading fast enough.
thrust_acceleration: Thrusting Acceleration
thrust_acceleration.description: >
The acceleration of thrusting.
The acceleration of thrusting in blocks per tick squared.
Higher values will make it easier to reach max speed.
thrust_particles: Show Thrusting Particles
misc:
Expand Down Expand Up @@ -302,7 +308,7 @@ toast.do_a_barrel_roll:
controlify:
category.do_a_barrel_roll.do_a_barrel_roll: Do a Barrel Roll
category.do_a_barrel_roll.do_a_barrel_roll: Do a Barrel Roll Movement
bind.do_a_barrel_roll:
pitch_up: Pitch Up
pitch_down: Pitch Down
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
package nl.enjarai.doabarrelroll.compat.controlify;

import dev.isxander.controlify.api.ControlifyApi;
import dev.isxander.controlify.api.bind.BindingSupplier;
import dev.isxander.controlify.api.bind.ControlifyBindingsApi;
import dev.isxander.controlify.api.bind.ControlifyBindApi;
import dev.isxander.controlify.api.bind.InputBindingSupplier;
import dev.isxander.controlify.api.entrypoint.ControlifyEntrypoint;
import dev.isxander.controlify.controller.input.GamepadInputs;
import dev.isxander.controlify.api.event.ControlifyEvents;
import dev.isxander.controlify.bindings.BindContext;
import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper;
import nl.enjarai.doabarrelroll.DoABarrelRoll;
import nl.enjarai.doabarrelroll.DoABarrelRollClient;
import nl.enjarai.doabarrelroll.ModKeybindings;
import nl.enjarai.doabarrelroll.api.event.RollContext;
import nl.enjarai.doabarrelroll.api.event.RollEvents;
import nl.enjarai.doabarrelroll.api.event.ThrustEvents;
import nl.enjarai.doabarrelroll.api.rotation.RotationInstant;
import nl.enjarai.doabarrelroll.config.ModConfig;

import static dev.isxander.controlify.controller.input.GamepadInputs.*;

public class ControlifyCompat implements ControlifyEntrypoint {
public static BindingSupplier PITCH_UP;
public static BindingSupplier PITCH_DOWN;
public static BindingSupplier ROLL_LEFT;
public static BindingSupplier ROLL_RIGHT;
public static BindingSupplier YAW_LEFT;
public static BindingSupplier YAW_RIGHT;
public static BindingSupplier THRUST_FORWARD;
public static BindingSupplier THRUST_BACKWARD;
public static final BindContext FALL_FLYING = new BindContext(
DoABarrelRoll.id("fall_flying"),
mc -> DoABarrelRollClient.isFallFlying()
);

public static InputBindingSupplier PITCH_UP;
public static InputBindingSupplier PITCH_DOWN;
public static InputBindingSupplier ROLL_LEFT;
public static InputBindingSupplier ROLL_RIGHT;
public static InputBindingSupplier YAW_LEFT;
public static InputBindingSupplier YAW_RIGHT;
public static InputBindingSupplier THRUST_FORWARD;
public static InputBindingSupplier THRUST_BACKWARD;

private RotationInstant applyToRotation(RotationInstant rotationDelta, RollContext context) {
var perhapsController = ControlifyApi.get().getCurrentController();
if (perhapsController.isPresent()) {
var controller = perhapsController.get();
var sensitivity = ModConfig.INSTANCE.getControllerSensitivity();

if (PITCH_UP.onController(controller) == null) return rotationDelta;
if (PITCH_UP.on(controller) == null) return rotationDelta;

double multiplier = context.getRenderDelta() * 1200;

double pitchAxis = PITCH_DOWN.onController(controller).state() - PITCH_UP.onController(controller).state();
double yawAxis = YAW_RIGHT.onController(controller).state() - YAW_LEFT.onController(controller).state();
double rollAxis = ROLL_RIGHT.onController(controller).state() - ROLL_LEFT.onController(controller).state();
double pitchAxis = PITCH_DOWN.on(controller).analogueNow() - PITCH_UP.on(controller).analogueNow();
double yawAxis = YAW_RIGHT.on(controller).analogueNow() - YAW_LEFT.on(controller).analogueNow();
double rollAxis = ROLL_RIGHT.on(controller).analogueNow() - ROLL_LEFT.on(controller).analogueNow();

pitchAxis *= multiplier * sensitivity.pitch;
yawAxis *= multiplier * sensitivity.yaw;
Expand All @@ -57,8 +62,8 @@ public static double getThrustModifier() {
}
var controller = ControlifyApi.get().getCurrentController().get();

float forward = THRUST_FORWARD.onController(controller).state();
float backward = THRUST_BACKWARD.onController(controller).state();
float forward = THRUST_FORWARD.on(controller).analogueNow();
float backward = THRUST_BACKWARD.on(controller).analogueNow();
return forward - backward;
}

Expand All @@ -73,46 +78,64 @@ public static RotationInstant manageThrottle(RotationInstant rotationInstant, Ro

@Override
public void onControlifyPreInit(ControlifyApi controlifyApi) {
var bindings = ControlifyBindingsApi.get();
PITCH_UP = bindings.registerBind(DoABarrelRoll.id("pitch_up"), builder -> builder
.defaultBind(getBind(RIGHT_STICK_AXIS_UP))
var bindings = ControlifyBindApi.get();
bindings.registerBindContext(FALL_FLYING);

PITCH_UP = bindings.registerBinding(builder -> builder
.id(DoABarrelRoll.id("pitch_up"))
.category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll"))
.name(Text.translatable("controlify.bind.do_a_barrel_roll.pitch_up"))
.allowedContexts(FALL_FLYING, BindContext.IN_GAME)
.addKeyCorrelation(ModKeybindings.PITCH_UP)
);
PITCH_DOWN = bindings.registerBind(DoABarrelRoll.id("pitch_down"), builder -> builder
.defaultBind(getBind(RIGHT_STICK_AXIS_DOWN))
PITCH_DOWN = bindings.registerBinding(builder -> builder
.id(DoABarrelRoll.id("pitch_down"))
.category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll"))
.name(Text.translatable("controlify.bind.do_a_barrel_roll.pitch_down"))
.allowedContexts(FALL_FLYING, BindContext.IN_GAME)
.addKeyCorrelation(ModKeybindings.PITCH_DOWN)
);
ROLL_LEFT = bindings.registerBind(DoABarrelRoll.id("roll_left"), builder -> builder
.defaultBind(getBind(RIGHT_STICK_AXIS_LEFT))
ROLL_LEFT = bindings.registerBinding(builder -> builder
.id(DoABarrelRoll.id("roll_left"))
.category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll"))
.name(Text.translatable("controlify.bind.do_a_barrel_roll.roll_left"))
.allowedContexts(FALL_FLYING, BindContext.IN_GAME)
.addKeyCorrelation(ModKeybindings.ROLL_LEFT)
);
ROLL_RIGHT = bindings.registerBind(DoABarrelRoll.id("roll_right"), builder -> builder
.defaultBind(getBind(RIGHT_STICK_AXIS_RIGHT))
ROLL_RIGHT = bindings.registerBinding(builder -> builder
.id(DoABarrelRoll.id("roll_right"))
.category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll"))
.name(Text.translatable("controlify.bind.do_a_barrel_roll.roll_right"))
.allowedContexts(FALL_FLYING, BindContext.IN_GAME)
.addKeyCorrelation(ModKeybindings.ROLL_RIGHT)
);
YAW_LEFT = bindings.registerBind(DoABarrelRoll.id("yaw_left"), builder -> builder
.defaultBind(getBind(LEFT_STICK_AXIS_LEFT))
YAW_LEFT = bindings.registerBinding(builder -> builder
.id(DoABarrelRoll.id("yaw_left"))
.category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll"))
.name(Text.translatable("controlify.bind.do_a_barrel_roll.yaw_left"))
.allowedContexts(FALL_FLYING, BindContext.IN_GAME)
.addKeyCorrelation(ModKeybindings.YAW_LEFT)
);
YAW_RIGHT = bindings.registerBind(DoABarrelRoll.id("yaw_right"), builder -> builder
.defaultBind(getBind(LEFT_STICK_AXIS_RIGHT))
YAW_RIGHT = bindings.registerBinding(builder -> builder
.id(DoABarrelRoll.id("yaw_right"))
.category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll"))
.name(Text.translatable("controlify.bind.do_a_barrel_roll.yaw_right"))
.allowedContexts(FALL_FLYING, BindContext.IN_GAME)
.addKeyCorrelation(ModKeybindings.YAW_RIGHT)
);
THRUST_FORWARD = bindings.registerBind(DoABarrelRoll.id("thrust_forward"), builder -> builder
.defaultBind(getBind(LEFT_STICK_AXIS_UP))
THRUST_FORWARD = bindings.registerBinding(builder -> builder
.id(DoABarrelRoll.id("thrust_forward"))
.category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll"))
.name(Text.translatable("controlify.bind.do_a_barrel_roll.thrust_forward"))
.allowedContexts(FALL_FLYING, BindContext.IN_GAME)
.addKeyCorrelation(ModKeybindings.THRUST_FORWARD)
);
THRUST_BACKWARD = bindings.registerBind(DoABarrelRoll.id("thrust_backward"), builder -> builder
.defaultBind(getBind(LEFT_STICK_AXIS_DOWN))
THRUST_BACKWARD = bindings.registerBinding(builder -> builder
.id(DoABarrelRoll.id("thrust_backward"))
.category(Text.translatable("controlify.category.do_a_barrel_roll.do_a_barrel_roll"))
.name(Text.translatable("controlify.bind.do_a_barrel_roll.thrust_backward"))
.allowedContexts(FALL_FLYING, BindContext.IN_GAME)
.addKeyCorrelation(ModKeybindings.THRUST_BACKWARD)
);

RollEvents.EARLY_CAMERA_MODIFIERS.register(context -> context
Expand All @@ -123,6 +146,12 @@ public void onControlifyPreInit(ControlifyApi controlifyApi) {
5, DoABarrelRollClient::isFallFlying);

ThrustEvents.MODIFY_THRUST_INPUT.register(input -> input + getThrustModifier());

ControlifyEvents.LOOK_INPUT_MODIFIER.register(event -> {
if (DoABarrelRollClient.isFallFlying()) {
event.lookInput().zero();
}
});
}

@Override
Expand Down

This file was deleted.

Loading

0 comments on commit 8f8c752

Please sign in to comment.