Placing custom skin skulls as blocks

Discussion in 'Plugin Development' started by cameron5906, Nov 3, 2012.

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


    Hello, quick question for a plugin i'm currently working on, wanted to see if anyone has any ideas on solving it :)

    Okay so, my idea is that when a player dies, it creates a skull with their player's head skin and then places it (as a SKULL type block) on the ground where they died.

    Basically, right now I can create the skull ENTITY/ItemStack with the custom player skin, but at the moment I can only drop the skull item itself to the ground, not place it as a block. I know it's possible, because I can pick this item up and place it on the ground manually as a block and see that it is indeed my player skin. However, I want to be able to do this programmatically.

    I've come across a function under the CraftItemStack class called placeItem(EntityHuman, World, int i, int j, int k, int l, float f, float f1, float f2), maybe this could have something to do with it?

    Any help is greatly appreciated, and i'm sure other people will be wondering how to do this in the future!
  2. Offline


    set the location where the player died as the skull
  3. If you want to place an ItemStack as a block, simply:
    Location loc = player.getLocation();
    Block b = player.getWorld().getBlockAt(loc);
  4. Offline


    Vandrake - The question was HOW not WHAT to do. He knows WHAT he wants to do, just not HOW.
    Muizers - There is no Block.setType(ItemStack) method.

    To solve this you do need to access CB methods, as there is currently no Skull BlockState.

    public void placeSkullBlock(Block skullBlock, String playerName) {
        // Set the block to a generic skull. This will create the tile entity ready for editing
        skullBlock.setTypeIdAndData(Material.SKULL.getId(), (byte) 1, true);
        // Grab the tile entity for the skull through CB
        TileEntitySkull tileentityskull = (TileEntitySkull) ((CraftWorld) skullBlock.getWorld()).getHandle().getTileEntity(skullBlock.getX(), skullBlock.getY(), skullBlock.getZ());
        // Set the skull type to 3 (Human) and give the owner's name to give it that player's skin
        tileentityskull.setSkullType(3, playerName);
        // Save changes to the tile entity
  5. I'm very sorry I don't have time to read your full post, I am sorry I meant Block.setType(Material) of course :)
  6. Offline


    cameron5906 assuming you have Location loc, the location of the skull
    1. Block b = loc.getBlock();
    2. if(b.getType() == Material.SKULL)
    3. {
    4. Skull skull = (Skull)b.getState();
    5. skull.setSkullType(SkullType.PLAYER);
    6. skull.setOwner("SomeName");
    7. skull.update(true);
    8. }
  7. Offline


    Using CB version 1.4.6 and onwards you should use this approach and not mine. Mine is strictly for 1.4 up to 1.4.5 before the Skull blockstate was introduced. You should never use CB methods unless you have to as every CB update will break your plugin if you do!
Thread Status:
Not open for further replies.

Share This Page