Search in sources :

Example 1 with GlowSkull

use of net.glowstone.block.entity.state.GlowSkull in project Glowstone by GlowstoneMC.

the class BlockSkull method getDrops.

@NotNull
@Override
public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
    GlowSkull skull = (GlowSkull) block.getState();
    Material skullMaterial = SKULL_MATERIALS.get(skull.getSkullType());
    ItemStack drop = new ItemStack(skullMaterial, 1);
    if (skull.hasOwner()) {
        SkullMeta meta = (SkullMeta) drop.getItemMeta();
        meta.setOwner(skull.getOwner());
        drop.setItemMeta(meta);
    }
    drop.setDurability((short) skull.getSkullType().ordinal());
    return Arrays.asList(drop);
}
Also used : GlowSkull(net.glowstone.block.entity.state.GlowSkull) Material(org.bukkit.Material) SkullMeta(org.bukkit.inventory.meta.SkullMeta) ItemStack(org.bukkit.inventory.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GlowSkull

use of net.glowstone.block.entity.state.GlowSkull in project Glowstone by GlowstoneMC.

the class BlockSkull method afterPlace.

@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
    GlowSkull skull = (GlowSkull) block.getState();
    skull.setSkullType(getType(holding.getDurability()));
    if (skull.getSkullType() == SkullType.PLAYER) {
        SkullMeta meta = (SkullMeta) holding.getItemMeta();
        if (meta != null) {
            skull.setOwner(meta.getOwner());
        }
    }
    MaterialData data = skull.getData();
    if (!(data instanceof Skull)) {
        warnMaterialData(Skull.class, data);
        return;
    }
    Skull skullData = (Skull) data;
    if (canRotate(skullData)) {
        // Can be rotated
        skull.setRotation(player.getFacing().getOppositeFace());
    }
    skull.update();
    // Wither
    for (int i = 0; i < 3; i++) {
        if (WITHER_PATTERN.matches(block.getLocation().clone(), true, i, 0)) {
            block.getWorld().spawnEntity(block.getLocation().clone().subtract(0, 2, 0), EntityType.WITHER);
            break;
        }
    }
}
Also used : GlowSkull(net.glowstone.block.entity.state.GlowSkull) GlowSkull(net.glowstone.block.entity.state.GlowSkull) Skull(org.bukkit.material.Skull) SkullMeta(org.bukkit.inventory.meta.SkullMeta) MaterialData(org.bukkit.material.MaterialData)

Aggregations

GlowSkull (net.glowstone.block.entity.state.GlowSkull)2 SkullMeta (org.bukkit.inventory.meta.SkullMeta)2 Material (org.bukkit.Material)1 ItemStack (org.bukkit.inventory.ItemStack)1 MaterialData (org.bukkit.material.MaterialData)1 Skull (org.bukkit.material.Skull)1 NotNull (org.jetbrains.annotations.NotNull)1