Solved Test if block is naturally generated

Discussion in 'Plugin Development' started by Gigabyte_Giant, Mar 8, 2014.

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

    Gigabyte_Giant

    Hi,
    I am working on a bukkit plugin, and I am wondering if there is currently a way to check if a block is naturally generated?

    If not, would there be a way I could do this manually? (Like, check block metadata, or something along those lines)

    Thanks,
    Gigabyte Giant
     
  2. Offline

    IkBenHarm

    Gigabyte_Giant
    i have never worked with metadata before, so i could be completely wrong at this.

    But maybe you can add a metadata to every placed block, check if it does not contain this data. If it does not, then you know it was naturally generated
     
  3. Offline

    Barinade

  4. Offline

    Gigabyte_Giant

    IkBenHarm I might do that, however, I have to look for the exact data that the file should contain if not naturally generated.

    Barinade How exactly would I use this? Please explain.
     
  5. Offline

    GameplayJDK

    Another way is to add a listener to the block place event, and add custom MetaData to it, like this:

    Code:java
    1.  
    2. public blockPlaced(BlockPlaceEvent event) {
    3. Block b = event.getBlock();
    4. b.setMetadata("PLACED", new FixedMetadataValue(this.plugin, "something"));
    5. }
    6.  
    7. // to get the metadata out of the block use this
    8. Block b = ...;
    9. b.getMetadata("PLACED"); // Check if it is null. If so, it was generated naturally / not placed by the player
    10. if (b.getMetadata("PLACED") == null); // do stuff
    11.  
     
  6. Offline

    Gigabyte_Giant

    GameplayJDK Thanks, just a tad bit late, like 3 minutes, I worked out something familiar, however, your code is quite a bit shorter and prettier... :D

    *Edit Also GameplayJDK, it is
    Code:java
    1. @EventHandler
    , not @EventListener. :)

    Thanks again.

    Problem is now solved, however, still open to discussion.
     
  7. Offline

    GameplayJDK

    You're welcome :)
    I plan to make a library containing that functionality of applying data to items and blocks (and other stuff), so I found out about that possibility as I started developing it 2 weeks ago
     
Thread Status:
Not open for further replies.

Share This Page