Solved Having trouble with Sapling data etc.

Discussion in 'Plugin Development' started by LeePMC, Jun 18, 2015.

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

    LeePMC

    Hi,

    so i was doing some research into changing sapling types, i then realised i needed Byte data to see what type of sapling it is, and before i go anymore i should probably tell you what I'm trying to do

    so i have thought of this much, a hash map storing the Log type and sapling data type, all i need is that if a wood log is broken (yes i already know listeners its just getting the sapling type) check the log type (got the log type all planned out too) then use the log type to get the sapling data from the hash map... but once i have the sapling data (-1, 0-5) i will then need to set the sapling type but thats the one thing i don't know how to do, i have been experimenting and this is what i have so far (its not a working plugin I'm just literally experimenting with what i can to)

    Code:
    Block block = this.getServer().getPlayer("LeePMC").getLocation().getBlock();
            BlockState state = block.getState();
            MaterialData data = state.getData();
            Tree sap = (Tree) data;
            sap.setSpecies(TreeSpecies.BIRCH);
            Material blah = new ItemStack(Material.SAPLING).getType();
            String blahString = blah.toString();
            this.getLogger().info(blahString);
            Class<? extends MaterialData> dasta = Material.SAPLING.getData();
           
    now what i need clarified is when i get the sapling data type (0-5) how do i use that to set the sapling block, whether it be before the sapling is placed in the world, or changing the type after the sapling is placed in the world, all help is greatly appreciated and boy oh boy will i be so happy after i clear this up.....
     
  2. Offline

    Drkmaster83

    Well, it's a bit late for me at the moment, so pardon if I misinterpret your question... but from skimming over this, it appears you're trying to change any given block at your location to a species sapling.

    First off, I'd rant about how you shouldn't force cast that MaterialData to a tree until you've checked its object instance, but you know, I'll let you do what you do. For all I know, this is psuedocode.

    Secondly, the way that I'd go about it is perhaps... call state.setData(sap); and then see if that works, maybe? If it doesn't, then state.update();.

    Just my thoughts on the matter. G'luck, bud.
     
  3. Offline

    LeePMC

    well thanks for the help anyway xD ill just have to figure it out myself because it seems no one on this whole website knows how to set a saplings data, oh and I'm trying to place a specific species of sapling based on the type of tree log that was destroyed, getting the type of data is easy with a hash map but setting the data to the sapling before/after it has been placed in the world is the hard part
     
  4. Offline

    tomudding

    Code:
    ItemStack sapling = new ItemStack(Material.SAPLING, 1, (byte) 2);
    is a birch sapling. Thats all I can say at the moment.
     
  5. Offline

    LeePMC

    so if i did the same thing but changed the byte to hashmap.get(birch) which will return the birch byte number?

    that helps me so much, i can actually finish my plugin now thanks!
     
  6. Offline

    tomudding

    If I understand you, you'll have to make it so that it knows that BIRCH is 2, ACACIA is 4 etc... and than you can do something like this \/
    Code:
    ItemStack sapling = new ItemStack(Material.SAPLING, 1, (byte) hashmap.get(BIRCH));
     
Thread Status:
Not open for further replies.

Share This Page