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()); }
Any examples of how to do that? I have not messed with blocks like this before, other then to change the type.
Rafiki2085 Code:java ItemStack skull = new ItemStack(Material.SKULL_ITEM);SkullMeta meta = (SkullMeta) skull.getItemMeta();meta.setOwner("chasechocolate");skull.setItemMeta(meta);
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.
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().
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.
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.
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.