Setting Block To Empty Flower Pot

Discussion in 'Plugin Development' started by elfin8er, Mar 19, 2014.

Thread Status:
Not open for further replies.
  1. All I want to do is set a block to an empty flower pot.

    Code:
    new Location(world, x, y, z).getBlock().setType(Material.FLOWER_POT);
    This sets the block as a flower pot, but the flower pot has a sapling in it. I want to spawn an empty pot. How would I do so?
     
  2. Offline

    rfsantos1996

  3. Thanks, I'll mess around with these a bit. In the mean time, if anyone just knows how to do it, I could still use the help.

    Edit: This is what I'm trying:
    Code:
    loc.getBlock().setType(Material.FLOWER_POT);
    FlowerPot pot = (FlowerPot) loc.getBlock();
    pot.setContents(null);
    loc.getBlock().getState().update();
    
    Apparently, the second line can't cast the block to FlowerPot, even though it was just set to be a FlowerPot. I feel like I'm missing something here...
    Also, I don't understand what argument pot.setContents would require for air.
     
  4. Offline

    Bammerbom

    elfin8er
    #1 pot.setContents(Material.AIR);
    #2 FlowerPot pot = (FlowerPot) loc.getBlock().getState();
     
  5. Offline

    rfsantos1996

    .getState() on getBlock() ;3
     
  6. pot.setContents requires a MaterialData parameter, not a Material parameter.

    rfsantos1996 Still unable to get this working. Any ideas?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  7. Offline

    rfsantos1996

    Code:java
    1. loc.getBlock().setType(Material.FLOWER_POT);
    2. loc.getBlock().getState().setData(new FlowerPot(Material.AIR)); // test with null later
     
  8. Didn't work. Also tried
    Code:
    loc.getBlock().getState().setData(new FlowerPot(null));
    
    Got a null pointer exception, and also tried adding
    Code:
    loc.getBlock().getState().update();
    
    With no success.
     
  9. Offline

    rfsantos1996

    Then I don't now, this is all I can think that may work... :/
     
  10. Hmm, well thanks for your help so far!

    Anybody else have any other suggestions?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
    rfsantos1996 likes this.
  11. Last change, and then I'll let it go.
     
Thread Status:
Not open for further replies.

Share This Page