Solved Remove tags from potions

Discussion in 'Plugin Development' started by ShowbizLocket61, Jan 18, 2016.

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

    ShowbizLocket61

    Hi,
    So you know those tags on the potions saying "Instant Health II" or "Poison: 3:00"?
    Well, I want to get rid of them.

    This method works on swords and tools but not potions:
    Code:
    public static ItemStack removeAttributes(ItemStack i){
            if(i == null) {
                return i;
            }
            if(i.getType() == Material.BOOK_AND_QUILL) {
                return i;
            }
            ItemStack item = i.clone();
            net.minecraft.server.v1_8_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
            NBTTagCompound tag;
            if (!nmsStack.hasTag()){
                tag = new NBTTagCompound();
                nmsStack.setTag(tag);
            }
            else {
                tag = nmsStack.getTag();
            }
            NBTTagList am = new NBTTagList();
            tag.set("AttributeModifiers", am);
            nmsStack.setTag(tag);
            return CraftItemStack.asCraftMirror(nmsStack);
        }
    How can I remove it from a potion?
     
  2. Offline

    ShowbizLocket61

  3. Offline

    HenrySartori

    I don't think this is possible. If it is, only change Bukkit Source =(
     
  4. Offline

    Zombie_Striker

    @ShowbizLocket61
    I do not think you can get rid of the tags. That is handled on the client's side. What you can do is "give" the player the effects without potions (E.g. Add more damage to a hit without giving the player strength, increasing the velocity of a jump instead of giving them a jump boost.)
     
  5. Offline

    ShowbizLocket61

    @Zombie_Striker @HenrySartori
    I am attempting to use a potion not for the effects, but for the display in a GUI. A water bottle suffices, but just doesn't look the same.

    Since you could do this with tools, I feel like there should be a way with potions.
     
  6. Offline

    Zombie_Striker

    How so? Can you explain what you mean?
     
  7. Offline

    ShowbizLocket61

    @Zombie_Striker
    This here piece of code:
    Code:
    public static ItemStack removeAttributes(ItemStack i){
            if(i == null) {
                return i;
            }
            if(i.getType() == Material.BOOK_AND_QUILL) {
                return i;
            }
            ItemStack item = i.clone();
            net.minecraft.server.v1_8_R3.ItemStack nmsStack = CraftItemStack.asNMSCopy(item);
            NBTTagCompound tag;
            if (!nmsStack.hasTag()){
                tag = new NBTTagCompound();
                nmsStack.setTag(tag);
            }
            else {
                tag = nmsStack.getTag();
            }
            NBTTagList am = new NBTTagList();
            tag.set("AttributeModifiers", am);
            nmsStack.setTag(tag);
            return CraftItemStack.asCraftMirror(nmsStack);
        }
    Can remove it from tools. Not potions.
     
  8. Offline

    Zombie_Striker

    @ShowbizLocket61
    I think the problem may be that potions do not store their potion effects the same way as enchantments. Try looping through all the values to see where the potion data is stored.
     
  9. Offline

    87pen

    ShowbizLocket61 and bennie3211 like this.
  10. Offline

    ShowbizLocket61

    @87pen
    Thanks, mate. That helped a lot!

    Solution was this simple one-liner:
    Code:
    itemMeta.addItemFlags(ItemFlag.HIDE_POTION_EFFECTS);
     
Thread Status:
Not open for further replies.

Share This Page