Solved How to place a leaves block without decaying?

Discussion in 'Spigot Plugin Development' started by szaros123, Jan 26, 2019.

  1. Hi guys i'm trying to place a bush in my world using blockpopulator , but when i place it and wait few minutes it disappears.

    How can i fix it? Is there a blockdata which controlls the decay?


    Code (Java):
    world.getBlockAt(loc).setType(Material.OAK_LEAVES,false);
    I am placing the leaves next to a oak log.
     
  2. Googled: leaf decay spigot java

    Result
     

  3. Hmm im not quite sure how to call it, do you have any idea?


    Code (Java):
    BlockData bd = Material.OAK_LEAVES.createBlockData();
    Returns

    Code (Text):
    CraftBlockData{Block{minecraft:oak_leaves}[distance=7,persistent=false]}
    But when i try
    Code (Java):
    BlockData bd = Material.OAK_LEAVES.createBlockData("persistent:true");
    it doesnt work

    Im trying like this way
    Code (Java):
    Block block = loc.getBlock();
    block.setBlockData(I NEED THE BLOCKDATA HERE);
     
  4. What options do you have with bd?
     
  5. To get the block data, use Block#getBlockData and then work from there as i wrote above.
     

  6. I'm trying with but my IDE isnt showing up the options im not sure about if its the right way.

    Code (Java):
    if (block.getBlockData() == BlockData.?!?!)
    i already imported
    import org.bukkit.block.data.type.Leaves;
     

  7. I tried to overwrite the blockdata as a string and then apply to a specific block


    Shows up this

    [​IMG]
     
  8. Why are you trying to compare it to something? Use something like this

    Code (Java):
                Block block = world.getBlockAt(loc);
               
                BlockData leavesData = (Leaves) block.getBlockData();
                leavesData.setPersistent(true);
                block.setBlockData(leavesData);
     
    • Like Like x 1

  9. Thanks , i guess that was the problem i didnt know that i can cast it to leaves. Well thanks.
     
    • Friendly Friendly x 1