Tutorials/Creating behavior packs

This tutorial shows how to create a behavior pack.

Getting Started
Behavior packs can be used to add or modify functions, loot tables, villager trades, recipes, items, blocks, mobs, and mob behavior

Time required
This tutorial should take around 1 to 1.5 hours to complete.

Required tools
You will need the following programs to follow along with this tutorial:

A text editor
Any text editor should work, but it is suggested to use some sort of programming IDE. Notepad++ is an excellent, and free, text editor with syntax highlighting for lots of programming languages. You can download Notepad++ from here: https://notepad-plus-plus.org/. If you want manage multiple files effectively, it is suggested to use Visual Studio Code.

Creating a Behavior Pack
To begin, you can find the unmodified game files on Minecraft's official site.

To find the files, navigate to the bottom of the page, where you will find a paragraph where you can dowload a zip for the unmodified base files. You must then take the downloaded zip file and navigate to the com.mojang file and place the zip file in the development_behavior_packs file, and unzip it.

This step is not strictly necessary, and you can create a behavior pack without it, but it makes it much easier.

to start without the downloaded files, you can follow these steps.


 * Again, navigate to the development_behavior_packs folder and create a new folder.
 * (%userprofile%\AppData\Local\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang\development_behavior_packs)
 * Within that new folder create a JSON file called "manifest.json"

manifest.json
This manifest file already exists in the dowloaded files.

In this manifest file you will want the following:

The "uuid" is a universal unique identifier, which is necessary to change to your own uuid, even in the downloaded files.
 * manifest.json

the "version" tells the game what version of the pack is being used, if the number is higher, it will use that pack instead of the old one. this is important for testing your pack.

Testing your behavior pack
The behavior pack is now game ready. to test it, open minecraft, go to a world on which you want to test it. go to the world settings, navigate to the addons menu, and find it under my packs. it will now work on your worlds. this is where the "version" line in the manifest.json file becomes important. anytime you modify anything in the development pack, the world will continue to run the old version unless the pack version is higher.

Functions
Functions are lists of commands that can be run in order.

To add functions, you must make a folder named  inside the main folder. Then create a file with a  extension within this folder or a subfolder. Such as  in a subfolder called. in game these functions woud be run using the  command and be syntaxed as such.

Loot Tables
Loot tables are what tells the game what to drop when killing a mob, or what to put in a chest, or what armor mobs wear or even what you get from fishing.

to add loot tables first create a folder called  within your main folder. Minecraft pulls from 4 subfolders called  and.

is responsible for any loot found in chests throughout the world, and it will also pull form a subfolder within it named  which is responsible for village loot.

is responsible for the items dropped by any entities, as well as things such as the armor worn by entities, and things such as piglin bartering.

is responsible for the low tier equipment worn by mobs

And  is responsible for fishing and mooshroom milking, it contains two subfolders,   and.

Here is an example of a cow's loot table.

Recipes
Recipes allow players to craft items.

To add recipes, you must create a folder names  within the main folder. within that folder, the game uses  to create recipes.

There are many different kinds of recipes.

Shaped Crafting
in a crafting table, there are two types of crafting, shaped and shapeless, we will begin with shaped.

In a shaped recipe, you have a specified pattern and a key of items like so:

The below code is the recipe for a diamond axe. in the above code, there is a, this pattern specifies how a recipe is shaped. the pattern in this case is 2 wide and 3 tall, as the diamond axe is crafted as such. this pattern can be flipped, and put in any place on the grid, and any pattern that is 2x2 or less will work in the inventory crafting grid. the pattern for paper is shaped as such:

and so it can be placed anywhere on the grid horizontally. they can also be flipped. the pattern for a fishing rod is as such:

where # is a stick and X is string, but the fishing rod can also be flipped horizontally, but not vertically.

Shapeless Crafting
there is another type of crafting which is shapeless, the shapeless crafting has no pattern, but instead has a list and number of items for the craft.

The below code is the recipe for a netherite ingot. in this recipe there are ingredients and counts. these define what the ingredients are and how many of each item are needed. there is also a  line which defines what you can craft them in, there are only two   and   the stonecutter recipes can only have one input and one output and are made in the stonecutter.

Smelting
You can also create new furnace, smoker, blast furnace, campfire, and soul campfire recipes.

The below code is the furnace recipe for iron ingots from iron ore. In this you see three things, tags, input and output, the input and output define what goes in and what comes out, the tags define in what you can smelt the item, there are 5 tags:  and. so in the example of creating a new recipe that only works on campfires, you would only put the tags  and.

{  "format_version": "1.16.0", "minecraft:entity": { "description": { "identifier": "minecraft:pig", "is_spawnable": true, "is_summonable": true, "is_experimental": false },    "component_groups": { component groups go here }, "components": { components go here }, "events": { events go here } } }


 * Note

This is not valid JSON for Minecraft! This is just an example of how our entity json files are laid out to use as reference. If you take a look at pig.json you will notice that "component groups go here" is actually filled in with components.


 * Note 2 - format_version

Format version is used to tell Minecraft what version of the JSON it should be trying to read. As we update our JSON and add new components, we need to tell the game what things it should be looking for. We do this by changing the format_version number.

'''DO NOT CHANGE THIS NUMBER! '''As the Minecraft JSON updates, you will need to update your JSON files to match what was added. However, if you do update your JSON, you will need to change this number to whatever the new number is. Alternatively, you can copy the new version of the JSON from the updated Vanilla files and then copy over the specific behaviors you had changed in the old version.

Component groups
Used to define groups of behavior, allow for easy removal/addition of multiple behaviors, useful for making states (i.e. Pig baby vs pig adult behaviors).

In pig.json there are 6 groups including pig_baby, pig_adult. Note that the behaviors in those groups will only run if the group is currently added to the entity. Thus, when the pig is a baby pig, the pig_baby component group will be added and running, but the pig_adult group will not be.

Components
Used to define individual behaviors that will run on every entity of this type.

Note that things like "minecraft:identifier" and "minecraft:type_family" are here because we want every type of pig to have these components.

Events
Events are used to add or remove component groups and are triggered by components we've added, or by Minecraft's native code.

Events can use a randomize function to pick between different results (see "minecraft:entity_spawned" in pig.json). Note that the weights for randomize can add to over 100. This is because they are not percentages! If you set the weight for making an adult pig to 23 and then the weight for making a pig baby to 100 then you will have a 23/123 chance of getting an adult pig and a 100/123 chance to get a baby pig when a pig is spawned.

minecraft:identifier
This is required for every entity. This is how the game knows what entity this .json file will run behaviors for. '''The identifiers must be named appropriately! If you give an incorrect identifier you will either get unintended results or your entity may not work at all. If you aren't sure what the identifier should be for an entity, please refer to the json file for that entity in the Vanilla Behavior Pack (remember json files are in /Vanilla_Behavior_Pack/entities/)'''

minecraft:type_family
This sets the family type for the entity. Family types are used for filtering entities for various components. See "minecraft:rideable" and "minecraft:breedable" for examples where type is used!

minecraft:entity_spawned
This is an event that is triggered when an entity of this type is spawned. In pig.json this has a randomize function that determines whether the pig is going to spawn as a baby or an adult pig.

Adding components
Now that we've looked at how an entity is setup; it is time to actually modify the pig's code!

Find the creeper.json file in the Vanilla Behavior Pack's entity folder (Vanilla_Behavior_Pack/entities/) and open it in a new text editor window. You should now have the pig.json from our custom add-on and creeper.json from Vanilla open in two separate windows.

The first thing we want to do is to have the pig find a target. We can do this by adding the "minecraft:nearest_attackable_target" and "minecraft:target_nearby_sensor" components into the components object for pig.json.

Find "minecraft:behavior.random_look_around" in the components object, it should be the last component before the "events" section.

Add a comma after the closing bracket of random_look_around. This is where we are going to add the targeting component. Either type or copy and paste the target_nearby_sensor and nearest_attackable_target components from creeper.json into pig.json. The end of Pig.json's "components" section should now look something like this (new text is highlighted in green):

pig.json excerpt:

...

"minecraft:behavior.random_look_around": { "priority": 9 }, "minecraft:behavior.nearest_attackable_target": { "priority": 1, "entity_types": [ {      "filters": { "other_with_families": "player" }, "max_dist": 16 }  ],    "must_see": true }, "minecraft:target_nearby_sensor": { "inside_range": 3.0, "outside_range": 7.0, "on_inside_range": { "event": "minecraft:start_exploding", "target": "self" },  "on_outside_range": { "event": "minecraft:stop_exploding", "target": "self" } }

...

Notice that the ending brace for target_nearby_sensor does not have a comma after it because it is the last value in the value list for "components".

minecraft:nearest_attackable_target
This component finds the nearest attack target given certain restrictions.


 * Priority – This sets how important this component is. Components with a higher priority will be more likely to be run. Note that a lower number means a higher priority and that priorities can be negative!
 * Entity_types – This is where we filter for what types of entities this entity can set as its target.
 * Max_dist – if the entity we want to be able to targets is within this many blocks from this entity than we can target it
 * Must_see – whether the entity that we want to target must be seen to be able to be set as our target

Notice that in our code, we are filtering for type player and that we will be able to set it as our target once they get within 16 blocks of this entity.

minecraft:target_nearby_sensor
This component will trigger events based on how close the entity's target is.


 * Inside_range – the distance in blocks that a target is considered to be inside this entity's range
 * Outside_range – the distance in blocks that a target is considered to be outside this entity's range
 * On_inside_range – this will trigger the event specified when a target is closer than inside_range
 * On_outside_range – this will trigger the event specified when a target is farther than outside_range

Notice that on_inside_range and on_outside_range are going to be triggering the events "minecraft:start_exploding" and "minecraft:stop_exploding" respectively. This won't currently do anything because we have not added these events yet!

Adding events
Scroll down to the bottom of the "events" object in pig.json and add a comma after the closing curly brace of "minecraft:on_unleash". This is where we are going to add our new start and stop exploding events.

Either type or copy and paste the "minecraft:start_exploding" and "minecraft:stop_exploding" events from creeper.json into pig.json. The end of Pig.jsons events section should now look something like this (new text is highlighted in green):

pig.json excerpt:

...

"minecraft:on_unleash": { "remove": { "component_groups": [ "minecraft:pig_leashed" ]  } }, "minecraft:start_exploding": { "remove": { "component_groups":[ "minecraft:hunting" ]  },   "add": { "component_groups": [ "minecraft:exploding" ]  } }, "minecraft:stop_exploding": { "remove": { "component_groups": [ "minecraft:exploding" ]  },   "add": { "component_groups": [ "minecraft:hunting" ]  } }

...

Now that we have brought over the creeper events, we need to do some cleanup. Our pig doesn't need a hunting component group so we can remove the "remove" section from start_exploding and the "add" section from stop_exploding. Our code should now look like:

pig.json excerpt:

...

"minecraft:on_unleash": { "remove": { "component_groups": [ "minecraft:pig_leashed" ]  } }, "minecraft:start_exploding": { "add": { "component_groups": [ "minecraft:exploding" ]  } }, "minecraft:stop_exploding": { "remove": { "component_groups": [ "minecraft:exploding" ]  } }

...

Notice that both events are adding and removing a component group called "minecraft:exploding". Our pig does not have this component group yet!

Adding component groups
Scroll back up to the top of pig.json to the "component_groups" section. Find the last component group, which should be pig_leashed, and add a comma to its closing curly brace. Now either type the following, or copy the "minecraft:exploding" component group from creeper.json. Pig.json should now look like the following (new code in green):

pig.json excerpt

...

"minecraft:pig_leashed": { "minecraft:behavior.move_towards_restriction": { "priority": 2, "speed_multiplier": 1.0 }  },   "minecraft:exploding": { "minecraft:explode": { "fuseLength": 1.5, "fuseLit": true, "power": 3, "causesFire": false }  }  }, "components": { "minecraft:damage_sensor": {

...

minecraft:explode
fuseLength – how long it takes, in seconds, until this entity explodes from when the fuse is lit

fuseLit – whether the fuse is automatically lit when this component is added

power – this determines the damage done, and how big the explosion radius is

causesFire – this determines whether the explosion will cause nearby blocks to catch on fire or not

Let's add a scale component to this group as well, so that our pig grows in size before it explodes! Add a comma to the closing curly brace of the "explode" component and put in the following (new text in green):

pig.json excerpt

...  "minecraft:exploding": { "minecraft:explode": { "fuseLength": 30, "fuseLit": true, "power": 1, "causesFire": false },    "minecraft:scale": { "value": 2 }   } }, "components": { "minecraft:damage_sensor": {

...

minecraft:scale
Value – a multiplier to the normal scale of the entity. A value of 2 will double the scale, a value of .5 will halve the scale, etc.

Testing our add-on

 * Launch the game
 * Create a new world
 * Set world to creative
 * Turn on cheats
 * Click on add-ons
 * Find "Tutorial Behavior Pack" in the list on the right and click it
 * Click play
 * Spawn a pig using the pig spawn egg from the creative inventory
 * Run 20 blocks or so away
 * Switch mode to survival by using the slash command: /gamemode s
 * Run toward the pig

Congratulations!
You've only just scratched the surface of what is possible with Add-ons! If you want to be able to do more than just make things explode, check out the Entity Component Reference Guide to see other behaviors and components you can add to entities! You can also always look at how the Vanilla Behavior pack is set up for examples.

Note on available behavior changes
Not all behaviors of a mob are data driven yet! You cannot change the details for special movement behaviors like flying (bat, ghast, blaze) or swimming (squid, guardian, guardian elder). This can also interfere with behaviors you might add to them. For example, giving the squid a melee attack does not work while it is in water as its swimming behavior is still hard coded. Additionally it is not possible to just change some mobs behavior such as for example the witch utilizing potions is not data driven yet and you will be unable to control it.

Look forward to these changes in the future!

Challenges
Now that you've gotten some basic experience, here are some challenges:


 * Make zombies rideable by the player
 * Have the player able to control direction with an item (hint: look at pig's item_controllable and controlled_by_player)
 * Make villagers transform into skeletons when given a bow (hint: look at wolf's tameable and villagers transformation)
 * Change the texture of the sun and moon
 * Make a cow shoot the ghast's projectile

Troubleshooting JSON
If your JSON changes don't appear to be working in game, check the following things:


 * Make sure that you've typed everything correctly. Typos and missing punctuation will cause unwanted behavior!
 * Make sure the .json file is in the correct folder and named correctly!
 * You should have a folder called entities that contains all your .json files
 * Make sure your entity has the correct identifier
 * Check the .json file in the Vanilla Minecraft pack if you aren't sure what it is supposed to be
 * Vanilla's .json files can be found in /Vanilla_Behavior_Pack/entities or downloading it through this link

Exporting and sharing
Now that you've created a behavior pack, you probably want to share it with friends! To do this, perform the following:


 * Navigate into your development_behavior_packs folder
 * (%userprofile%\AppData\Local\Packages\Microsoft.MinecraftUWP_8wekyb3d8bbwe\LocalState\games\com.mojang\development_behavior_packs\tutorial_behavior_pack)
 * Select all of the files and folders
 * Right click on the highlighted files and select send to -&gt; compressed zip folder
 * Name the file tutorial_behavior_pack.mcpack
 * Make sure to change the file extension to .mcpack
 * when the popup asks you if you are sure you want to change the file extension. Hit Yes

You can now give your friends that .mcpack file! When they open it, Minecraft will launch if it isn't running yet, and then it will import your resource pack for them to use!


 * Note

You can test to see if the exported behavior pack works by deleting your copy in your development_behavior_packs folder (make a backup first!), then opening your mcpack to import it. If it doesn't work, make sure you selected the contents of your behavior pack and not the folder itself when making the .mcpack zip.


 * Note 2

If your behavior pack references a resource pack, the mcpack won't automatically include that resource pack as well, even if you have given the behavior pack_manifest a dependency on that pack. If you have a resource pack dependency either: make a .mcpack for the resource pack as well, or make a world and add the behavior and resource packs you want to export and then export that world. When that world is imported, the save folder for that world will have a folder for the behavior packs and resource packs of that world. You can copy those packs to your local folders to be able to see them in the behavior and resource pack menus and add them to other worlds.

Shortcuts

On Bedrock Edition, there are a few third-party apps you can download to make Add-Ons without the hassle of JSON. Google Play users have access to "Add-Ons Maker" by PA Technologies. The interface is easy to use, and there is no JSON code-writing whatsoever. Exports are as easy as selecting a previously-made world and sending it. Your Minecraft app automatically holds a copy for future uses too.

チュートリアル/Bedrock Edition/ビヘイビアーパックの作成 教程/制作行为包