-
Notifications
You must be signed in to change notification settings - Fork 0
Adding Conditions Via Datapack (release 1.1.5 for minecraft 1.16 )
As of release 1.1.5 there is a new conditions system in place.
The conditions file located at data/followme/conditions/conditions.json will be loaded by the mod and can be used to allow more control over whether entities will be able to follow you or not. Conditions are written in strict JSON formatting and it's recommended to know how that formatting works or have experience with it. If you're unsure please try looking at a json formatting tutorial before you try using this, or use a json format checker on your code.
It's also recommended to use an NBT editor or refer to the minecraft wiki to understand the NBT format; and which values you will need to search for.
The following is an example of a conditions datapack:
Example
{
"minecraft:iron_golem": {
"conditions": {
"player_created": {
"mode": "entity_nbt",
"target": "PlayerCreated",
"type": "boolean",
"operation": "==",
"value": true
},
"not_adventure": {
"mode": "user_nbt",
"target": "playerGameType",
"type": "int",
"operation": "!=",
"value": 2
}
}
},
"minecraft:villager": {
"conditions": {
"not_adventure": {
"mode": "user_nbt",
"target": "playerGameType",
"type": "int",
"operation": "!=",
"value": 2
},
"day_time": {
"mode": "world_nbt",
"target": "DayTime",
"type": "long",
"operation": "%",
"value": {
"comparison": 24000,
"operation": "<",
"value": 12000
}
},
"no_profession_or_child": {
"mode": "or",
"conditions": [{
"mode": "entity_nbt",
"target": "VillagerData.profession",
"type": "string",
"operation": "==",
"value": "minecraft:none"
}, {
"mode": "entity_nbt",
"target": "Age",
"type": "int",
"operation": "<",
"value": 0
}]
}
}
}
}
The example provided looks quite complicated, but it's intended to show as many features of conditions as possible.
First of all to break down the beginning of the file; this conditions file has two entries, one for iron golems and the other for villagers, a conditions file can contain any number of objects representing entities, using the entity registry name as the name for the object.
An entity entry will contain one object, the conditions object, which will contain all conditions that apply to that entity;
For the first example the conditions object contains two conditions, both must be true for the entity to start following the player.
Both conditions are fairly simple. For the first, if the nbt value "PlayerCreated" for the iron golem, which refers to if a golem was built by a player or naturally spawned, is true.
Breaking this down further, the condition has a name, which needs to be unique for that entity and is used internally, after that comes the parameters.
The parameters are as following:
"mode", which in this case refers to the nbt of the iron golem.
"target", which in this case refers to the "PlayerCreated" value in nbt. The full formatting can be found in it's references section.
"type", refers to the data type of the nbt value, in this case boolean.
"operation", refers to the comparative operation you want to apply to the values, in this case equals.
"value", refers to the value you want to compare to the value found in nbt.
This pattern will follow with most conditions you would want to add, full decriptions and types for each paramenter will be detailed in the references page, and follows for the next condition, and for the first condition for villagers.
In the villagers object, there are two new types of condition, the first is a modulo condition.
This condition is only true if it is day.
A modulo condition is referred to with the '%' operation and gets the remainder of a divisend divided by a divisor.
Example
{
"minecraft:villager": {
"conditions": {
"day_time": {
"mode": "world_nbt",
"target": "DayTime",
"type": "long",
"operation": "%",
"value": {
"comparison": 24000,
"operation": "<",
"value": 12000
}
}
}
}
}
It's value, is an object which contains three parameters:
"comparison", refers to the divisor of a mod operation, where the nbt value is the divisend.
"operation", refers to the comparative operation you want to apply to the result of the mod operation.
"value", refers to the value you want to compare to the result of the mod operation.
The final condition is a logical condition, this is referred to by setting the mode to one of the 5 logical operators, as detailed in the references section. In this case it uses the or operator.
A logical condition doesn't have the usual parameters for a condition, except the mode parameter, and instead uses a conditions parameter, which is a json list of other conditions objects, which may also be a logical condition.
Example
{
"minecraft:villager": {
"conditions": {
"no_profession_or_child": {
"mode": "or",
"conditions": [{
"mode": "entity_nbt",
"target": "VillagerData.profession",
"type": "string",
"operation": "==",
"value": "minecraft:none"
}, {
"mode": "entity_nbt",
"target": "Age",
"type": "int",
"operation": "<",
"value": 0
}]
}
}
}
}
In the above example the or condition returns true, if the villager doesn't have a job, or is a baby.
"mode" refers to the type of condition you wish to use.
Valid types are "entity_nbt", "user_nbt" , "world_nbt" , "compare_nbt" , "and" , "or" , "nand", "nor" and "xor".
Prior to 1.1.6 use "player_nbt" instead of "user_nbt".
Gets a value from the entity nbt structure corresponding to "target" and compares it to "value" using "Operation".
Gets a value from the player/interacting entity nbt structure corresponding to"target" and compares it to "value" using "Operation".
Gets a value from the world nbt structure corresponding to "target" and compares it to "value" using "Operation".
This is limited to values found inside the level.dat and does not include chunk data.
Gets a value from the entity nbt structure corresponding to "target" and compares it to a value from the player nbt structure defined in "value" in the same format, using "Operation".
Logical conditions exist for five operations "and", "or", "nand", "nor" and "xor" and are specified in "mode", along with a "Conditions", which is a list of other conditions objects.
Example
{
"minecraft:villager": {
"conditions": {
"no_profession_or_child": {
"mode": "or",
"conditions": [{
"mode": "entity_nbt",
"target": "VillagerData.profession",
"type": "string",
"operation": "==",
"value": "minecraft:none"
}, {
"mode": "entity_nbt",
"target": "Age",
"type": "int",
"operation": "<",
"value": 0
}]
}
}
}
}
Logical conditions may contain other logical conditions.
Due to how the xor operator works with more than one operator, it returns true if an odd number of values are true.
Using an example from the greek fantasy mod, as of version 16.5.3 the favor value for the god zeus can be obtained by "ForgeCaps.greekfantasy:favor.FavorLevels.greekfantasy:zeus.Favor.Favor". This is an extreme example of how the target parameter is defined.
Each nbt compound in the compound structure is separated by ..
The structure of this in player nbt is:
Example
{
ForgeCaps: {
greekfantasy:favor: {
FavorLevels: [{
Name: "greekfantasy:zeus",
Favor: {
Favor: 0
}
}]
}
}
}
As shown in the example, the tag will either search for a compound with the specified name or a compound in an nbt list where the value of the Name field matches.
"type" refers to the data type of the nbt value that "target" searches for.
Valid types are "byte", "short" , "int" , "long" , "float" , "double" , "string", "boolean".
Valid operations are "==", "!=", "<", ">", "<=", ">=" and "%".
Each operation applies the nbt value from "target" to "value".
As opposed to normal operations the value for a modulo operation is an object containing details of the modulo operation; instead of a value or nbt path.
It represents the remainder of an operation of a divisend divided by a divisor.
Example
{
"minecraft:villager": {
"conditions": {
"day_time": {
"mode": "world_nbt",
"target": "DayTime",
"type": "long",
"operation": "%",
"value": {
"comparison": 24000,
"operation": "<",
"value": 12000
}
}
}
}
}
Modulo value objects must have the three parameters:
"comparison", refers to the divisor of a mod operation, where the nbt value is the divisend.
"operation", refers to the comparative operation you want to apply to the result of the mod operation, this cannot refer to another modulo operation.
"value", refers to the value you want to compare to the result of the mod operation.