Get Potion Data out of Damage Value

Discussion in 'Plugin Development' started by KoffiePatje, Mar 28, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    KoffiePatje

    What i'm trying to do is resolve the potion id, level, splash and extended value out of the dammage value. I already made sure that my item is a potion before doing this:

    Code:
     
    int damage = a_Item.getDurability();
     
    PleducPVPListener.pp.getLogger().info( Integer.toString( damage ) );
     
    // Bitshifting to get values - for the win
    m_PotionID = getPotionID( damage & 0xF );
    m_PotionLvl = ( ( damage & 0x20 ) >> 5 ) + 1;
    m_PotionSplash = ( ( damage & 0x4000 ) > 0 )?1:0;
    m_PotionExtended = ( ( damage & 0x40 ) > 0 )?1:0;
     
    
    EDIT: a_Item is an ItemStack, and is an ItemStack retrieved from the players, PlayerInventory.

    The Bitshifting works like a charm, however when im trying to retrieve the Durability / Damage value i get values that are not in "Potion Damage Value" range....

    Code:
    Output:
     
    01:22:04 [INFO] [PleducPlugins] 16318 - Should be 8206 ( according to the Wiki )
    01:22:04 [INFO] [PleducPlugins] 16369
    01:22:04 [INFO] [PleducPlugins] 32725 - Should be 16421 ( according to the Wiki )
    01:22:04 [INFO] [PleducPlugins] 32724
    01:22:04 [INFO] [PleducPlugins] 32721
    01:22:04 [INFO] [PleducPlugins] 32755
    01:22:04 [INFO] [PleducPlugins] 16370
    01:22:04 [INFO] [PleducPlugins] 16371
    01:22:04 [INFO] [PleducPlugins] 32758

    Anybody got any idea why a_Item.getDurability(); is returning these bogus values?

    Thanks in Advance !

    EDIT: Got the bitshifting part out of Bukkits own code: http://jd.bukkit.org/rb/apidocs/src-html/org/bukkit/potion/Potion.html#line.366

    Little Bump (A)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  2. Offline

    KoffiePatje

    Second ( and last ) bump
     
  3. Offline

    kreashenz

  4. Offline

    KoffiePatje

    kreashenz No it doesnt, when i create new potions out of the values i've got, i get errors like instant potions can't be extended, because the m_PotionExtended value is set to 1

    i do notice an obvious increase in every number becuase all values seem to be twice the original with a little bit added....

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  5. why you server reported 10 messages, while you printed 0 messages wit the code?
     
  6. Offline

    KoffiePatje

    ferrybig This code is inside a for loop that loops over a player inventory, if the inventory contains multiple potions it prints multiple

    Has anyone ever used this function with succes?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
Thread Status:
Not open for further replies.

Share This Page