Need some help with blockbreakevent

Discussion in 'Plugin Development' started by PenguinsOfMadagascar, Jul 26, 2019.

Thread Status:
Not open for further replies.
  1. So basically, i'm trying to create a drugs / "weed" plugin. Not seriously trying to release it but imo it's a good way to learn about the development of plugins.

    Currently this is my class. I know it's a little messy but I only started today.

    https://gist.github.com/PenguinsOfm/1c317a7bc30c1af0e89bbd6cf4b705c5

    So basically, i need seeds that i place with the name "Sativa Seeds", and when I harvest the wheat it'll be named "Sativa Weed" or something. The code above runs but i'm not sure how to progress it in the way i want to.

    I know i could probably make it look for a certain name or tag or something but i'm not sure how, again I have little experience with this library.

    Any replies or methods on how to create this would be greatly appreciated. Thanks : )
     
  2. Offline

    KarimAKL

    @PenguinsOfMadagascar Blocks or items? (I got a little confused on what exactly you wanted, lol. :p)
    EDIT: If you want to check the block then i would probably store the block (seed)'s location and some other information inside a class. (I don't think block meta saves through restarts)
     
    PenguinsOfMadagascar likes this.
  3. I would be placing seeds with a custom name, and breaking the grown crops from those certain custom seeds to give custom wheat, you can place normal seeds, get normal wheat, i was wondering if i could do something like this

    (this is pseudo code i know it won't run)
    onBlockBreak
    if (block = material.CROPS)
    {
    if(blockname == "Sativa Seeds")
    {
    drop wheat named "Sativa Weed"
    }
    }

    I hope that explains what i'd like it to do, regardless of whether thats the correct way to do it. thanks :)
     
  4. Offline

    KarimAKL

    @PenguinsOfMadagascar Blocks can't have names, instead you could do something like this:
    Code:Java
    1. private final List<Location> sativaSeeds = new ArrayList<>();
    2.  
    3. private void onBlockPlace(BlockPlaceEvent e) {
    4. sativaSeeds.add(e.getBlock().getLocation());
    5. }
    6.  
    7. private void onBlockBreak(BlockBreakEvent e) {
    8. sativaSeeds.remove(e.getBlock().getLocation());
    9. }

    Then you can do the same for your other seeds as well.
     
    PenguinsOfMadagascar likes this.

  5. Thank you, i'll give it a go :).
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page