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

Solved str_replace not working?(Item Custom Names)

Discussion in 'Development' started by ShushImSam, Aug 17, 2019.

  1. ShushImSam

    ShushImSam Spider Jockey

    Messages:
    37
    Hey, so Im making custom enchantments and I want to replace (Ex Haste 1 is already in the name) With Haste 2, so Here's what I do
    PHP:
            if($item->hasEnchantment($enchantment->getId())){
                
    $lvl $item->getEnchantment($enchantment->getId())->getLevel();
                
    $name $item->getName();
                
    str_replace("\n" $e->getName() . " " $lvl''$name);
                
    var_dump($lore);
                
    $item->setCustomName($name);
                
    $item->removeEnchantment($enchantment->getId());
            }
    Though It doesnt remove it,

    for ex the name of a pickaxe would be "Diamond Pickaxe\n§9Haste 1"
    We want to remove \n§9Haste 1
    then we set \n§9Haste 2
    but thats not working, it just sets \n§9Haste 2 without removing the other one which is pretty annoying

    "e->getName()" = §9Haste
    Ive tried var_dump and it gets the correct String, but it doesnt remove it
     
    Last edited: Aug 17, 2019
  2. ShushImSam

    ShushImSam Spider Jockey

    Messages:
    37
    ok well.. what Ive done is assigning the str_replace to a variable and made a string instead(don't think it will change anything but oh well) and it works.. I really need to start waiting before posting in these forums
    PHP:
    $hi "\n$name $lvl1";
                
    var_dump($hi);
                
    $hello str_ireplace($hi""$lore);
                
    $item->setCustomName($hello);
                
    $item->removeEnchantment($enchantment->getId());
     
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Why not use item lores instead?
     
  4. ShushImSam

    ShushImSam Spider Jockey

    Messages:
    37
    I want it to look more like Actual Enchantments
     
  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.