Checking if a block is a tile entity

Discussion in 'Resources' started by iKeirNez, May 15, 2014.

Thread Status:
Not open for further replies.
  1. Surprisingly, whilst developing a plugin, I realised there is no way to tell if a block is a tile entity. I found a small dirty "hack" to do this that should be future-proof (providing CraftBukkit doesn't rename it's CraftBlockState class)

    The "hack" is a very simple one liner:

    Code:java
    1. if (!block.getState().getClass().getName().endsWith("CraftBlockState")){
    2. // this will execute if the block is a tile entity
    3. }


    The way this works is if the block was a tile entity, the name of the class would be something like CraftChest or CraftSign. If it's not a tile entity then the class will simple be a CraftBlockState. We know this by looking at the source code for CraftBukkit: https://github.com/Bukkit/CraftBukk...bukkit/craftbukkit/block/CraftBlock.java#L246

    I thought I would post this as after searching for a way to do this I found nothing and I feel this is quite a good way to do this as we do not have to do anything with NMS.

    Please leave a like if this helped you ;)
     
    minecreatr and Phasesaber like this.
  2. Offline

    DevilMental

    I'm sorry to bump this thread but what is a tile entity ? iKeirNez
     
Thread Status:
Not open for further replies.

Share This Page