added Free look
This commit is contained in:
@@ -3,8 +3,10 @@ package org.saturnclient.saturnclient.event;
|
|||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
|
||||||
import net.minecraft.client.option.KeyBinding;
|
import net.minecraft.client.option.KeyBinding;
|
||||||
|
import net.minecraft.client.option.Perspective;
|
||||||
import net.minecraft.client.util.InputUtil;
|
import net.minecraft.client.util.InputUtil;
|
||||||
import org.saturnclient.saturnclient.menus.SaturnMenu;
|
import org.saturnclient.saturnclient.menus.SaturnMenu;
|
||||||
|
import org.saturnclient.saturnmods.mods.FreeLook;
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -15,9 +17,12 @@ public class KeyInputHandler {
|
|||||||
private static final String KEY_CATEGORY = "key.category.saturnclient";
|
private static final String KEY_CATEGORY = "key.category.saturnclient";
|
||||||
private static final String MAIN_MENU_KEY_ID = "key.saturnclient.main_menu";
|
private static final String MAIN_MENU_KEY_ID = "key.saturnclient.main_menu";
|
||||||
private static final int DEFAULT_MENU_KEY = GLFW.GLFW_KEY_RIGHT_SHIFT;
|
private static final int DEFAULT_MENU_KEY = GLFW.GLFW_KEY_RIGHT_SHIFT;
|
||||||
|
|
||||||
private static KeyBinding mainMenuKeyBinding;
|
private static KeyBinding mainMenuKeyBinding;
|
||||||
|
|
||||||
|
private static final String FREELOOK_KEY_ID = "key.saturnclient.freelook";
|
||||||
|
private static final int FREELOOK_KEY = GLFW.GLFW_KEY_M;
|
||||||
|
private static KeyBinding freelookKeyBinding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers all keybindings and their associated event handlers.
|
* Registers all keybindings and their associated event handlers.
|
||||||
* Should be called during mod initialization.
|
* Should be called during mod initialization.
|
||||||
@@ -30,10 +35,37 @@ public class KeyInputHandler {
|
|||||||
DEFAULT_MENU_KEY,
|
DEFAULT_MENU_KEY,
|
||||||
KEY_CATEGORY));
|
KEY_CATEGORY));
|
||||||
|
|
||||||
|
freelookKeyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding(
|
||||||
|
FREELOOK_KEY_ID,
|
||||||
|
InputUtil.Type.KEYSYM,
|
||||||
|
FREELOOK_KEY,
|
||||||
|
KEY_CATEGORY));
|
||||||
|
|
||||||
// Register the event handler for the main menu key
|
// Register the event handler for the main menu key
|
||||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||||
if (mainMenuKeyBinding.wasPressed()) {
|
if (mainMenuKeyBinding.wasPressed()) {
|
||||||
client.setScreen(new SaturnMenu());
|
client.setScreen(new SaturnMenu());
|
||||||
|
} else if (freelookKeyBinding.wasPressed() && FreeLook.enabled.value && FreeLook.toggle.value) {
|
||||||
|
FreeLook.isFreeLooking = !FreeLook.isFreeLooking;
|
||||||
|
if (FreeLook.isFreeLooking) {
|
||||||
|
FreeLook.lastPerspective = client.options.getPerspective();
|
||||||
|
client.options.setPerspective(Perspective.THIRD_PERSON_BACK);
|
||||||
|
} else if (FreeLook.lastPerspective != null) {
|
||||||
|
client.options.setPerspective(FreeLook.lastPerspective);
|
||||||
|
FreeLook.lastPerspective = null;
|
||||||
|
}
|
||||||
|
} else if (FreeLook.enabled.value && !FreeLook.toggle.value) {
|
||||||
|
if (freelookKeyBinding.isPressed()) {
|
||||||
|
if (!FreeLook.isFreeLooking) {
|
||||||
|
FreeLook.lastPerspective = client.options.getPerspective();
|
||||||
|
client.options.setPerspective(Perspective.THIRD_PERSON_BACK);
|
||||||
|
FreeLook.isFreeLooking = true;
|
||||||
|
}
|
||||||
|
} else if (FreeLook.isFreeLooking && FreeLook.lastPerspective != null) {
|
||||||
|
client.options.setPerspective(FreeLook.lastPerspective);
|
||||||
|
FreeLook.isFreeLooking = false;
|
||||||
|
FreeLook.lastPerspective = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package org.saturnclient.saturnclient.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.client.MinecraftClient;
|
||||||
|
import net.minecraft.client.render.Camera;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.mod_utils.CameraOverriddenEntity;
|
||||||
|
import org.saturnclient.saturnmods.mods.FreeLook;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.world.BlockView;
|
||||||
|
|
||||||
|
@Mixin(Camera.class)
|
||||||
|
public abstract class CameraMixin {
|
||||||
|
@Unique
|
||||||
|
boolean firstTime = true;
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
protected abstract void setRotation(float yaw, float pitch);
|
||||||
|
|
||||||
|
@Inject(method = "update", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/Camera;setRotation(FF)V", ordinal = 1, shift = At.Shift.AFTER))
|
||||||
|
public void lockRotation(BlockView focusedBlock, Entity cameraEntity, boolean isThirdPerson, boolean isFrontFacing,
|
||||||
|
float tickDelta, CallbackInfo ci) {
|
||||||
|
if (FreeLook.isFreeLooking && cameraEntity instanceof ClientPlayerEntity) {
|
||||||
|
CameraOverriddenEntity cameraOverriddenEntity = (CameraOverriddenEntity) cameraEntity;
|
||||||
|
|
||||||
|
if (firstTime && MinecraftClient.getInstance().player != null) {
|
||||||
|
cameraOverriddenEntity.freelook$setCameraPitch(MinecraftClient.getInstance().player.getPitch());
|
||||||
|
cameraOverriddenEntity.freelook$setCameraYaw(MinecraftClient.getInstance().player.getYaw());
|
||||||
|
firstTime = false;
|
||||||
|
}
|
||||||
|
this.setRotation(cameraOverriddenEntity.freelook$getCameraYaw(),
|
||||||
|
cameraOverriddenEntity.freelook$getCameraPitch());
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!FreeLook.isFreeLooking && cameraEntity instanceof ClientPlayerEntity) {
|
||||||
|
firstTime = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
package org.saturnclient.saturnclient.mixin;
|
||||||
|
|
||||||
|
import net.minecraft.client.network.ClientPlayerEntity;
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.mod_utils.CameraOverriddenEntity;
|
||||||
|
import org.saturnclient.saturnmods.mods.FreeLook;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Unique;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
@Mixin(Entity.class)
|
||||||
|
public class EntityMixin implements CameraOverriddenEntity {
|
||||||
|
@Unique
|
||||||
|
private float cameraPitch;
|
||||||
|
|
||||||
|
@Unique
|
||||||
|
private float cameraYaw;
|
||||||
|
|
||||||
|
@Inject(method = "changeLookDirection", at = @At("HEAD"), cancellable = true)
|
||||||
|
public void changeCameraLookDirection(double xDelta, double yDelta, CallbackInfo ci) {
|
||||||
|
// noinspection ConstantValue// IntelliJ is incorrect here, this code block is
|
||||||
|
// reachable
|
||||||
|
if (FreeLook.isFreeLooking && (Object) this instanceof ClientPlayerEntity) {
|
||||||
|
double pitchDelta = (yDelta * 0.15);
|
||||||
|
double yawDelta = (xDelta * 0.15);
|
||||||
|
|
||||||
|
this.cameraPitch = MathHelper.clamp(this.cameraPitch + (float) pitchDelta, -90.0f, 90.0f);
|
||||||
|
this.cameraYaw += (float) yawDelta;
|
||||||
|
|
||||||
|
ci.cancel();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Unique
|
||||||
|
public float freelook$getCameraPitch() {
|
||||||
|
return this.cameraPitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Unique
|
||||||
|
public float freelook$getCameraYaw() {
|
||||||
|
return this.cameraYaw;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Unique
|
||||||
|
public void freelook$setCameraPitch(float pitch) {
|
||||||
|
this.cameraPitch = pitch;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Unique
|
||||||
|
public void freelook$setCameraYaw(float yaw) {
|
||||||
|
this.cameraYaw = yaw;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package org.saturnclient.saturnclient.mod_utils;
|
||||||
|
|
||||||
|
public interface CameraOverriddenEntity {
|
||||||
|
float freelook$getCameraPitch();
|
||||||
|
float freelook$getCameraYaw();
|
||||||
|
|
||||||
|
void freelook$setCameraPitch(float pitch);
|
||||||
|
void freelook$setCameraYaw(float yaw);
|
||||||
|
}
|
||||||
@@ -15,7 +15,8 @@ public class ModManager {
|
|||||||
new ArmorDisplay(),
|
new ArmorDisplay(),
|
||||||
new FpsDisplay(),
|
new FpsDisplay(),
|
||||||
new Particles(),
|
new Particles(),
|
||||||
new Crosshair()
|
new Crosshair(),
|
||||||
|
new FreeLook()
|
||||||
};
|
};
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package org.saturnclient.saturnmods.mods;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.config.ConfigManager;
|
||||||
|
import org.saturnclient.saturnclient.config.Property;
|
||||||
|
import org.saturnclient.saturnmods.SaturnMod;
|
||||||
|
import org.saturnclient.ui.Textures;
|
||||||
|
|
||||||
|
import net.minecraft.client.option.Perspective;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
|
public class FreeLook implements SaturnMod {
|
||||||
|
public static boolean isFreeLooking = false;
|
||||||
|
public static Perspective lastPerspective = null;
|
||||||
|
|
||||||
|
private static ConfigManager config = new ConfigManager("armor");
|
||||||
|
public static Property<Boolean> enabled = config.property(
|
||||||
|
"Enabled",
|
||||||
|
new Property<>(false));
|
||||||
|
|
||||||
|
public static Property<Boolean> toggle = config.property(
|
||||||
|
"Toggle Free Look",
|
||||||
|
new Property<>(false));
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean e) {
|
||||||
|
enabled.value = e;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ConfigManager getConfig() {
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Identifier getIconTexture() {
|
||||||
|
return Textures.getModIcon("freelook");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "Free Look";
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 959 B |
@@ -10,7 +10,9 @@
|
|||||||
"WhoAmI",
|
"WhoAmI",
|
||||||
"SaturnReload",
|
"SaturnReload",
|
||||||
"TotemParticleMixin",
|
"TotemParticleMixin",
|
||||||
"Crosshair"
|
"Crosshair",
|
||||||
|
"EntityMixin",
|
||||||
|
"CameraMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|||||||
Reference in New Issue
Block a user