Solved Stop crops from breaking on bock update

Discussion in 'Plugin Development' started by Tacodude, Aug 10, 2020.

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

    Tacodude

    I have made it so you can place wheat crops on sand. The placing works fine but when I place a block next to the crops and they get updated, the game realizes that crops are not supposed to be growing on sand, so they break. I don't know what event gets called when they break like this (not BlockBreakEvent because no player is responsible for the breaking).

    How do I stop the crops from breaking?
     
  2. Maybe BlockPhysicsEvent?
     
  3. Offline

    Tacodude

    Worked like a charm, thanks! [I feel like this event could have a better name] The code for this encase anybody who finds this in the future:

    Code:
        if (e.getBlock().getType() == Material.WHEAT) {
           Location l = e.getBlock().getLocation();
           if (e.getBlock().getWorld().getBlockAt(l.getBlockX(), l.getBlockY() - 1, l.getBlockZ())
               .getType() == Material.SAND) {
             e.setCancelled(true);
           }
         }
     
    Last edited by a moderator: Aug 10, 2020
  4. @Tacodude just remember that the BlockPhysicsEvent is called often thousands of times per second, so if you don't want lag don't do any heavy processing in it (this should be just fine I think).
     
  5. Offline

    timtower Administrator Administrator Moderator

    You sure you are not confused with the PlayerMoveEvent?
     
  6. Offline

    KarimAKL

    @timtower
     
    pietermantel likes this.
  7. Offline

    timtower Administrator Administrator Moderator

    Yeah, can't argue with that one XD
    Thanks
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page