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

player-use-pertick-interpolated #119

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

Conversation

silnarm
Copy link

@silnarm silnarm commented Oct 14, 2023

  • add player position/rotation interpolation to perTick use action

* add player position/rotation interpolation to perTick use action
@silnarm
Copy link
Author

silnarm commented Oct 14, 2023

perTick test 1_14_4 (read-only).zip
Script should be stopping the bot before killing, in some versions the momentum carries over on respawn and messes up test reruns.

/script load pertick_test
/script in pertick_test invoke reset
/script in pertick_test invoke run_test
... wait for bot to be killed (unless something goes wrong) ...
/script in pertick_test invoke report

IServerPlayerEntity iplayer = (IServerPlayerEntity)(Object)player;
EntityPlayerActionPackActionTypeAccessor typeAccessor = ((EntityPlayerActionPackActionTypeAccessor)(Object)type);
EntityPlayerActionPack.Action self = (EntityPlayerActionPack.Action)(Object)this;
IEntityPlayerActionPackActionTypeUse actionTypeUSE = (IEntityPlayerActionPackActionTypeUse)(Object)EntityPlayerActionPack.ActionType.USE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it only support "USE" action pack? imo it's much better if all action packs support interpolation
at the same time, and them will have the same behavior

Copy link
Author

Choose a reason for hiding this comment

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

added to ATTACK as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can use the global flag suggestion described in 2. of #119 (comment), so you don't need to mixin into every action implemetation that invokes EntityPlayerActionPack#getTarget

{
private float tickPart = 1.0f;

@Redirect(
Copy link
Contributor

Choose a reason for hiding this comment

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

@Redirect is bad, try use @ModifyExpressionValue or @WrapOperation from mixin extra, or set require = 0 if you do need an @Redirect

Copy link
Author

Choose a reason for hiding this comment

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

Yes, bad I know. It is carpet code at least, not MC. Added the require = 0, but I was unable to get rid of it, @ModifyExpressionValue gave an unhelpful error message, but I assume the static function is the problem.

@Fallen-Breath
Copy link
Contributor

Some suggestions:

  1. Store the posLastTick stuffs inside EntityPlayerActionPack instead of storing in ServerPlayerEntityMixin
    • It's for tweaking the action pack, then place it inside the action pack
    • It's also a per-player object
  2. Use ThreadLocal to store your extra custom argument (tickPart) to alternate the logics inside carpet.script.utils.Tracer#rayTrace, then do @ModifyArg inside the rayTrace method
    • A more proper (and suggested iirc.) way to pass a custom variable, in cause multiple EntityPlayerActionPack run at the same time
    • Then you can just set / clear the ThreadLocal at the beginning / end of the perTickMultiplier multiplier logic


actionTypeUSE.setTickPart(1.0f);
iplayer.swapOldPosRot(false);
iplayer.pushOldPosRot();
Copy link
Contributor

Choose a reason for hiding this comment

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

So here's where you record the rotation and position of the player:

  • when the action starts
  • when the action completes an execution

You're assuming that the player moves smoothly between 2 positions, but this assution might be wrong. The player might be teleported, and teleporation do not have interpolation

Copy link
Author

Choose a reason for hiding this comment

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

This is true. I had largely discounted it as an issue originally because player reach meant the use attempts would do nothing anyway, but it will potentially load chunks which does suck.
Will have a think about it, seems like it will be a few more injects at least though, I'm not convinced it is worth handling this explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

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

imo, it's import to ensure interpolation only applies in the correct scenarios. As you mentioned, interpolating in unexpected scenarios can cause problems, especially since carpet doesn't provide fine-granular permission system for these commands

and that's why the interpolation feature is hard to implement

* remove static in ActionType.USE, move 'tickPart' to ActionPack.
* move last tick pos/rot into Action
* dupe USE mixin for ATTACK
* change some names
@Fallen-Breath Fallen-Breath added the change requested Change is requested for this PR to merge label May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
change requested Change is requested for this PR to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants