Modding:Entity Behavior harvestable

From Vintage Story Wiki
Revision as of 21:11, 21 October 2024 by Craluminum (talk | contribs) (added a note about quantitySlots that it will crash if done wrong way)

This entity behavior behavior handles calculating the entity drops, updating the animal weight, adjusting the drops based on weight, and the harvest inventory.

The GuiDialogCreatureContents will only open if the entity is in the harvested state. In the vanilla code, only the knife can put the entity in the harvested state.

The way the animal died also affects the drop rate. The drop rate is halved if the entity died from falling or crushing. The drop rate is reduced to 40% if the animal was killed by an entity other than the player.

The behavior must be installed on the client so that it can open the harvested dialog. It must also be installed on the server so that the server calculates the drops. So the drops only need to be listed on the server side. Here's an example from "wolf-male.json".

	client: {
        ...
		behaviors: [
            ...
            { code: "harvestable" },
            ...
		],
        ...
	},
	server: {
        ...
		behaviors: [
            ...
            {
                code: "harvestable",
                drops: [ 
                    {
                        type: "item", 
                        code: "bushmeat-raw", 
                        quantity: { avg: 7, var: 1 }
                    },
                    {
                        type: "item", 
                        code: "hide-raw-medium", 
                        quantity: { avg: 1.5, var: 0 }
                    },
                    {
                        type: "item", 
                        code: "fat",
                        quantity: { avg: 1.25, var: 0 }
                    }
                ]
            },
            ...
		],
        ...
	},

This behavior stores the harvest inventory in the "harvestableInv" attribute on the entity. There can only be at most one harvestable behavior per entity variant, because otherwise the multiple copies of the behavior would override each others inventory in that attribute. The harvestable behavior is also incompatible with the openablecontainer behavior for the same reason.

An alternative to the harvestable behavior is to directly list drops in the entity properties. The entity drops are immediately spawned on the ground when the entity dies. This differs from the harvestable drops, where the player has to right click harvest the corpse, then remove the items from the harvest inventory.

Starting in 1.20.0-pre.1, this behavior also adds all of the entity drops as harvestable drops, in addition to how on death the entity already drops the entity drops. Presumably these duplicate drops are a bug that will get fixed later.

Animal weight

The animals spawn in with a random weight between 0.66 (low weight) and 0.86 (okay weight). Animals quickly gain weight for the first week after eating. They will continue to gain wait for up to 4 months after eating. After 4 months, they slowly lose weight when the temperature is at or below 0, or maintain weight if the temperature is above 0.

If "harshWinters" are disabled in the world config, then animals are still given a random weight when they spawn, but it is not adjusted after that. Even increasing the weight after eating is disabled.

The animal weight only affects drops listed in the behavior (not drops attached directly to the entity) which have nutrition. It also affects foods that can be cooked to have nutrition, this includes redmeat-raw, which cannot be eaten raw, but can be cooked.

Properties

quantitySlots: (int, default 4)
minimum number of slots in the inventory. This will be increased if necessary when the drops are calculated. Should be identical on both client and server otherwise it will crash.
drops: (array of BlockDropItemStack, default empty)
the harvest drops.
duration: (float, default 5)
the number of seconds the player must use the knife on the corpse to harvest it. The actual number of seconds is reduced based on the knife tier.
fixedweight: (boolean, default false)
if true, then disable the animal weight system for this entity.


Content Modding
Basics Content Mods Developing a Content Mod Packaging & Release
Tutorials
Concepts Modding Concepts Modinfo Variants Domains Patching Remapping World Properties
Moddable Assets
Uncategorized
Icon Sign.png

Wondering where some links have gone?
The modding navbox is going through some changes! Check out Navigation Box Updates for more info and help finding specific pages.

Modding
Modding Introduction Getting Started Theme Pack
Content Modding Content Mods Developing a Content Mod Basic Tutorials Intermediate Tutorials Advanced Tutorials Content Mod Concepts
Code Modding Code Mods Setting up your Development Environment
Property Overview ItemEntityEntity BehaviorsBlockBlock BehaviorsBlock ClassesBlock EntitiesBlock Entity BehaviorsCollectible BehaviorsWorld properties
Workflows & Infrastructure Modding Efficiency TipsMod-engine compatibilityMod ExtensibilityVS Engine
Additional Resources Community Resources Modding API Updates Programming Languages List of server commandsList of client commandsClient startup parametersServer startup parameters
Example ModsAPI DocsGitHub Repository