Solved Where is PotateState and CarrotState?

Discussion in 'Plugin Development' started by Dyukusi, Jan 8, 2015.

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

    Dyukusi

    Thank you for help.

    I found CropState and NetherWartsState but it seems there aren't PotatoState, CarrotState, CocoaState and so on.
    I try to cast them to CropState but it out cast error.
    How do I get the state of them?
     
  2. hope this will help you :)
    Code:
            Block b;
            if(b.getType().equals(Material.CARROT)){
                b.getState();
            }
    
    should also work with potato
     
    ChipDev likes this.
  3. Offline

    Dyukusi

    It returns a BlockState and it hasn't growth state of Carrot and Potato.
    I think it need to cast..?
     
  4. sorry misunderstood you question...
    casting would be an idea but the Materials "Carrot" and "Potato" doesn't exist to import/cast it
     
  5. Offline

    Dyukusi

    Sorry I should have wrote more detail about the question.
    I wanna get the state that whether they state RIPE or not.

    So, anyone has an idea?
     
  6. Offline

    1Rogue Retired Staff

    http://jd.bukkit.org/dev/apidocs/

    CropState is what you would use for all of those. You don't need a different one...

    Also CropState is not a BlockState.

    Off the top of my head you might be able to check a crop's damage/meta value.
     
  7. Offline

    Dyukusi

    Yeah I thought so too but it seems can't cast to CropState.
    If can, could you provide a example code?

    Thank you for comments.
     
  8. now i got what you meant
    Code:
            Block b;
            if(b.getType().equals(Material.CARROT)){
                //cast the block as corpstate
                Crops c = (Crops) b.getState().getData();
                //get a crepitate
                c.getState();
                //set a cropstate
                c.setState(CropState.RIPE);
            }
    
    you have to define the block but i hope that will help :)
     
  9. Offline

    1Rogue Retired Staff

    Code:java
    1. Block b = /*...*/;
    2. b.setData(CropState.RIPE.getData());


    However I recommend the api-orientated solution above.
     
    sn1cko likes this.
  10. is there also a way to get the CropState without casting the block to crops ?
     
  11. @sn1cko You could get the raw data value and get the CropState from that I suppose. However, since one should check if they actually are crops first anyway, you might as well go with the casting approach.
     
  12. Offline

    Dyukusi

    I did this cast but it outs the cast error.

    I tried to some method and get the bad(?) solution.
    Code:
    CropState.getByData(event.getNewState().getData().getData();
    This code seems correctly returns the state of the crop, carrot, potato, and others but getByData method and last getData method is now deprecated.
    So I guess there is more smart method to do this.

    Even my awful English skill, thank you for helpful comments.
     
  13. but i can't get any more data from the block than b.getData()

    and yep the method where i cast the block works i think :)

    thanks for the reply
     
  14. @sn1cko That's true, but you don't need anymore data than that - the byte that getData() returns will depend on the CropState that the crop is.
     
    sn1cko likes this.
  15. @AdamQpzm i see
    thanks :)

    @AdamQpzm but my first code will work too...

    isn't that right ?
     
    Last edited by a moderator: Jan 8, 2015
    AdamQpzm likes this.
  16. @sn1cko That's right. I'd advise people to use the code you first posted rather than the raw byte value method... but it's nice to know both can work :)
     
    sn1cko likes this.
  17. yep haha that's why i asked how to get the data with raw block data

    thanks again @AdamQpzm
     
Thread Status:
Not open for further replies.

Share This Page