How to destroy a block and drop it?

Discussion in 'Plugin Development' started by VitaB, Mar 11, 2011.

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

    VitaB

    Hi,

    I'm trying to create a weapon which destroys block instantly.

    There's just one problem:
    At first I just set the Block.Material to AIR (TypeId: 0). But by doing so you won't get any blocks added to your inventory. To solve that, I wrote some code which added the destroyed blocks to the players inventory.

    Now I want to drop the destroyed block instead, so that any player can pick it up.

    I found the following answer by Steven Richards:
    http://leaky.bukkit.org/issues/213

    But I can't get it to work.

    I imported net.minecraft.server from the craftbukkit_0.0.1.jar. But net.minecraft.server.Block has no function g(...) which takes the parameters in Steven Richard's solution. So I tried functions a(...), b(...), c(...), d(...). But none of them drops the destroyed block.

    My testing code:
    Code:
    public void onBlockDamage(BlockDamageEvent event)
    {
    	Block b = event.getBlock();
    	int d = b.getData();
    	net.minecraft.server.Block.byId[b.getTypeId()].d(((org.bukkit.craftbukkit.CraftWorld)b.getWorld()).getHandle(), b.getX(), b.getY(), b.getZ(), d);
    	b.setTypeId(0);
    }
    
    Any help is appreciated


    VitaB
     
  2. Offline

    Joshua Neicho

    i wouldn't know if this is possible but couldn't you instead of making the block air just make it take a lot of damage so the block gets destroyed
     
  3. Offline

    VitaB

    That would be a good solution too, but I didn't find a way to increase the damage dealt to the block or a method which is responsible for damaging/destroying a block
     
  4. Offline

    Joshua Neicho

    couldn't you use

    BlockDamageLevel getDamageLevel ()
    Returns the level of damage to the block.
     
  5. Offline

    VitaB

    I can't find a method to set the damage level. With getDamageLevel() I can just read it, but I can't modify it
     
  6. Offline

    Joshua Neicho

    sorry i have no clue
     
  7. Offline

    eltorqiro

    If you check out org.bukkit.craftbukkit.CraftWorld there are 2 methods that may help you: dropItem() and dropItemNaturally()

    From the description, these can be used to simulate what happens when you "destroy" a block. I am not sure how you can extract the natural loot that would normally come from the block you have changed to AIR, but you could always make your own loot table with each block type in it.
     
  8. Offline

    Edward Hand

    Thanks to Steven Richards I was able to find a solution.
    His solution no longer works because the obfuscation changes in every new version of minecraft, however knowing that such a solution existed allowed me to find it with ease.

    The function:
    Code:
    Block.byId[id].d(etc etc)
    is now called:
    Code:
    Block.byId[id].a_(etc etc)
    Otherwise your code looks fine.
     
  9. Offline

    VitaB

    @Joshua Neicho
    Thanks for trying ;)

    @eltorqiro
    Thanks for your help, without the help of Edward Hand this would have been the way to go ;)

    @Edward Hand
    Thank you, this solution works perfectly
     
Thread Status:
Not open for further replies.

Share This Page