Spawning a certain skull

Discussion in 'Plugin Development' started by handyhacker, Dec 23, 2014.

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

    handyhacker

    Hello there,

    i'm writing a plugin, which should spawn a wither skull as a block. But that isn't working.

    What i did:
    Code:
    Location randomLoc = getRandomLocation(plugin.aloc1, plugin.aloc2);
            plugin.getServer().getWorld(fc.getString(WGPaths.ARENA_WORLD)).strikeLightning(randomLoc);
            plugin.getServer().getWorld(fc.getString(WGPaths.ARENA_WORLD)).getBlockAt(randomLoc).setType(new ItemStack(Material.SKULL, 1, (short) 1).getType());
    
    It's only spawning a regular skeleton head, so id like to know, how to implement the durability (in this case which skull type it is, for instance 1 is wither) into the material. Because setType only takes Material as argument.
     
  2. Offline

    timtower Administrator Administrator Moderator

    Moved to plugin development.
     
  3. Offline

    Windy Day

    Code:
    block.setType(Material.SKULL);
    ((Skull) block.getState()).setSkullType(SkullType.WITHER);
    or
    Code:
    block.setType(Material.SKULL);
    block.setData((byte)1);
     
  4. Offline

    pookeythekid

    @handyhacker ^ that or try using this:
    Code:
    BlockState bstate = plugin.getServer().getWorld(fc.getString(WGPaths.ARENA_WORLD)).getBlockAt(randomLoc).getState();
    bstate.setType(Material.SKULL);
    ((Skull) bstate).setSkullType(SkullType.WITHER);
    bstate.update();
    Pretty much what Windy Day said, but using BlockStates and the blockstate.update() method.
     
  5. Offline

    handyhacker

    setSkullType() doesn't exist in my bukkit version, but i guess i didn't think about setting the data of the block after spawning it. I wanted to do it both at the same time. Wouldn't have worked, but well, what can i say, i was already tired of coding yesterday.

    I'll try to get the newest 1.7.5 bukkit version
    Edit: Has setSkullType()

    @pookeythekid
    Your code isn't working :(
    It gives me an exception:
    Code:
    
    java.lang.ClassCastException: org.bukkit.craftbukkit.v1_7_R2.block.CraftBlockSta
    te cannot be cast to org.bukkit.block.Skull
            at handyhacker.WitherGames.Commands.WitherGamesCommand.spawnHead(WitherG
    amesCommand.java:448) ~[?:?]
            at handyhacker.WitherGames.Commands.WitherGamesCommand$3.run(WitherGames
    Command.java:395) ~[?:?]
            at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftTask.run(CraftTask.java
    :53) ~[craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at org.bukkit.craftbukkit.v1_7_R2.scheduler.CraftScheduler.mainThreadHea
    rtbeat(CraftScheduler.java:345) [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.
    3-14-g8f8716c-b3042jnks]
            at net.minecraft.server.v1_7_R2.MinecraftServer.v(MinecraftServer.java:5
    90) [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at net.minecraft.server.v1_7_R2.DedicatedServer.v(DedicatedServer.java:2
    50) [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at net.minecraft.server.v1_7_R2.MinecraftServer.u(MinecraftServer.java:5
    48) [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at net.minecraft.server.v1_7_R2.MinecraftServer.run(MinecraftServer.java
    :459) [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
            at net.minecraft.server.v1_7_R2.ThreadServerApplication.run(SourceFile:6
    18) [craftbukkit-1.7.5-R0.1.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
    
    Yes, i did exactly what your code did. And imported org.bukkit.block.BlockState, but in the exception it says CraftBlockState. Seems strange to me :/

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
  6. Offline

    nverdier

    You can't cast a BlockState to Skull... Learn to read stack traces :p
     
  7. Offline

    handyhacker

    Yeah, wow. u don't say.
    What i mean is, why did it try to cast CraftBlockState to Skull, when i said:
    Code:
    BlockState bstate = plugin.getServer().getWorld(fc.getString(WGPaths.ARENA_WORLD)).getBlockAt(randomLoc).getState();
    bstate.setType(Material.SKULL);
    ((Skull) bstate).setSkullType(SkullType.WITHER);
    
    Why did the exception say CraftBlockState, and not BlockState? Because Skull extends BlockState
     
Thread Status:
Not open for further replies.

Share This Page