Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Issues with instanceof and getId()

Comments in 'Plugin Development' started by MyNameIsTriXz, Mar 27, 2016.

  1. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    You cant check if a tile in getTiles is a sign by using these 2 things up here, so how can I get it working?
  2. MCPEPIG
    Offline

    MCPEPIG Notable Member

    Joined:
    Jun 22, 2014
    Posts:
    349
    Minecraft User:
    MCPEPIG
    Try:
    PHP:
    foreach($level->getTiles() as $tile){
      if(
    $tile instanceof Sign){
        
    //Code
      
    }
    }  
    MyNameIsTriXz likes this.
  3. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    Be careful, "Sign" class could be either type of Block, Item or Tile... Check your namespaces twice
    Ritch, PEMapModder and MyNameIsTriXz like this.
  4. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    Oh I already got the problem solved by getting the sign as block and then getting its id, but I still wonder why it has entity like IDs and wasnt also recogized as an instanceof the Sign class, even as I dumped the type using get_class() hmm
  5. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    The problem was that instanceof Sign doesnt work for me.
  6. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    What are you willing to work with? Block or Tile?
  7. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    The tile, to modify the sign text.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Make sure you have `use pocketmine\tile\Sign;`?
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    How to debug:

    1. Do var_dump($sign instanceof Sign) to make sure that it is this line that has a problem.
    2. Do var_dump(get_class($sign)) to make sure you indeed have signs in your world.
    3. Do var_dump(Sign::class) to check if you got the imports right.
  10. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    I debugged everything hmm
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Are the chunks loaded at all? What is the output of the var_dump()s?
  12. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    The sign instance, but when I do instanceof it returns false
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    So, have you tried `var_dump(get_class($sign) === Sign::class)`? I still believe that you have a typo in your use statement for pocketmine\tile\Sign.
  14. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    No, I dumped with get_class, I even copied the class name from the docs, to be sure

Share This Page

Advertisement