WitherSkeleton [Spawner]

Discussion in 'Spigot Plugin Development' started by creepyloveYT, Mar 17, 2019 at 2:02 PM.

  1. Hello,
    i want to create a WitherSkeleton-Spawner, here is the code that i have currently:
    Code (Text):
        public void onPlayer(BlockPlaceEvent e) {
            Block b = e.getBlock();
            ItemStack item = e.getPlayer().getItemInHand();
            if(b.getType() == Material.MOB_SPAWNER && item.getType() == Material.MOB_SPAWNER) {
                ItemMeta im  = item.getItemMeta();
                if(im.getDisplayName().equalsIgnoreCase("WitherSkeleton-Spawner")) {
                    spawner(b, WitherSkeleton);

    public void spawner(Block block, EntityType entityType) {
            BlockState BS = block.getState();
            CreatureSpawner spawner = ((CreatureSpawner) BS);
    I know there is a method to spawn WitherSkeletons (SkeletonTypes) but the Spawner only accepts EntityTypes. Thanks in ahead

    PS: Sorry for my bad english

    PS Nr. 2: I'm coding on 1.8 so there is no WITHER_SKELETON
    #1 creepyloveYT, Mar 17, 2019 at 2:02 PM
    Last edited: Mar 17, 2019 at 2:07 PM
  3. I should've said that i'm coding with Spigot 1.8. Sorry
  4. you're going to need some NBT editing.

    • Cast CraftCreatureSpawner to your CreatureSpawner
    • Get TileEntityMobSpawner with getTileEntity
    • Grab the field 'a' in TileEntityMobSpawner which is an instance of MobSpawnerAbstract. To grab the field 'a' you'll to call getSpawner
    • Grab the field 'spawnData' in MobSpawnerAbstract which is an instance of MobSpawnerAbstract.a (a subclass in MobSpawnerAbstract) (You'll need reflection to grab the field)
    • Call the 'a' method which will return an NBTTagCompound
    • use setInt("SkeletonType", 1)
    • Update the block
    This is all assuming that the spawner's type is already a Skeleton
  5. Sorry but i don't really understand what you mean. I know did the following because i didn't really know what you mean.
    Code (Text):
    BlockState BS = b.getState();
                    CreatureSpawner sp = ((CreatureSpawner) BS);
                    BlockPosition blockPos = new BlockPosition(b.getLocation().getBlockX(), b.getLocation().getBlockY(), b.getLocation().getBlockZ());
                    CraftWorld world = (CraftWorld) b.getWorld();
                    TileEntityMobSpawner spawner = (TileEntityMobSpawner) ((CraftWorld) world).getHandle().getTileEntity(blockPos);
                    NBTTagCompound spawnerTag = spawner.getSpawner().a();
                    spawnerTag.setInt("SkeletonType", 1);
    Oh... and if i do .getSpawner().a() i get a world

Share This Page