diff --git a/common/src/main/java/net/xolt/freecam/Freecam.java b/common/src/main/java/net/xolt/freecam/Freecam.java index a03f5393..71b8d896 100644 --- a/common/src/main/java/net/xolt/freecam/Freecam.java +++ b/common/src/main/java/net/xolt/freecam/Freecam.java @@ -14,6 +14,7 @@ import net.xolt.freecam.config.ModConfig; import net.xolt.freecam.tripod.TripodRegistry; import net.xolt.freecam.tripod.TripodSlot; +import net.xolt.freecam.util.DummyInput; import net.xolt.freecam.util.FreeCamera; import net.xolt.freecam.util.FreecamPosition; import net.xolt.freecam.variant.api.BuildVariant; @@ -46,9 +47,8 @@ public static void preTick(Minecraft mc) { if (isEnabled()) { // Prevent player from being controlled when freecam is enabled if (mc.player != null && mc.player.input instanceof KeyboardInput && !isPlayerControlEnabled()) { - Input input = new Input(); - input.shiftKeyDown = mc.player.input.shiftKeyDown; // Makes player continue to sneak after freecam is enabled. - mc.player.input = input; + // Makes player continue to sneak after freecam is enabled. + mc.player.input = new DummyInput(mc.player.input); } mc.gameRenderer.setRenderHand(ModConfig.INSTANCE.visual.showHand); @@ -155,13 +155,14 @@ public static void switchControls() { return; } + playerControlEnabled = !playerControlEnabled; if (playerControlEnabled) { - freeCamera.input = new KeyboardInput(MC.options); - } else { MC.player.input = new KeyboardInput(MC.options); freeCamera.input = new Input(); + } else { + freeCamera.input = new KeyboardInput(MC.options); + // We set MC.player.input every tick anyway, so don't bother here } - playerControlEnabled = !playerControlEnabled; } private static void onEnableTripod(TripodSlot tripod) { @@ -245,7 +246,6 @@ private static void onDisable() { MC.setCameraEntity(MC.player); playerControlEnabled = false; freeCamera.despawn(); - freeCamera.input = new Input(); freeCamera = null; if (MC.player != null) { diff --git a/common/src/main/java/net/xolt/freecam/util/DummyInput.java b/common/src/main/java/net/xolt/freecam/util/DummyInput.java new file mode 100644 index 00000000..7476968a --- /dev/null +++ b/common/src/main/java/net/xolt/freecam/util/DummyInput.java @@ -0,0 +1,15 @@ +package net.xolt.freecam.util; + +import net.minecraft.client.player.Input; + +public class DummyInput extends Input { + + public DummyInput(Input old) { + this(old.shiftKeyDown); + } + + public DummyInput(boolean isSneaking) { + // Makes player continue to sneak after freecam is enabled. + this.shiftKeyDown = isSneaking; + } +}