quick sign check

Discussion in 'Plugin Development' started by Techy4198, Sep 16, 2013.

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

    Techy4198

    hello is there a way to quickly check if a vertical column of blocks (y:0 to y:255) contains a sign with [VFlipBoard] on the first line, and if so, return the other 3 lines?
     
  2. Offline

    EdenCampo

    Techy4198

    Loop all the blocks in the arena, get the block at the location and convert to a sign, then get it's lines and return them via a method.
     
  3. Offline

    Techy4198

    EdenCampo
    nononono. I know about that way, but I need a QUICKER way, as I need to check every vertical column of blocks in every currently loaded chunk in the world, several times a second, possibly in multiple worlds. this is because I want fully customizable game boards (and it's not arena-based, btw. it's based on a minigame from Pokémon, Voltorb Flip) and would rather not use game board regions.
     
  4. Offline

    CubieX

    Then why not register those signs on creation in some flatfile or database?
    So you would only have to check/update those known sign locations.
     
  5. Offline

    metalhedd

    Chunk.getTileEntities() should make it considerably quicker.
     
  6. Offline

    Techy4198

    THANKS! now is there any way to quickly do that for every loaded chunk in the world, rather than looping over every chunk and checking if its loaded?
     
  7. Offline

    CubieX

    getWorld(world).getLoadedChunks()
     
  8. Offline

    Techy4198

    CubieX I wanted a faster way than iterating over chunks... but I guess using regions is the only way. now can you please tell me, how do I get the text off a sign, once I have it as a block? I know it is block.getBlockState() but whats the next bit? I forgot. and I know that the tile entities thing probably doesn't return blocks but I want to test the iteration method first, I wrote it all down (in perfect java) today while I was bored in school, and ive just perfected it
     
  9. Offline

    CubieX

    You are mixing things up.
    My suggestion was, to save a signs location in a yaml file or a database, so you only have to search through those known positions.
    This is faster than anything else, because you will not need to iterate over thouands of locations or through thousands of tile entities to find a sign in the first place.
    You KNOW there is a sign at every saved location (unless it has been removed without you noticing it. In this case you would delete it from the list).
    So you search will need a minimum number of steps to find the sign you want.
    If you can't register those signs locations on placement for some reasons (for example because the are all placed already), then you have to iterate through all tile entities of all loaded chunks, like metalhedd suggested.

    To get the text from a (possible) sign, do the following:
    Code:
    if((block.getType() == Material.SIGN_POST) || (block.getType() == Material.WALL_SIGN))
    {
      Sign mySign = (Sign)block.getBlockState();
      String[] lines = mySign.getLines();
    }
    If lines are empty, the array may have less than 4 elements. (not sure about this though)
    So to be safe, check the element count before accessing the element at an index.

    May I ask what action will trigger the search for a sign?
    Because depending on how this works, one or another method of finding those signs will be more efficient.
    Currently I guess you want to iterate those signs time triggered by some scheduler.
     
  10. Offline

    Techy4198

    CubieX yea... casting seems obvious. but last time I tried, and it was definitely on a sign, the server crashed saying that BlockState cannot be cast to Sign :/
     
  11. Offline

    CubieX

    There is no other way. If you properly checked the block for a sign, it will work.

     
  12. Offline

    Techy4198

    I want it done quickly because I want to my minigame to 'tick' every, idk, lets say 4, minecraft ticks, so yes a scheduler
     
Thread Status:
Not open for further replies.

Share This Page