Json block behaviors Harvestable
Purpose
Enables right click to harvest the block. After the block is harvested, it is replaced with the one specified by the harvestedBlockCode
property.
Used by blocks
- bigberrybush
- saguarocactus
- smallberrybush
- log-resin
Usage
The player begins harvesting the block by holding right click. The player can be holding any tool while harvesting the block (the behavior ignores what the player is holding). harvestingSound
is played when the harvesting starts and again randomly during the harvest. During the harvest, particles are randomly spawned and the attack animation is shown.
After harvestTime
seconds have elapsed, the block is replaced with harvestedBlockCode
. harvestedStack
is placed in the player inventory if they have room, otherwise it is dropped on the ground. If the block has the forageStatAffected
attribute, then the dropped stack size is affected by the player's forageDropRate trait (comes from their class).
Example:
{
name: "Harvestable", properties: {
harvestTime: 1,
harvestedStack: { type: "item", code: "resin", quantity: { avg: 1 } },
harvestedBlockCode: "log-resinharvested-{wood}-ud"
}
}
The "onitemcollected" event is fired after the block is harvested. Nothing in vanilla VS listens to the event, but a mod could be created to listen to it. It is not possible for such an event handler to block the item from getting dropped.
Alone this behavior does not support making the block harvestable again after a fixed time period. So the Transient block entity class is often assigned to the harvested block type, which does replace the harvested block after a configurable time period.
Properties
harvestTime
(float, seconds, default: 0)- The number of seconds it takes to harvest the block.
harvestedStack
(BlockDropItemStack)- The item stack to drop when the block is harvested.
harvestingSound
(path from sounds folder)- Sound that is played when harvesting begins and randomly during harvesting.
harvestedBlockCode
(block code)- The harvestable block is replaced with this when harvesting is done. Typically this is an unharvestable block that converts back to harvestable block after a while using the Transient block entity class.
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 | Item • Entity • Block • Block Behaviors • Block Classes • Block Entities • Block Entity Behaviors • World properties |
Workflows & Infrastructure | Modding Efficiency Tips • Mod-engine compatibility • Mod Extensibility • VS Engine |
Additional Resources | Community Resources • Modding API Updates • Programming Languages • List of server commands • List of client commands • Client startup parameters • Server startup parameters Example Mods • API Docs • GitHub Repository |