Solved Replanting problem ~~"

Discussion in 'Spigot Plugin Development' started by CaoTrongThang, Jan 25, 2020.

  1. Sorry because my bad English ~~"

    I want to replant wheat with crops when players break it, i have tried many ways but still not work, please help me ~~"

    Code (Text):
        public void onBreak(BlockBreakEvent e) {

            Player p = e.getPlayer();
            Block b = e.getBlock();

                if (b.getType() == Material.WHEAT) {
                    if(p.getGameMode() == GameMode.CREATIVE){
  2. Can you elaborate on what exactly is not working?
  3. My issue is when i break the wheat, it don't get replanted
  4. You can't set a block to be a Material.WHEAT_SEEDS, so look up what a baby wheat is, and then lace that instead.
    • Like Like x 1
  5. Welp looks like baby wheat is also wheat. Wheat has BlockData attached that is responsible for its growth status, so you might want to look into that (if you only want to replaced fully grown wheat plants for example)
    • Like Like x 1
  6. Can you give me an example?, i have tried many ways ~~"
  7. This works on a plugin I made in 1.9. This will probably work in 1.14.4, but with other material and other data.
    Code (Java):
    public void onBreak(BlockBreakEvent event) {
        final Block block = event.getBlock();

        if(block.getType().equals(Material.CROPS) && block.getData() == (byte) 7){
    • Like Like x 1
    • Winner Winner x 1
  8. This would need more than just a bit of tailoring.
    Here's what I mean:
    You'll need to check for the block as you did
    Code (Java):
    if (block.getType() == Material.WHEAT)
    Now, you can cast that Block-data to the data of something that is Ageable:
    Code (Java):
    final Ageable data = (Ageable) block.getBlockData();
    Be careful to import the right Ageable. There is an Ageable in entity and in BlockData. You want the latter one
    Now you can check if the plant is fully grown:
    Code (Java):
    if (data.getAge() == data.getMaxAge())
    After this, you'd cancel the event, break the block naturally and set a new Wheat. When you set it, it will be at age 0 by default
    • Agree Agree x 1
    • Winner Winner x 1
  9. Thank you guys very much :D
  10. What's the thing with the ~~" ?
  11. That is the "stupid" face icon