Skull Blocks

Discussion in 'Plugin Development' started by Rafiki2085, Mar 3, 2013.

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

    Rafiki2085

    Hi

    I'm trying to create a Skull Block in the world from a Plugin.

    I have the following code and it half works. It creates a Skull Block of the Skelly Type even though I'm trying to make it a Player Skull and set the name. I know all the calls even those inside the If are being called because of some print statements I added.

    Any Ideas?

    HL is a Location.

    Code:
            Block Head = HL.getBlock();
            Head.setType(Material.SKULL);
            Head.setData((byte) SkullType.PLAYER.ordinal());
            BlockState HeadState = Head.getState();
            if( HeadState instanceof Skull )
            {
                ((Skull)HeadState).setOwner(P.getName());
            }
     
  2. Offline

    chasechocolate

    You can just use SkullMeta, but in your code, you have to set the block's ItemMeta.
     
    tom1000o likes this.
  3. Offline

    tom1000o

    ItemMeta making things so much easier <3
     
  4. Offline

    Rafiki2085

    Any examples of how to do that? I have not messed with blocks like this before, other then to change the type.
     
  5. Offline

    Rafiki2085

    Can anyone help with this, I have not done Block Data like this before.
     
  6. Offline

    chasechocolate

    Rafiki2085
    Code:java
    1. ItemStack skull = new ItemStack(Material.SKULL_ITEM);
    2. SkullMeta meta = (SkullMeta) skull.getItemMeta();
    3. meta.setOwner("chasechocolate");
    4. skull.setItemMeta(meta);
     
  7. Offline

    Rafiki2085

    chasechocolate
    That is for an Itemstack, but how to I do that for a Block?

    Code:
            Block Head = HL.getBlock();
            Head.setType(Material.SKULL);
            Head.setData((byte) 0x1); // Floor
    But I don't know how to set the rest of the data to be a Player Head, and Whos head it should be and what the Rotation should be.
     
    Dzikoysk likes this.
  8. I've looked at the methods for Skull, you have setSkullType() and setRotation() there.
    Go back to your initial code, set data to position you want and after casting add .setSkullType() and setRotation().
     
  9. Offline

    Rafiki2085

    Digi Ok, So I get the Skull information, what do I do after that? I have tried that before(just setting it) and just filling it all out does nothing. Somehow I assume I need to set that Skull data back to the block but I don't know how.
     
  10. Get what information ? I said setSkullType() and setRotation(), that sets the skull type and rotation of the block.

    Code:
    block.setData((byte)0x1);
    BlockState state = block.getState();
    
    if(state instanceof Skull)
    {
        System.out.print("Setting skull stuff...");
        Skull skull = (Skull)state;
    
        skull.setRotation(BlockFace.SOUTH_SOUTH_EAST);
        skull.setSkullType(SkullType.PLAYER);
        skull.setOwner("Notch");
    }
    No.
     
  11. Offline

    Rafiki2085

    I finally figure out what was missing, for anyone else having problems with this...

    Code:
    block.setData((byte)0x1);
    BlockState state = block.getState();
     
    if(state instanceof Skull)
    {
        System.out.print("Setting skull stuff...");
        Skull skull = (Skull)state;
     
        skull.setRotation(BlockFace.SOUTH_SOUTH_EAST);
        skull.setSkullType(SkullType.PLAYER);
        skull.setOwner("Notch");
    }
    I don't remember (I'm at work) if its on the skull type or the itemstack (but I think the skull), but you have to also call

    Code:
    skull.update();
    to get it to apply those changes. Other things use that .update() function, so keep an eye out for it, it can safe you A LOT of pain as to wondering why something is not being updated when you set the values.
     
Thread Status:
Not open for further replies.

Share This Page