Jump to content

setWalkingSpeed only applies after rejoining game


Lexjp

Recommended Posts

When the below code runs in game adding/removing a piece of bronze armor will change the players FOV, however the speed change only applies if you leave the game and rejoin.

How is it possible to dynamically change the speed as the player adds/removes pieces of bronze armor?

 


    @SubscribeEvent
    public void onPlayerTick(TickEvent.PlayerTickEvent event) {
        Player player = event.player;
        Iterable<ItemStack> slots = player.getArmorSlots();
        final int[] bronzeArmourItemCount = {0};
        slots.forEach(itemStack -> {
            if (itemStack.is(ModItems.BRONZE_BOOTS.get()) ||
                    itemStack.is(ModItems.BRONZE_LEGGINGS.get()) ||
                    itemStack.is(ModItems.BRONZE_CHESTPLATE.get()) ||
                    itemStack.is(ModItems.BRONZE_HELMET.get())) {
                bronzeArmourItemCount[0]++;
            }
        });

        if (bronzeArmourItemCount[0] != lastBronzeArmourItemCount) {
            player.getAbilities().setWalkingSpeed((float) (0.1+bronzeArmourItemCount[0]*0.075));
            lastBronzeArmourItemCount = bronzeArmourItemCount[0];
        }

    }

 

Link to comment
Share on other sites

Unfortunately no change, I've read through a couple classes and haven't seen an obvious flag,


would there be a way to do this by calling player.getAbilities.loadSaveData(pCompound)? I'm not sure what the pCompound would be if this were to work...

EDIT: Pretty sure this won't work as the loadSaveData method only sets this.walkingspeed which already shows the correct value



The other strange thing I saw was a method

/**
 * Sends the player's abilities to the server (if there is one).
 */
public void onUpdateAbilities() { }

had no idea why there was nothing actually in the method?

Edited by Lexjp
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.

Announcements



×
×
  • Create New...

Important Information

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