1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

More Secure Custom Items

Discussion in 'Development' started by CupidonSauce173, Aug 12, 2019.

  1. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Hello everyone! I had a question
    currently, we can create ""custom items"" with a crafting shape and a custom name, the current problem is that if someone rename an item with the name of one of the custom items name, it will have the same behavior.
    We can do a double check with the meta but it's only working with items that doesn't get damage (food, ores, etc) but for armor and weapons, it doesn't work. Is there any better idea to be sure that a player cannot cheat just by renaming an item ? Ik there is enchants but I try to avoid that.
     
  2. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    24
    GitHub:
    mrpandaz
    NBT Tags Are Another Way
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    "Custom items" having "custom behaviour" shouldn't rely on an identifier that can be changed by them... like item name as you mentioned. Use nbt tags instead.
     
  4. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    I keep saying stuff about NBT but never really understood how to use them, can you explain please ?

    Yes I know, this is exactly why I made this post, actually, I was hoping that someone mention NBT tags but I wasn't sure that I was correct.
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    It's simple. You set an nbt tag onto an item so you can verify it is a custom item by checking if it has that tag. See how https://github.com/dktapps-pm-pl/AimTP does it.
     
    CupidonSauce173 likes this.
  6. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    $stick->setNamedTagEntry(new ByteTag(self::AIMSTICK_TAG, 1));
    Ah ok I see, it's much easier than I thought. Thank you very much for your help.
     
    Muqsit likes this.
  7. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    setting a namedTagEntry on custom crafted items seems to not work.
    PHP:
            $i Item::get(Item::MUSHROOM_STEW01);
            
    $i->setCustomName("Iderula Soup");
            
    $i->setNamedTagEntry(new StringTag("IDERULA_SOUP"'aaaaaasdfasdf'));
            
    $LE = new EnchantmentInstance(Enchantment::getEnchantment(Enchantment::PROTECTION));
            
    $LE->setLevel(1);
            
    $i->addEnchantment($LE);
            
    $CEB = new ShapedRecipe(["AAA"," B ","AAA"],
                [
    "A"=>Item::get(Item::SPIDER_EYE01), "B"=>Item::get(Item::MUSHROOM_STEW,1)],[$i]);
            
    $CEB->registerToCraftingManager($this->getServer()->getCraftingManager());
    Doing that will make the item to disappear when you try to hold it
     
  8. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Crafting inputs don't support any kind of nbt tags (incl custom name, lore, ench)
     
    CupidonSauce173 likes this.
  9. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    So should I set the NBT on CraftItemEvent if customname = to example Iderula Soup ?
     
  10. DaRealPandaz

    DaRealPandaz Silverfish

    Messages:
    24
    GitHub:
    mrpandaz
    sure, it should work
     
  11. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    You really shouldn't do this. If you were around for the mob spawner debacle of 1.9.0 you should know this.

    For the uninitiated, magic meta values are not supported by Minecraft and they may break at any time without any warning. Meta values which don't exist in vanilla are on borrowed time. They work by accident, and they will stop working in the future.
     
    CupidonSauce173 likes this.
  12. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    This is why I was asking another way to make checks on what is what
     
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.