Item Weight

Discussion in 'Plugin Development' started by JustRik, Feb 10, 2020.

  1. Offline

    JustRik

    Hello there,

    I have a question and I don't know to do that...

    What's is the best begin to make a code for Item Weight

    Example:
    If I have 10 gold in my inventory, I have to walk slower.
    It is therefore the intention that the inventory needs to be updated since you can also get the gold from your inventory.

    thanks in advance!
     
  2. Offline

    KarimAKL

    @JustRik I'm not really sure but, i guess you could create a Map<Material, Double> with the material and the weight. Then listen to inventory events so that you can update the movement speed using this:
    Code:Java
    1. Player player = ...; // Your player
    2. double speed = ...; // Get the item change, or loop the player's inventory, then get the weight and calculate the speed based on that
    3.  
    4. player.getAttribute(Attribute.GENERIC_MOVEMENT_SPEED).setBaseValue(speed);
     
  3. Offline

    Kars

    Exactly as Karim suggests. You have the data pertaining to item weight somewhere and on every inventory event, you calculate the players inventory weight and set their movement speed accordingly.
     
  4. Offline

    JustRik

    Thanks guys!
     

Share This Page