Posted January 31, 20232 yr 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]; } }
January 31, 20232 yr 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.
January 31, 20232 yr 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 January 31, 20232 yr 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.