1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Other How to make custom spawners using NBT

Discussion in 'Tutorials' started by jaylawl, Aug 19, 2018.

  1. jaylawl

    jaylawl Well-Known Member

    Joined:
    Jan 29, 2017
    Messages:
    173
    Likes Received:
    31
    You need
    Tile entities are blocks that store data. This ("NBT") data is used by the tile entities to execute their functions. Essentially, almost all blocks that have changable gimmicks to them are considered tile entities: chests, mob spawners, skulls, and so on...

    This tutorial assumes you have effect commands activated and know how to use them. If you never heard of that before: it's explained in your Skript-config.sk.

    1. How to customize a placed mob-spawner
    Find or place down a mob spawner. If you placed the mob spawner yourself you will notice that it automatically has a spinning pig inside, which is some hardcoded Mojang magic. We'll get to that in a bit.

    Look at the spawner and use
    Code (Skript):
    1. !send "%targeted block's nbt%"
    Which should result in seeing something like this:
    [​IMG]

    I think most of the NBT values that are contained within here are quite self-explanatory. If you're having trouble understanding what any these values mean, please visit this: https://minecraft.gamepedia.com/Chunk_format#Block_entity_format and check out the section for mob spawners. Explaning everything here is futile, as it would be version dependent (I'm using 1.12 as of writing this).

    We're just gonna focus on the fun part and learn how to change the mob that is being spawned by the spawner. For this, again, look at the mob spawner, and try this:
    Code (Skript):
    1. !add "{SpawnData:{id:""minecraft:llama""}}" to targeted block's nbt
    And the result should be:
    [​IMG]

    Wasn't that nice and easy?
    Depending on your MC version, i recommend changing both "SpawnData" and "SpawnPotentials" to the desired mob to be spawned.

    2. Allowing players to place custom mob spawners

    On to the more fun stuff.
    Mob spawners automatically make all spawners that are placed by players spawn pigs instead of what they originally spawned, as i explained earlier. There is no way to (as far as i know), to stop minecraft from doing that, but we can simply overwrite the data on the spawn event.

    First off, let's get a custom spawner:
    Code (Skript):
    1. command /test:
    2.     trigger:
    3.      
    4.         set {_spawner} to spawner with custom nbt "{SpawnData:{id:""minecraft:zombie""},SpawnPotentials:[{Entity:{id:""minecraft:zombie""},Weight:1}]}"
    5.         set {_spawner}'s name to "Zombie Spawner"
    6.         add 1 of {_spawner} to command sender's inventory
    Again, if you place this spawner, it will spawn pigs, so let's add a nice little script:
    Code (Skript):
    1. on place of spawner:
    2.     add "%event-player's tool's nbt%" to event-block's nbt
    Reload... get the spawner, place it, aaaaaaaaaaaaaand:

    [​IMG]

    Spawners are highly customizable. Have fun with this!
    -j

    Note: Yes, this also works with ender dragons and withers. Don't accidentally let them destroy your stuff.
     
    #1 jaylawl, Aug 19, 2018
    Last edited: Aug 19, 2018
  2. Donut

    Addon Developer

    Joined:
    Mar 27, 2017
    Messages:
    1,340
    Likes Received:
    175
    Medals:
    i would personally use skript mirror for this instead of relying on nbt
    Code (Skript):
    1. set {_spawner} to event-block.getState()
    2. {_spawner}.setSpawnedType(...)
    3. {_spawner}.setSpawnCount(...)
    4. everything else you want to set
    5. {_spawner}.update()
     
  3. jaylawl

    jaylawl Well-Known Member

    Joined:
    Jan 29, 2017
    Messages:
    173
    Likes Received:
    31
Loading...