2014-12-15 23:04:40 +03:00
|
|
|
---
|
|
|
|
title: Active Block Modifiers
|
|
|
|
layout: default
|
2017-08-26 18:40:30 +03:00
|
|
|
root: ../../
|
2014-12-15 23:04:40 +03:00
|
|
|
---
|
|
|
|
|
2015-02-22 13:28:37 +03:00
|
|
|
## Introduction
|
2014-12-15 23:04:40 +03:00
|
|
|
|
2017-08-29 02:48:40 +03:00
|
|
|
An **A**ctive **B**lock **M**odifier (**ABM**) allows you to run code on
|
2017-08-29 02:21:46 +03:00
|
|
|
certain nodes at specific intervals.
|
2017-08-29 02:38:45 +03:00
|
|
|
|
2017-08-29 02:21:46 +03:00
|
|
|
Please be warned, ABMs which are too frequent or act on a large number of nodes
|
|
|
|
cause massive amounts of lag. Use them sparingly.
|
2014-12-15 23:04:40 +03:00
|
|
|
|
2017-08-29 14:17:21 +03:00
|
|
|
* [Example: Growing Alien Grass](#example-growing-alien-grass)
|
2017-08-29 02:38:45 +03:00
|
|
|
* [Your Turn](#your-turn)
|
|
|
|
|
|
|
|
## Example: Growing Alien Grass
|
2014-12-15 23:04:40 +03:00
|
|
|
|
2017-08-29 02:38:45 +03:00
|
|
|
Alien grass, for the purposes of this chapter, is a type of grass which
|
|
|
|
has a chance to appear near water.
|
2014-12-15 23:04:40 +03:00
|
|
|
|
2017-08-29 02:38:45 +03:00
|
|
|
To create it, you first need to register the grass, then
|
2017-08-29 02:21:46 +03:00
|
|
|
write an ABM.
|
2014-12-15 23:04:40 +03:00
|
|
|
|
|
|
|
{% highlight lua %}
|
|
|
|
minetest.register_node("aliens:grass", {
|
2017-08-26 21:01:51 +03:00
|
|
|
description = "Alien Grass",
|
|
|
|
light_source = 3, -- The node radiates light. Values can be from 1 to 15
|
|
|
|
tiles = {"aliens_grass.png"},
|
|
|
|
groups = {choppy=1},
|
|
|
|
on_use = minetest.item_eat(20)
|
2014-12-15 23:04:40 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
minetest.register_abm({
|
2017-08-26 21:01:51 +03:00
|
|
|
nodenames = {"default:dirt_with_grass"},
|
|
|
|
neighbors = {"default:water_source", "default:water_flowing"},
|
|
|
|
interval = 10.0, -- Run every 10 seconds
|
|
|
|
chance = 50, -- Select every 1 in 50 nodes
|
|
|
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
|
|
|
minetest.set_node({x = pos.x, y = pos.y + 1, z = pos.z}, {name = "aliens:grass"})
|
|
|
|
end
|
2014-12-15 23:04:40 +03:00
|
|
|
})
|
|
|
|
{% endhighlight %}
|
|
|
|
|
2017-08-29 02:21:46 +03:00
|
|
|
This ABM runs every ten seconds. There is a 1 in 5 chance of the ABM running on each
|
|
|
|
node that has the correct name and the correct neighbors. If the ABM runs on a
|
|
|
|
node, an alien grass node is placed above it. Please be warned, this will delete any
|
|
|
|
node previously located in that position. To prevent this you should include a check
|
|
|
|
using minetest.get_node to make sure there is space for the grass.
|
2014-12-15 23:04:40 +03:00
|
|
|
|
2017-08-29 02:21:46 +03:00
|
|
|
Specifying a neighbor is optional. If you specify multiple neighbors, only one of them
|
|
|
|
needs to be present to meet the requirements.
|
|
|
|
|
|
|
|
Specifying chance is also optional. If you don't specify the chance, the ABM will
|
2017-08-29 02:38:45 +03:00
|
|
|
always run when the other conditions are met.
|
2014-12-15 23:04:40 +03:00
|
|
|
|
2015-02-22 13:28:37 +03:00
|
|
|
## Your Turn
|
2014-12-15 23:04:40 +03:00
|
|
|
|
|
|
|
* **Midas touch**: Make water turn to gold blocks with a 1 in 100 chance, every 5 seconds.
|
|
|
|
* **Decay**: Make wood turn into dirt when water is a neighbor.
|
|
|
|
* **Burnin'**: Make every air node catch on fire. (Tip: "air" and "fire:basic_flame").
|
|
|
|
Warning: expect the game to crash.
|