Solved Subtypes with Crops and Trees

Discussion in 'Plugin Development' started by hellobrad100, Dec 19, 2014.

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

    hellobrad100

    Hello everyone,

    I am making a plugin that automatically places a sapling after you destroy the log.

    I have achieved that part, brilliant. However I'm stuck with the Subtypes.

    How would I use subtypes within my code here:

    Code:
                Location under = e.getBlock().getLocation().subtract(0, 1, 0);
                int underb = under.getBlock().getTypeId();
                Block b = e.getBlock();
                if(b.getTypeId() == 17)
                {
                    if(underb == 3)
                    {
                        e.setCancelled(true);
                        b.setTypeId(6);
                    }
                } 
    I have tried multiple ways, but can't seem to crack it, it is most likely something very basic and I'll end up looking like a noob. :p

    And an additional question, it will be the same for the crops, however I only want the grown crops to be destroyed then replaced with the type like you have just planted the seeds. Is it subtypes again? or something completely different?

    - Brad
     
  2. Offline

    Skionz

    @hellobrad100 What is a subtype? Are you talking about data? I would use the getData() and setData() method.
     
  3. Offline

    hellobrad100

    @Skionz You know in Minecraft how there is 6 types of trees?
    Different Colours of wool? Different types of wood? A subtype is basically the mini-type in effect I guess.

    Eg: an Oak log's ID is 17, whereas a Birch Log's ID is 17:2

    However with bukkit, they all fall under Material.LOG or the ID 17, so you need a different method to be able to use the subtypes, which I can't seem to do, so that is why I'm here. xD
     
  4. Offline

    Skionz

    @hellobrad100 Yes. Then use the Block#getData and setData methods.
     
  5. Offline

    hellobrad100

    @Skionz Figured it out, thanks so much for your help!
     
Thread Status:
Not open for further replies.

Share This Page