Skip to content

Commit 824f6f5

Browse files
authored
feat: expand on rotation logic and update readme (#26)
* feat: closes #24 * chore: cleanup * fix: rotateAfterSnap and cleanup
1 parent 03407aa commit 824f6f5

File tree

4 files changed

+87
-56
lines changed

4 files changed

+87
-56
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ You can set up shortcuts for quick camera control. To prevent shortcuts from app
3737
- **Look South Key**: Face camera South when pressed
3838
- **Look East Key**: Face camera East when pressed
3939
- **Look West Key**: Face camera West when pressed
40+
- **Rotate 180°**: Rotates the camera to opposite side (always 180°)
41+
- **Rotate Clockwise**: Rotates camera clockwise
42+
- **Rotate Counterclockwise**: Rotates camera counterclockwise
4043

44+
### Keybind Options
45+
- **Rotate After Snap**: Snap to the closest cardinal direction before rotation, applies to all rotation keybindings
46+
- **Rotation Value**: Set rotation value for clockwise and counterclockwise rotation keybindings
4147
---
4248
### Custom Cycle Order
4349
You can specify a custom order for cycling through directions. For example, if you prefer to cycle between North and South, you can set the cycle order to `N,S`. Only `N`, `S`, `W`, and `E` are valid characters for this field, all other characters will be ignored.
@@ -50,4 +56,4 @@ If you encounter any bugs, have suggestions for improvements, or would like to g
5056

5157
---
5258
#### Contributors
53-
Thanks to [LlemonDuck](https://github.com/LlemonDuck) and [insizhen](https://github.com/insizhen) for their valuable code contributions.
59+
Thanks to [LlemonDuck](https://github.com/LlemonDuck), [insizhen](https://github.com/insizhen), and [Scarcy](https://github.com/Scarcy) for their valuable code contributions.

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ dependencies {
2727
}
2828

2929
group = 'com.compassCameraControl'
30-
version = '1.0-SNAPSHOT'
30+
version = '1.2.2-SNAPSHOT'
3131

3232
tasks.withType(JavaCompile).configureEach {
3333
options.encoding = 'UTF-8'

src/main/java/com/compassCameraControl/CompassCameraControlConfig.java

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -60,33 +60,33 @@ default ShiftMode shiftClickMode()
6060
String cardinalKeybindingSnap = "cardinalKeybindingSnap";
6161

6262
@ConfigItem(
63-
keyName = "snapFacingKey",
64-
name = "Snap Facing",
65-
description = "Snaps the camera to the player's facing direction on key press",
66-
position = 5,
67-
section = cardinalKeybindingSnap
63+
keyName = "snapFacingKey",
64+
name = "Snap Facing",
65+
description = "Snaps the camera to the player's facing direction on key press",
66+
position = 5,
67+
section = cardinalKeybindingSnap
6868
)
6969
default Keybind snapFacingKey() {
7070
return new Keybind(KeyEvent.VK_UNDEFINED, 0);
7171
}
7272

7373
@ConfigItem(
74-
keyName = "snapCloseKey",
75-
name = "Snap to Closest",
76-
description = "Snaps the camera to the nearest cardinal direction on key press",
77-
position = 6,
78-
section = cardinalKeybindingSnap
74+
keyName = "snapCloseKey",
75+
name = "Snap to Closest",
76+
description = "Snaps the camera to the nearest cardinal direction on key press",
77+
position = 6,
78+
section = cardinalKeybindingSnap
7979
)
8080
default Keybind snapCloseKey() {
8181
return new Keybind(KeyEvent.VK_UNDEFINED, 0);
8282
}
8383

8484
@ConfigItem(
85-
keyName = "cycleCardinalKey",
86-
name = "Cycle Cardinal",
87-
description = "Cycles through cardinal directions on key press",
88-
position = 7,
89-
section = cardinalKeybindingSnap
85+
keyName = "cycleCardinalKey",
86+
name = "Cycle Cardinal",
87+
description = "Cycles through cardinal directions on key press",
88+
position = 7,
89+
section = cardinalKeybindingSnap
9090
)
9191
default Keybind cycleCardinalKey() {
9292
return new Keybind(KeyEvent.VK_UNDEFINED, 0);
@@ -136,32 +136,56 @@ default Keybind lookWestKey() {
136136
return new Keybind(KeyEvent.VK_UNDEFINED, 0);
137137
}
138138

139-
140-
141139
@ConfigItem(
142-
keyName = "rotateWestKey",
143-
name = "Rotate West Key",
144-
description = "Rotate camera West, based on user configuration (Default 90°)",
140+
keyName = "rotateFlipKey",
141+
name = "Rotate 180° Key",
142+
description = "Rotates the camera to opposite side (always 180°)",
145143
position = 12,
146144
section = cardinalKeybindingSnap
147145
)
148-
default Keybind rotateWestKey() { return new Keybind(KeyEvent.VK_UNDEFINED, 0);}
146+
default Keybind rotateFlipKey() { return new Keybind(KeyEvent.VK_UNDEFINED, 0);}
147+
148+
149+
@ConfigItem(
150+
keyName = "rotateClockwiseKey",
151+
name = "Rotate Clockwise Key",
152+
position = 13,
153+
section = cardinalKeybindingSnap,
154+
description = "Rotate camera a user defined number of degrees clockwise<br/>" +
155+
"Based on Rotation Degree"
156+
)
157+
default Keybind rotateClockwiseKey() { return new Keybind(KeyEvent.VK_UNDEFINED, 0);}
158+
159+
@ConfigItem(
160+
keyName = "rotateCounterclockwiseKey",
161+
name = "Rotate Counterclockwise Key",
162+
position = 14,
163+
section = cardinalKeybindingSnap,
164+
description = "Rotate camera a user defined number of degrees counterclockwise<br/>" +
165+
"Based on Rotation Degree"
166+
)
167+
default Keybind rotateCounterclockwiseKey() { return new Keybind(KeyEvent.VK_UNDEFINED, 0);}
149168

150169
@ConfigItem(
151-
keyName = "rotateEastKey",
152-
name = "Rotate East Key",
153-
description = "Rotate camera East, based on user configuration (Default 90°)",
154-
position = 13,
155-
section = cardinalKeybindingSnap
170+
keyName = "rotateAfterSnap",
171+
name = "Rotate After Snap",
172+
position = 15,
173+
description = "Snap to the closest cardinal direction before rotation<br/>" +
174+
"Applies to all rotation keybindings"
156175
)
157-
default Keybind rotateEastKey() { return new Keybind(KeyEvent.VK_UNDEFINED, 0);}
176+
default boolean rotateAfterSnap()
177+
{
178+
return false;
179+
}
158180

159181
@ConfigItem(
160-
keyName = "rotateDegree",
161-
name = "Rotation Degree",
162-
description = "How many degrees to rotate",
163-
position = 14,
164-
section = cardinalKeybindingSnap
182+
keyName = "rotateDegree",
183+
name = "Rotation Degree",
184+
position = 16,
185+
description = "Rotation value for clockwise and counterclockwise rotation keybindings"
165186
)
166-
default int rotateDegree(){ return 90; }
187+
default int rotateDegree()
188+
{
189+
return 90;
190+
}
167191
}

src/main/java/com/compassCameraControl/CompassCameraControlPlugin.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -221,26 +221,25 @@ private int degreesToYaw(int degrees) {
221221
return (int) Math.round(degrees * 2048.0 / 360.0);
222222
}
223223

224-
private void rotateWestYaw()
224+
private void rotateYaw(String s)
225225
{
226226
int currentYaw = client.getCameraYaw();
227-
int userInputDegree = config.rotateDegree();
228-
int shift = degreesToYaw(userInputDegree);
227+
int shift = s.equals("Flip") ? degreesToYaw(180) : degreesToYaw(config.rotateDegree());
228+
int targetYaw;
229229

230-
int targetYaw = currentYaw + shift;
231-
// Wraps yaw into camera range [0,2048)
232-
targetYaw &= 2047;
230+
if (config.rotateAfterSnap()) {
231+
alignYaw();
232+
// Above updates the yaw target in this tick, so use the target rather than the current yaw
233+
currentYaw = client.getCameraYawTarget();
234+
}
233235

234-
client.setCameraYawTarget(targetYaw);
235-
}
236-
237-
private void rotateEastYaw()
238-
{
239-
int currentYaw = client.getCameraYaw();
240-
int userInputDegree = config.rotateDegree();
241-
int shift = degreesToYaw(userInputDegree);
236+
if(s.equals("Clockwise")){
237+
targetYaw = currentYaw + shift;
238+
}
239+
else {
240+
targetYaw = currentYaw - shift;
241+
}
242242

243-
int targetYaw = currentYaw - shift;
244243
// Wraps yaw into camera range [0,2048)
245244
targetYaw &= 2047;
246245

@@ -268,13 +267,15 @@ public void keyPressed(KeyEvent event) {
268267
} else if (config.lookSouthKey().matches(event)) {
269268
client.setCameraYawTarget(SOUTH_YAW);
270269
} else if (config.lookEastKey().matches(event)) {
271-
client.setCameraYawTarget(EAST_YAW);}
272-
else if (config.lookWestKey().matches(event)) {
270+
client.setCameraYawTarget(EAST_YAW);
271+
} else if (config.lookWestKey().matches(event)) {
273272
client.setCameraYawTarget(WEST_YAW);
274-
} else if (config.rotateWestKey().matches(event)) {
275-
rotateWestYaw();
276-
} else if (config.rotateEastKey().matches(event)) {
277-
rotateEastYaw();
273+
} else if (config.rotateFlipKey().matches(event)) {
274+
rotateYaw("Flip");
275+
} else if (config.rotateClockwiseKey().matches(event)) {
276+
rotateYaw("Clockwise");
277+
} else if (config.rotateCounterclockwiseKey().matches(event)) {
278+
rotateYaw("Counterclockwise");
278279
} else {
279280
handledEvent = false;
280281
}

0 commit comments

Comments
 (0)