FANDOM


This Article is up to date with Custom Stuff 2 CS2

Below, you can find a list of triggers for blocks that can be used to add functionality to your custom blocks. For item triggers, refer to the Item Function Triggers page.

The table below also contains various information that is labeled as untested. If someone has or would like to confirm this information, please feel free to update the table to indicate your results.

Table of Triggers

Trigger Name Description Functions and Variables
onActivated This trigger is called when the player right clicks (or activates) the block. Useful for chests, furnaces, and crafting tables, among other uses. mod, config, world, position, player, side, hitX, and hitY
onAdded This trigger is called when a block is added to the world. This can be through almost any means. Unknown if it is triggered from world generation. mod, config, world, and position
onBoneMeal This trigger is called when bonemeal is used on the block. Useful for custom plants that grow over time. mod, config, world, position, and player
onBreak This trigger is called when the block gets removed. This is called even if the block is removed using harvestBlock. Untested with setBlockId. Refer to onDestroyedByPlayer if this is undesired. mod, config, world, and position
onClicked This trigger is called when the player left clicks the block. mod, config, world, position, and player
onCollided This trigger is called when an entity collides with the block. It is untested if hasCollision needs to be set to true or false for this to trigger. mod, config, world, entity, and position
onDestroyedByPlayer This trigger is called when the block is destroyed by a player. Useful if you do not want the trigger to go off because of explosions or other scripts. mod, config, world, and position
onFallenUpon This trigger is called when an entity (player, mob, item, etc) falls on the block. Untested if it has to be from a fall greater than 3 blocks high. mod, config, world, and position
onNeighborChange This trigger is called when a neighboring block changes. This may also trigger with state changes such as redstone current changes. mod, config, world, and position
onPlaced This trigger is called when a block is placed. Exactly which methods of placing a block do not trigger this is currently untested. mod, config, world, and position
onPlacedBy This trigger is called when an entity places the block. Untested if this triggers when block is moved by piston or from changing back from a falling block entity. mod, config, world, position, and living
onPlacedByPlayer This trigger is called when a player places the block. Untested if player.placeBlock() also triggers this. mod, config, world, position, and player
onRedstoneSignal This trigger is called when the block is added or when a neighbor changes. The redstoneSignal boolean attribute is used to check if redstone signal is being applied to the block. mod, config, world, position, and redstoneSignal
onUpdate This trigger is called every tickrate ticks while the block is in the world. Useful for plants that grow over time or imitating decay. mod, config, world, and player
onWalking This trigger is called when an entity is walking on the block. Doesn't trigger if the entity stops moving. mod, config, world, entity, and position
onWalkingLiving This trigger is called when a mob is walking on the block. Doesn't trigger if the entity stops moving. mod, config, world, living, and position
onWalkingPlayer This trigger is called when an entity is walking on the block.Doesn't trigger if the entity stops moving. mod, config, world, player, and position

Examples

Receive a diamond each time you right click the block:

onActivated[0] = "player.add(264, 0, 1);";

Same example, but using config functions to give a custom item:

onActivated[0] = "player.add(config.getItemId("pinkDiamondID"), 0, 1);";

Example for changing block metadata depending on redstone state:

onRedstoneSignal[0] = "if(redstoneSignal == true){world.setBlockMetadata(position, 1);}";
onRedstoneSignal[1] = "if(redstoneSignal == false){world.setBlockMetadata(position, 0);}";

Make a 5% chance for a cherry blossom sapling to drop even if removed by harvestBlock function:

onBreak[0] = "if(Math.floor(Math.random()*100 < 20){world.spawnItem(position, config.getBlockId("cherryBlossomSaplingID"), 0, 1);}";

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.