Solved Simulate Bonemeal usage

Discussion in 'Plugin Development' started by Lordloss, Jun 16, 2016.

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

    Lordloss

    Hello guys,

    i tried to fake the use of bonemeal to create a bonemeal-wand for easy terraforming. I know there are some ways to make this with worldedit, i.e. //flora. But i prefer the natural, random-looking effect of real bonemeal. Especially because of the biome-dependent flowers that get mixed in.

    I tried the examples in this thread which uses NMS, but i cant get it to work.

    That was my attempt:
    Code:
                                int x = player.getLocation().getBlockX(), y = player.getLocation().getBlockY(), z = player.getLocation().getBlockZ();
                                World w = player.getLocation().getWorld();
                        
                                ItemStack i = new ItemStack(Material.INK_SACK, (short)15);
                                CraftItemStack bonemealStack = CraftItemStack.asCraftCopy(i);
    
                                Item.a(bonemealStack, ((CraftPlayer)player).getHandle(), ((CraftWorld)w).getHandle(), x, y, z, 0);
    
    No method with this signature exists. And there is no "interactWith()" method mentioned in the thread above.
    Also the CraftItemStack doesnt have a getHandle(), i think i get something mixed up here, im not really good at NMS stuff.

    Any help is appreciated.
     
  2. Offline

    I Al Istannen

    @Lordloss
    You can use CraftItemStack.asNMSCopy(BukkitItemStack) to get a NMS itemstack. But I will look into it, maybe I find a solution. Just wanted to say this, as you said getHandle doesn't exist.

    EDIT:
    Okay, I found one solution. The best part is, that it is the only public method returning a boolean, which means you can hopefully make it at least a bit version proof using reflection. But here is the code. Explaining is a lot worse than just posting the three lines:
    Code:
    ItemStack nmsStack = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.INK_SACK, 1, (short) 15));
    ItemDye.a(nmsStack, ((CraftWorld) player.getWorld()).getHandle(),
                    new BlockPosition(player.getLocation().getBlockX(), player.getLocation().getBlockY() - 1,
                            player.getLocation().getBlockZ()));
    I used the player location as you can see and it correctly let plants and grass grow. Saplings didn't seem to work, but that is thankfully unimportant :p
     
    Last edited: Jun 16, 2016
    Lordloss likes this.
  3. Offline

    Lordloss

    @I Al Istannen Well, what a nice solution! Thank you very much for your time. [diamond]
     
  4. Offline

    I Al Istannen

    @Lordloss
    No problem! Glad I could help!

    Have a nice day and good luck with your project :)
     
Thread Status:
Not open for further replies.

Share This Page