Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I hacked in a spectator-like follow mode #115

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jpicht
Copy link

@jpicht jpicht commented Nov 10, 2023

Is this kind of thing something that you'd consider to merge? I'd be willing to put in some work to make it nicer, this is just a simple hack that works for me™️

Copy link
Member

@MattSturgeon MattSturgeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funnily enough, I was just about to look into working on this feature myself, before I found your PR. 😂

I've given it a quick test and had a quick glance over the code. It's working very well as an initial proof of concept.

Other than code cleanup/refactoring, I personally would take a different approach to the keybinding. IMO it makes sense to re-use vanilla's "Pick" keybind (middle mouse) rather than adding a new freecam-specific one.

This would mean "follow" is always activated from within freecam mode, and we'd have to think about how to exit follow mode; perhaps the freecam keybind or using the "pick" bind would exit?

Even if we don't go with my approach, I still think the "follow" and "followSet" binds should be combined somehow.

Hopefully @hashalite is happy to include a follow/spectate mode. If I get chance I may look into working on this myself too, although I have other stuff I want to look at too, so who knows.

followBind = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.freecam.follow", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, "category.freecam.freecam"));
setFollowBind = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"key.freecam.setFollow", InputUtil.Type.KEYSYM, GLFW.GLFW_KEY_UNKNOWN, "category.freecam.freecam"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'm in favor of hooking into vanilla's Pick Block action instead of adding our own keybind, however if we do add a custom bind I'd rather it be one single bind than two separate ones.

Also, the keybind translation key should be added to the lang file.

private static boolean freecamEnabled = false;
private static boolean tripodEnabled = false;
private static boolean followEnabled = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isEnabled method should also check this. Currently various mixins are broken, e.g. "Show Player".

return follow;
}

public static void toggleFollow() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toggleFollow might benefit from being split into enableFollow and disableFollow methods?

Comment on lines +261 to +264
if (followEnabled) {
freeCamera.applyPosition(new FreecamPosition(followMe));
followEnabled = false;
}
Copy link
Member

@MattSturgeon MattSturgeon Nov 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should use FreecamPosition.getSwimmingPosition() instead of new FreecamPosition(). (Currently activating freecam from follow mode will position the camera at the feet instead of at the head of followMe.)

It may be cleaner to remove the public FreeCamera(int id) constructor entirely and instead do something like:

freeCamera = new FreeCamera(-420, FreecamPosition.getSwimmingPosition(
    followEnabled ? followMe : MC.player
));

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, calling onEnable() conditionally and then manually disabling followEnabled without any sorta disableFollow method feels a bit messy.

@MattSturgeon MattSturgeon mentioned this pull request Nov 22, 2023
11 tasks
@hashalite
Copy link
Collaborator

I like what's been done here, thank you!

I agree with what @MattSturgeon has said. I think the two keybinds should be replaced with the default pick block bind. I think it feels more intuitive and it uses less space in the controls menu. followEnabled definitely needs to be checked by isEnabled, too. The other style-related changes would also be appreciated.

@MattSturgeon MattSturgeon added the enhancement New feature or request label Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants