Modding:Entity Behaviors

From Vintage Story Wiki
Revision as of 03:47, 6 October 2024 by Bluelightning32 (talk | contribs) (→‎All Behaviors: copy the remaining behaviors from the entity properties)

Using Entity Behaviors

Inside the entity json file, entity behaviors can be added to the client section, server section, or both. For example, here is the controlledphysics behavior from deer.json, added to both the client and server sections. This shows the pre-1.20 style of including the behavior on both sides. Note that the properties are added directly to the behavior object, instead of in a properties object like with blocks and items. Also note that the builtin entity behavior names are all lower case, unlike block and collectible behaviors.

	client: {
        ...
		behaviors: [
            ...
			{
                code: "controlledphysics",
                "stepHeightByType": {
		    		"deer-pampas-*": 2.1251,
	    			"deer-pudu-*": 2.1251,
    				"deer-redbrocket-*": 2.1251,
				    "*": 3.1251
			    } 
            },
            ...
		],
        ...
	},
	server: {
        ...
		behaviors: [
            ...
			{
                code: "controlledphysics",
                "stepHeightByType": {
		    		"deer-pampas-*": 2.1251,
	    			"deer-pudu-*": 2.1251,
    				"deer-redbrocket-*": 2.1251,
				    "*": 3.1251
			    } 
            },
            ...
		],
        ...
	},

In 1.20, the behaviorConfigs section was added. For behaviors that added to both sections, the properties may be specified in the behaviorConfigs section to avoid duplicating the properties in both the client and server section. Here is the above example using behaviorConfigs.

	behaviorConfigs: {
		"controlledphysics": { 
			"stepHeightByType": {
				"deer-pampas-*": 2.1251,
				"deer-pudu-*": 2.1251,
				"deer-redbrocket-*": 2.1251,
				"*": 3.1251
			}
		},
        ...
	},
	client: {
        ...
		behaviors: [
            ...
			{ code: "controlledphysics" },
            ...
		],
        ...
	},
	server: {
        ...
		behaviors: [
            ...
			{ code: "controlledphysics" },
            ...
		],
        ...
	},

All Behaviors

Here is a table containing all the entity behaviors of the base game. Of course mods can, and are encouraged to add new behaviors.

Behavior Name Explanation Example entities Properties Side
aimingaccuracy Adds aiming inaccuracy when sprinting, jumping, etc.
  • player
  • playerbot
Server
breathe The entity will need to breathe and therefore suffocate in other blocks (for example sand).
  • player
  • most animals
Server
collectitems The entity collections items laying around on the ground.
  • player
  • bot
  • racoon
Server
controlledphysics Add physics to the entity.
  • most entities

stepHeight = 0.6

Universal
despawn The entity will despawn under given circumstances.
  • most entities

minPlayerDistance
belowLightLevel
minSeconds = 30

Server
emotionstates Adds emotion states with a given chance. As an example, it can be used to make an animal "hungry" (aggressive) and "saturated" (passive).
  • most animals
  • most humanoids

states

Server
floatupwhenstuck Float up the entity if it gets stuck in a block.
  • item
  • most animals

onlyWhenDead = false
pushVelocityMul = 1

Universal
grow The entity will grow and eventually turn into one of its adults.
  • pig-wild-piglet
  • most baby animals

hoursToGrow = 96
adultEntityCodes = []

Server
health Applies custom health to the entity. Means the entity can be hurt as well.
  • bear
  • most entities

currenthealth = 20
maxhealth = 20
basemaxhealth = 20

Server
hunger Adds saturation and hunger, the entity needs to eat in order to stay alive.
  • player

currentsaturation = 1200 maxsaturation = 1200 saturationlossdelay = 60 * 24 currentfruitLevel = 0 currentvegetableLevel = 0 currentgrainLevel = 0 currentproteinLevel = 0 currentdairyLevel = 0

Server
interpolateposition Interpolates entity position and rotate. Smooths out the animations. It's a visual effect, therefore not available on server side.
  • most entities
Client
multiply A pack of wolves for example grows in size over time (new babies are born).
  • wolf-female
  • most female animals

pregnancyDays = 3.0
spawnEntityCode
requiresNearbyEntityCode
requiresNearbyEntityRange = 5
multiplyCooldownDaysMin = 6
multiplyCooldownDaysMax = 12
portionsEatenForMultiply = 3
spawnQuantityMin = 1
spawnQuantityMax = 2
requiresFood = true

Server
nametag Adds a name tag to the entity which will be displayed above the entity.
  • player
  • playerbot
  • trader
  • villager

renderRange = 99
selectFromRandomName
showtagonlywhentargeted = false

Universal
passivephysics Adds physics to the entity.
  • item
  • thrownstone
  • most projectiles

waterDragFactor = 1
airDragFallingFactor = 1
groundDragFactor = 1
gravityFactor = 1

Universal
placeblock The entity will place one of the given block codes from time to time.
  • hen - prior to 1.15 update

minHourDelay = 8 * 24
maxHourDelay = 15*24
blockCodes = []

Server
playerphysics Makes an entity controllable by a player. Because this inherits from controlledphysics, do not add both to an entity.
  • player

stepHeight = 0.6

Universal
repulseagents Pushes other entities back.
  • most entities
  • movable = true
Universal
taskai Allows you to specify tasks.
  • most entities

aitasks

Server
tiredness The entity will get tired over time. When it is sufficiently tired, it may sleep in a bed.
  • player

currenttiredness = 0

Universal