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

LockRotation app #376

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

LockRotation app #376

wants to merge 11 commits into from

Conversation

TernaryC
Copy link

An app that recreates the behavior of the "lock rotation" tweak from the Quark mod.

This app adds a command, /lockrotation, which saves the player's current orientation for block placement (or an approximation), and applies it to all future blocks placed.
The lock can be disabled by running the command /lockrotation clear or setting the same rotation twice in a row.
Your current saved rotation can be displayed by running the command /lockrotation show.

I am not positive how this app will interact with any modded blocks, although I imagine not well. That's something that can be improved perhaps.
For vanilla blocks, though, I've accounted for as many edge cases as I could think of. Hopefully, I've not missed anything glaringly obvious.

TernaryC added 3 commits July 27, 2023 02:37
Added entry for lockrotation.sc
New program added to programs/utilities
- Updated orientation calculation to better reflect actual Minecraft placement behavior.
- Fixed major bug in reorientation function
Fixed a typo in _getIdealState()
@rv3r
Copy link
Collaborator

rv3r commented Jul 27, 2023

Shaped stairs aren't getting updated when they get their rotation changed by this script. Locking rotation and trying to make shaped stairs should just produce nicely aligned stairs. Instead I get the attached image. Have you encountered this or tried to make stairs update properly?
stairs

@rv3r
Copy link
Collaborator

rv3r commented Jul 27, 2023

Other than that it certainly functions as expected. Your _castSide function produces some fun results when _sign is passed 0 (especially since gnembon/fabric-carpet#1776 is a thing) but it still works so nbd.

I was a bit confused on how to get the "half" part of the lock to activate and I had to read through the code to find it, so an explanation of how to use the script could be added to the readme entry.

My last major note is that there are a lot of lines that could be optimized with scarpet-specific features (lines 109-117 could become truepos = map(raycast - blockpos - 0.5,ceil(abs(_) - 0.49999) * _sign(_));, ifs can act as their own elif, you can use function returns directly rather than assigning to a variable first, etc.), but it's already so fast that I'm not worried about these minor performance gains.

TernaryC added 3 commits July 28, 2023 01:46
Usage instructions added to lockrotation.sc entry
- Holographic indicator added when running the command, to better indicate block halves
- When locking rotation and immediately placing a block, some blocks would be placed opposite to how one would expect. This has been largely corrected.
Cleaned up errant print statement. Whoops
@TernaryC
Copy link
Author

I've added a short description to the readme, as well as a holographic indicator when running the command, which should make it a little more obvious how to use it.
I hadn't encountered the bug with shaped stairs, and while I can't seem to recreate your exact screenshot, I have found similar inconsistencies with the way stairs place when rotated.
The problem is easily resolved by simply delivering a block update to the glitchy stair block, but, of course, it doesn't seem to work if I update it programmatically. I might be missing something about the update() function?
I'll continue looking for a working solution that doesn't involve recreating the entire vanilla stair-shaping logic from scratch.

Not an ideal solution, but one that works without meaningful side effects.
@TernaryC
Copy link
Author

TernaryC commented Jul 28, 2023

Alright, I have something working. It's not ideal, but it does work and doesn't seem to have any adverse effects apart from an errant sfx.
I'm sure there must be a better way to do this.

TernaryC added 2 commits July 28, 2023 02:20
Made the stairs fix less overzealous
Added missing grindstone exception detection.
- Cleaned up and quickened stair correction code
- Fixed minor bug in hologram rendering
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants