Player skull not placing correctly?

Sponge Build: 1.12.2-7.1.9
Java Version: 1.8

Hello, I am very new to sponge plugin development and am trying to place a player’s skull in their death location. My attempt is as follows:

    public void onPlayerDeath(DestructEntityEvent.Death event) {
        if (event.getTargetEntity() instanceof Player) {
            Player player = (Player) event.getTargetEntity();

            BlockState state = BlockState.builder()
                    .add(Keys.SKULL_TYPE, SkullTypes.PLAYER)
                    .add(Keys.REPRESENTED_PLAYER, player.getProfile())

The skull is being placed fine however it displays a skeleton texture rather than that of the player.

I would really appreciate any help.


Any help would really be appreciated.

Your code looks solid. When i get a sec ill test it myself but I can not think what is wrong with it. Maybe an issue on sponges side?

Found the issue:
So normally you can place all the keys on the blockstate all at once, the exception to this rule is if your trying to apply a key that can only be applied to the tile entity.
I thought that SKULL_TYPE was part of the state of skull as most “types” are, however with the skull, the type is attached to the tile entity. The type needs to be set to player before you can apply the reparented player (also attached to the tile entity) hence where we were going wrong.

Here is my code that works, while it is a command, you can easily adapt it for your code.

public void onEnable(GameStartingServerEvent event){
    Sponge.getCommandManager().register(this, CommandSpec.builder().executor((source, context) -> {
        Player player = context.<Player>getOne(Text.of("player")).get();
        BlockState state = BlockTypes.SKULL.getDefaultState();
        Skull skull = (Skull) player.getLocation().getTileEntity().get();
        skull.offer(Keys.SKULL_TYPE, SkullTypes.PLAYER);
        skull.offer(Keys.REPRESENTED_PLAYER, player.getProfile());
        System.out.println("State1: " + skull.supports(Keys.REPRESENTED_PLAYER) + " | " + skull.supports(Keys.SKULL_TYPE));
        return CommandResult.success();
    }).arguments(GenericArguments.playerOrSource(Text.of("player"))).build(), "Example");

btw, whoever made the implementation for “supports”, it helped a lot :wink: