Transform into a mob!
Alright, so here is your default path for the variants:
data\<your_namespace>\walkers\variants
In this folder, you can create a JSON-file. I recommend naming it like minecraft_wolf.json
if you’re registering Variants for the minecraft:wolf
.
Here’s an example for a Variant, which is based on another mob (e.g. you have a subclass of the sheep and want to apply sheep variants to it, too).
{
"entity_type": "modid:wolf",
"parent": "minecraft:wolf"
}
There are also ways to add it via classes, though it’s not recommended:
{
"entity_type": "modid:llama",
"type_provider_class": "tocraft.walkers.impl.variant.LlamaTypeProvider"
}
A list of possible TypeProvider-Classes for 1.20.2 can be found in the source code.
Now, let’s get to registering custom Variants.
General File Structure
{
"entity_type": "minecraft:sheep",
"required_mod": "some_modid",
"type_provider": {
"fallback": 0,
"range": 15,
"nbt": [
{
"nbt_type": "INTEGER",
"nbt_field": "Color",
"is_mutable": false,
"parameters": {
"0": "5"
}
}
],
"names": {
"0": "<some lang key for that variant, like 'White %s'.>"
}
}
}
entity_type
is the mob you want to register the Variants for.required_mod
is optional and only required if adding support for mods like MoreMobVariants.fallback
isn’t required and is only needed forINTEGER
values which should start with zero.range
this is essentially the range of possible variants. Note that 0 is a variant and therefore counted. (e.g. there are 16 colors for sheep, therefore the range is 15)nbt
the NBT Tags you want to modify (Yes, you can modify multiple at once, see below for more details).nbt_type
specifies, what type of NBT Tag you want to modify.- Possible entries are
BOOLEAN
,INTEGER
andSTRING
. BOOLEAN
doesn’t require any extra arguments.INTEGER
requires thatrange
is specified.STRING
requires thatparameters
is specified.
- Possible entries are
nbt_field
specifies the NBT Field, in this examplePumpkin
since/summon minecraft:snow_golem ~ ~ ~ {Pumpkin:true}
spawns a Snow Golem with a pumpkin and/summon minecraft:snow_golem ~ ~ ~ {Pumpkin:false}
spawns one without one, therefore thenbt_field
must be set toPumpkin
.is_mutable
this is only required for String Tags and is still a bit unstable.parameters
this is only required if the variant id shouldn’t match the Tag Value (for Integer Tags) or for Strings to specify, what Variant id equals what String value (see below).
names
take a look at Custom Names for Variants
Boolean NBT Tags
Since it’s getting more complicated from now on, we’ll take a look at a simple example:
{
"entity_type": "minecraft:snow_golem",
"type_provider": {
"nbt": [
{
"nbt_type": "BOOLEAN",
"nbt_field": "Pumpkin"
}
]
}
}
This essentially registers two Snow Golem Variants - one with and one without the Pumpkin. True is a variant id of 1
and False a variant id of 0
.
Integer NBT Tags
This is still simple since most things are automatically detected.
{
"entity_type": "minecraft:sheep",
"type_provider": {
"range": 16,
"nbt": [
{
"nbt_type": "INTEGER",
"nbt_field": "Color"
}
]
}
}
You need to specify range
so you have a range of possible Integer values for your NBT Tag.
String NBT Tags
Now it’s getting a bit more advanced.
{
"entity_type": "minecraft:sheep",
"type_provider": {
"range": 1,
"nbt": [
{
"nbt_type": "STRING",
"nbt_field": "CustomName",
"is_mutable": true,
"parameters": {
"1": "\"jeb_\""
}
}
]
}
}
Now, we’ll have a look at the keys again.
range
is required in this example, because we only specified one parameter. If norange
is specified, it will default to theparameters
list.is_mutable
this means, the specified String Tag is a mutable component. Normally, this is only required forCustomName
.parameters
is a list of possible String Entries per Variant id. In this example, a sheep with the variant id1
will have aCustomName
of\"jeb_\"
. If not specified, the String Tag will be empty for that variant id. So, in this example, a sheep with the variant id0
won’t have aCustomName
at all.
Variants with multiple NBT Tags
If you’ve understood the above code, you’ll find your way around this, too.
{
"entity_type": "minecraft:sheep",
"type_provider": {
"range": 16,
"nbt": [
{
"nbt_type": "string",
"nbt_field": "CustomName",
"is_mutable": true,
"parameters": {
"16": "\"jeb_\""
}
},
{
"nbt_type": "int",
"nbt_field": "Color",
"parameters": {
"16": "0"
}
}
]
}
}
You’ll notice that more than one nbt
is specified. In this example, a sheep with the variant id 0
will have an empty CustomName
(since no parameters
entry is specified) and a color of 0
. If the variant id equals 16
the sheep will have the CustomName
"\jeb_\"
because it’s specified in the respective parameters
list and a Color
of 16. You won’t notice the Color of 16
though, since there isn’t a color with that id.
Note that it’s important to specify parameters with multiple nbt tags. Every jeb_
-sheep has technically a white color, so you have to specify the parameters for this.
Advanced NBT Method
As of Walkers 4.4, there is a new option to register variants. So, previously, we created a file looking like this:
{
"entity_type": "minecraft:snow_golem",
"type_provider": {
"fallback": 1,
"nbt": [
{
"nbt_type": "BOOLEAN",
"nbt_field": "Pumpkin"
}
]
}
}
Now, we can simplify those scripts. Here’s an example (I’ve stripped it to 6 colors instead of 16):
{
"entity_type": "minecraft:sheep",
"type_provider": {
"nbt": {
"variants": {
"0": {
"Color": 0
},
"1": {
"Color": 1
},
"2": {
"Color": 2
},
"3": {
"Color": 3
},
"4": {
"Color": 4
},
"5": {
"Color": 5
}
}
}
}
}
You’ll notice the new variants
key and that the NBT is registered completely different. This allows datapack creators to register the NBT to the Variant, so it’s easier to understand how the mod works. Of course it’s also possible with multiple NBT Keys:
{
"entity_type": "minecraft:bee",
"type_provider": {
"nbt": {
"variants": {
"0": {
"HasStung": false,
"HasNectar": false
},
"1": {
"HasStung": true,
"HasNectar": false
},
"2": {
"HasStung": false,
"HasNectar": true
},
"3": {
"HasStung": true,
"HasNectar": true
}
}
}
}
}
Using a StringTag, the script would look like this:
{
"entity_type": "namespace:entity",
"type_provider": {
"nbt": {
"variants": {
"0": {
"someNBTKey": "someValue",
"otherNBTKey": false
},
"1": {
"2ndNbtKey": "hello world",
"otherNBTKey": true
}
}
}
}
}
Again, you’ll notice that the NBT Tags don’t have to be in every variant. Only the registered tag will be checked per variant.
Custom Names for Variants
If you like to specify a name for your Variant you can do so with the following:
{
"entity_type": "minecraft:snow_golem",
"type_provider": {
"nbt": [
{
"nbt_type": "BOOLEAN",
"nbt_field": "Pumpkin"
}
],
"names": {
"0": "walkers.variants.minecraft.snow_golem.0"
}
}
}
In this example, we’ll continue the example from the Boolean NBT Tags. You’ll notice the names
key. In it is a language key for the variant id 0
specified. Any variant id not specified will defer to the default entity name, in this example “Snow Golem”. You can name the language keys whatever you want, though I recommend the layout walkers.variants.<namespace>.<mob>.<id>
.
Once you specified them, you also need to add them to a language file. For example I added this entry to the en_us.json
:
{
"walkers.variants.minecraft.snow_golem.0": "Headless %s"
}
%s
means, this will be replaced by the default name. In this example, you’ll see an output of “Headless Snow Golem”.