Cancel dirt to grass

Discussion in 'Plugin Development' started by shohouku, Jun 2, 2014.

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

    shohouku

    So what I'm trying to do is cancel when dirt turns into grass. Not when grass turns to dirt!

    I'm trying to use dirt as a block so it doesn't turn to grass.

    I'v tried this:

    Code:java
    1. @EventHandler
    2. public void onBlockPhysics(BlockFadeEvent event){
    3. if (event.getBlock().getType() == Material.DIRT) {
    4. event.setCancelled(true);
    5. }
    6. }
     
  2. Offline

    Shlobdon

    If I'm not mistaken, this should work: If the material is dirt, make it grass instead of canceling the event. (This WILL cause strain on the server when starting new worlds and such, and there's more than likely an easier way to do it, but it's worth a shot).

    I suppose you could even check to see that ONLY if the dirt block is in contact with an air block only THEN shall it change the dirt block to a grass block. (This could still cause strain on the server, but I wouldn't suppose it would cause too much. I'm not great at this yet and I'm still learning, so I could be all wrong xP)
     
  3. Offline

    shohouku


    I'm trying to cancel when dirt turns grass.

    Not when grass turns to dirt.
     
  4. Offline

    Shlobdon

    My bad, I read this wrong. It's 2:23 AM. (Bit tired but don't wanna sleep.)
     
  5. Offline

    shohouku

    #bump!
     
  6. Offline

    L33m4n123

  7. Offline

    desht

    You're using the wrong event. BlockSpreadEvent is called when dirt turns to grass (the adjacent grass is, in effect, spreading).
     
  8. Offline

    shohouku


    Im assuming BlockFormEvent works?
    Testing it now.
     
  9. Offline

    desht

    The actual event fired is a BlockSpreadEvent (see BlockGrass in Craftbukkit), which is a subclass of BlockFormEvent.
     
  10. Offline

    Necrodoom

    Or, as desht said, blockspreadevent. See javadocs.
     
  11. Offline

    L33m4n123

    He tells you exactly which event is being called and you use another one? Whut?
     
Thread Status:
Not open for further replies.

Share This Page