mirror of
https://github.com/chylex/Better-Controls.git
synced 2025-05-31 22:34:04 +02:00
Implement option to disable smooth camera when sneaking
This commit is contained in:
parent
d7151afd0e
commit
bec0bcb597
src/main
java/chylex/bettercontrols
config
gui
mixin
player
resources
@ -11,6 +11,8 @@ public final class BetterControlsConfig{
|
|||||||
|
|
||||||
public boolean doubleTapForwardToSprint = true;
|
public boolean doubleTapForwardToSprint = true;
|
||||||
|
|
||||||
|
public boolean sneakingMovesCameraSmoothly = true;
|
||||||
|
|
||||||
public boolean flyOnGroundInCreative = false;
|
public boolean flyOnGroundInCreative = false;
|
||||||
public float flightSpeedMpCreativeDefault = 1F;
|
public float flightSpeedMpCreativeDefault = 1F;
|
||||||
public float flightSpeedMpCreativeSprinting = 2F;
|
public float flightSpeedMpCreativeSprinting = 2F;
|
||||||
|
@ -32,6 +32,8 @@ final class ConfigSerializer implements JsonSerializer<BetterControlsConfig>, Js
|
|||||||
|
|
||||||
Json.setBool(obj, "Sprint.DoubleTapForward", cfg.doubleTapForwardToSprint);
|
Json.setBool(obj, "Sprint.DoubleTapForward", cfg.doubleTapForwardToSprint);
|
||||||
|
|
||||||
|
Json.setBool(obj, "Sneak.SmoothCamera", cfg.sneakingMovesCameraSmoothly);
|
||||||
|
|
||||||
Json.setBool(obj, "Flight.FlyOnGround.Creative", cfg.flyOnGroundInCreative);
|
Json.setBool(obj, "Flight.FlyOnGround.Creative", cfg.flyOnGroundInCreative);
|
||||||
Json.setFloat(obj, "Flight.SpeedMp.Creative.Default", cfg.flightSpeedMpCreativeDefault);
|
Json.setFloat(obj, "Flight.SpeedMp.Creative.Default", cfg.flightSpeedMpCreativeDefault);
|
||||||
Json.setFloat(obj, "Flight.SpeedMp.Creative.Sprinting", cfg.flightSpeedMpCreativeSprinting);
|
Json.setFloat(obj, "Flight.SpeedMp.Creative.Sprinting", cfg.flightSpeedMpCreativeSprinting);
|
||||||
@ -48,6 +50,8 @@ final class ConfigSerializer implements JsonSerializer<BetterControlsConfig>, Js
|
|||||||
|
|
||||||
cfg.doubleTapForwardToSprint = Json.getBool(obj, "Sprint.DoubleTapForward", cfg.doubleTapForwardToSprint);
|
cfg.doubleTapForwardToSprint = Json.getBool(obj, "Sprint.DoubleTapForward", cfg.doubleTapForwardToSprint);
|
||||||
|
|
||||||
|
cfg.sneakingMovesCameraSmoothly = Json.getBool(obj, "Sneak.SmoothCamera", cfg.sneakingMovesCameraSmoothly);
|
||||||
|
|
||||||
cfg.flyOnGroundInCreative = Json.getBool(obj, "Flight.FlyOnGround.Creative", cfg.flyOnGroundInCreative);
|
cfg.flyOnGroundInCreative = Json.getBool(obj, "Flight.FlyOnGround.Creative", cfg.flyOnGroundInCreative);
|
||||||
cfg.flightSpeedMpCreativeDefault = Json.getFloat(obj, "Flight.SpeedMp.Creative.Default", cfg.flightSpeedMpCreativeDefault);
|
cfg.flightSpeedMpCreativeDefault = Json.getFloat(obj, "Flight.SpeedMp.Creative.Default", cfg.flightSpeedMpCreativeDefault);
|
||||||
cfg.flightSpeedMpCreativeSprinting = Json.getFloat(obj, "Flight.SpeedMp.Creative.Sprinting", cfg.flightSpeedMpCreativeSprinting);
|
cfg.flightSpeedMpCreativeSprinting = Json.getFloat(obj, "Flight.SpeedMp.Creative.Sprinting", cfg.flightSpeedMpCreativeSprinting);
|
||||||
|
@ -46,6 +46,16 @@ public class BetterControlsScreen extends GameOptionsScreen{
|
|||||||
return y;
|
return y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int generateSneakingOptions(int y, final List<Element> elements){
|
||||||
|
final BetterControlsConfig cfg = BetterControlsMod.config;
|
||||||
|
|
||||||
|
generateLeftSideText(y, elements, Text.of("Move Camera Smoothly"));
|
||||||
|
elements.add(new BooleanValueWidget(col2(1), y, COL2_W, cfg.sneakingMovesCameraSmoothly, value -> cfg.sneakingMovesCameraSmoothly = value));
|
||||||
|
|
||||||
|
y += ROW_HEIGHT;
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings({ "AutoBoxing", "AutoUnboxing" })
|
@SuppressWarnings({ "AutoBoxing", "AutoUnboxing" })
|
||||||
private int generateFlightOptions(int y, final List<Element> elements){
|
private int generateFlightOptions(int y, final List<Element> elements){
|
||||||
final BetterControlsConfig cfg = BetterControlsMod.config;
|
final BetterControlsConfig cfg = BetterControlsMod.config;
|
||||||
@ -116,6 +126,9 @@ public class BetterControlsScreen extends GameOptionsScreen{
|
|||||||
elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, Text.of("Sprinting"), CENTER));
|
elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, Text.of("Sprinting"), CENTER));
|
||||||
y = generateSprintingOptions(y + ROW_HEIGHT, elements) + TITLE_MARGIN_TOP;
|
y = generateSprintingOptions(y + ROW_HEIGHT, elements) + TITLE_MARGIN_TOP;
|
||||||
|
|
||||||
|
elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, Text.of("Sneaking"), CENTER));
|
||||||
|
y = generateSneakingOptions(y + ROW_HEIGHT, elements) + TITLE_MARGIN_TOP;
|
||||||
|
|
||||||
elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, Text.of("Flying"), CENTER));
|
elements.add(new TextWidget(0, y, ROW_WIDTH, ROW_HEIGHT, Text.of("Flying"), CENTER));
|
||||||
y = generateFlightOptions(y + ROW_HEIGHT, elements) + TITLE_MARGIN_TOP;
|
y = generateFlightOptions(y + ROW_HEIGHT, elements) + TITLE_MARGIN_TOP;
|
||||||
|
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package chylex.bettercontrols.mixin;
|
||||||
|
import net.minecraft.client.render.Camera;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||||
|
|
||||||
|
@Mixin(Camera.class)
|
||||||
|
public interface AccessCameraFields{
|
||||||
|
@Accessor
|
||||||
|
Entity getFocusedEntity();
|
||||||
|
|
||||||
|
@Accessor
|
||||||
|
void setCameraY(float y);
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
package chylex.bettercontrols.player;
|
package chylex.bettercontrols.player;
|
||||||
import chylex.bettercontrols.BetterControlsMod;
|
import chylex.bettercontrols.BetterControlsMod;
|
||||||
import chylex.bettercontrols.config.BetterControlsConfig;
|
import chylex.bettercontrols.config.BetterControlsConfig;
|
||||||
|
import chylex.bettercontrols.mixin.AccessCameraFields;
|
||||||
import chylex.bettercontrols.mixin.AccessClientPlayerFields;
|
import chylex.bettercontrols.mixin.AccessClientPlayerFields;
|
||||||
import net.minecraft.client.MinecraftClient;
|
import net.minecraft.client.MinecraftClient;
|
||||||
import net.minecraft.client.network.ClientPlayerEntity;
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
@ -92,5 +93,13 @@ public final class PlayerTicker{
|
|||||||
wasSneakingBeforeTouchingGround = false;
|
wasSneakingBeforeTouchingGround = false;
|
||||||
holdingSneakWhileTouchingGround = false;
|
holdingSneakWhileTouchingGround = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!cfg().sneakingMovesCameraSmoothly){
|
||||||
|
final AccessCameraFields camera = (AccessCameraFields)mc().gameRenderer.getCamera();
|
||||||
|
|
||||||
|
if (camera.getFocusedEntity() == player){
|
||||||
|
camera.setCameraY(player.getStandingEyeHeight());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
"package": "chylex.bettercontrols.mixin",
|
"package": "chylex.bettercontrols.mixin",
|
||||||
"compatibilityLevel": "JAVA_8",
|
"compatibilityLevel": "JAVA_8",
|
||||||
"mixins": [
|
"mixins": [
|
||||||
|
"AccessCameraFields",
|
||||||
"AccessClientPlayerFields",
|
"AccessClientPlayerFields",
|
||||||
"AccessKeyBindingFields",
|
"AccessKeyBindingFields",
|
||||||
"AccessScreenButtons",
|
"AccessScreenButtons",
|
||||||
|
Loading…
Reference in New Issue
Block a user