So I want to have an item that has Jump Boost when equipped (already working), and I want the movement speed to be faster in the air. Therefore, I want to change the Attribute Modifiers of my ArmorItem programatically, and at runtime.
The code below doesn't produce the expected outcome of only applying the speedup when the player holds the space key, instead it only even seems to fire if I hover directly on the item in my armor slot, pressing the space bar.
public class JumpBootsItem extends ArmorItem {
private AttributeModifier movementSpeed = new AttributeModifier("JumpBootsMovementSpeedModifier", 1, Operation.MULTIPLY_TOTAL);
public Minecraft mc = Minecraft.getInstance();
@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(EquipmentSlotType slot, ItemStack stack) {
Multimap<String, AttributeModifier> output = super.getAttributeModifiers(slot, stack);
if (slot == EquipmentSlotType.FEET && stack.getItem().equals(this) && InputMappings.isKeyDown(mc.getMainWindow().getHandle(), mc.gameSettings.keyBindJump.getKey().getKeyCode())) {
output.put(SharedMonsterAttributes.MOVEMENT_SPEED.getName(), this.movementSpeed);
LOGGER.fatal("I am holding jump, speed should change");
}
return output;
}
How to actually implement what I'm trying to do? Should I maybe instead try to simply add a "clone" of the item with the speed boost applied, then silently change it in the armor slot once the space bar is pressed?
Thanks for replies!