Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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];
        }

    }

 

There's a flag in the game that prevents it from checking for changed abilities every tick. I believe it's hurtMarked()?

Try using that, to tell the game something has changed.

  • Author

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

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.