Closed hammy275 closed 1 year ago
Will only support primary hand throwing.
Looks like the way to do this is a mixin into Projectile#shootFromRotation
.
We'll want to average the velocity of the hand every tick for the past 3 ticks and use that as our throwing velocity. Might move this to server-side at some future point, but for now, I'll run this client side. On release, we send a packet to the server containing the velocity we should throw at.
From there, the server will call use
or releaseUsing
(depending on the item) after adding the player to a global HashMap
. Call it vrNextThrowData
or something, with keys being player names or UUIDs, and values being the velocity from the packet.
In our Mixin, we check if the player is part of the aforementioned HashMap
. If so, we use their hand's rotation. Additionally, at the end of shootFromRotation
, we check again if they're in the HashMap
. If so, we remove them from the map, and use the provided velocity to augment the delta movement of the projectile. This augmentation I'll have to experiment with until I find something that "feels right".
Based on https://minecraft-archive.fandom.com/wiki/Category:Projectiles , we'll support the following items:
Notable exceptions:
shootFromRotation
, and would just generally feel "weird" to throw due to how they travel in-game.Also, since people may throw things in a variety of different ways, to determine the direction, we'll do the difference between the current controller pos and the last, then normalize it. To get it to a x and y rotation, we should be able to reverse the calculation done in Entity#calculateViewVector
. Note that the constant being multiplied there is pi/180.
EDIT: Also, for throwable items, we always cancel their left click action with the exception of the Trident, which we only cancel if we're not hovering over an Entity at melee range.
For where I'm currently stuck, here are some ideas:
shootFromRotation
, or do something similar to the Before PR and replace the ModifyVariable
s with our own. Ideally if it exists, we can put our ModifyVariable
after Vivecraft'sModifyVariable
calls, and modify from thereEntire pivot:
Instead of trying to override shootFromRotation
as a whole (since MIxin config plugins can't affect other mods, it seems), instead, we can take advantage of @Redirect
. For each individual item, whenever it calls shootFromRotation
from its use
method (or the other for Tridents), we call our own entire shoot method instead. If we personally don't run, pass control over to the normal shootFromRotation
instead.
Part 1 of this is at https://github.com/hammy3502/immersive-mc/commit/9df56606c086c9bc44a684df2ff2538f56485abb .
Things left to do:
deltaMovement
of it by our velocity factor.Trident rendering done (even comes with rumble!)
Velocity tuning is done! Next is a config entry, then we can port to other versions!
I don't even need to worry about not blocking it for the first tick; we run at the end of the game tick! :)
It already works identically in Optifine Vivecraft let's gooooo
This is finally done! Here's all the commits from oldest to newest:
See this thread on the ImmersiveMC Discord: https://discord.com/channels/1061675558347489343/1065409551324684288