Jump to content

Increase arrow entity speed and bow draw speed.


Darkorg69

Recommended Posts

Long story short, I'm writing some mod which allows you to increase your arrow speed and bow draw speed.

Currently I'm handling this though events.

    @SubscribeEvent
    public void onArrowSpeed(@NotNull EntityJoinLevelEvent event) {
        if (event.getEntity() instanceof Arrow arrow) {
            if (arrow.getOwner() instanceof ServerPlayer serverPlayer) {
                serverPlayer.getCapability(PlayerCapabilityProvider.PLAYER_CAP).ifPresent(capability -> {
                    if (capability.isUnlocked(serverPlayer, ARROW_SPEED)) {
                        int level = capability.getLevel(serverPlayer, ARROW_SPEED);
                        //Level is value between 0 and 20;
                        if (level > 0) {
                            float modifier = 1.0F + level * 0.05F;
                            arrow.setDeltaMovement(arrow.getDeltaMovement().scale(modifier));
                        }
                    }
                });
            }
        }
    }

    @SubscribeEvent
    public void onBowDraw(@NotNull ArrowNockEvent event) {
        if (event.getEntity() instanceof ServerPlayer serverPlayer) {
            if (event.getBow().getItem() instanceof BowItem) {
                serverPlayer.getCapability(PlayerCapabilityProvider.PLAYER_CAP).ifPresent(capability -> {
                    if (capability.isUnlocked(serverPlayer, BOW_DRAW)) {
                        int level = capability.getLevel(serverPlayer, BOW_DRAW);
                        //Level is value between 0 and 10;
                        if (level > 0) {
                        //I have used AT to make this field public from protected;
                            serverPlayer.useItemRemaining -= level;
                        }
                    }
                });
            }
        }
    }
}

Problem I have is this delta movement data is not syncronized with the client, because when I shoot the arrow, at first the arrow goes in another direction and later actually syncs to it's real position.

In other words client-side animation is bugged/not properly synced.

To better visualize the problem I'm including a video:

https://streamable.com/x741gp

Any ideas how can I fix this?

Link to comment
Share on other sites

Try setting

arrow.hasImpulse = true

after you change the velocity.

If you look at ServerEntity.sendChanges() that should cause it to send an update packet instead of waiting 20 ticks (the arrow's updateInterval).

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

I think your problem is caused by the ClientBoundSetEntityMotionPacket which clamps the maximum delta at +/- 3.9d

Obviously, the same clamp doesn't happen to the real data on the server so there is an inconsistency.

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.