Change document formatting, finally move cactus cart dropping to node definition for mcl_core:cactus
This commit is contained in:
parent
be664b08ec
commit
08e2876a1e
|
@ -1,4 +1,4 @@
|
|||
== Cart-Node interactions
|
||||
## Cart-Node interactions
|
||||
|
||||
As the cart moves thru the environment, it can interact with the surrounding blocks
|
||||
thru a number of handlers in the block definitions. All these handlers are defined
|
||||
|
@ -7,18 +7,18 @@ as:
|
|||
`function(node_position, cart_luaentity, cart_direction, cart_position)`
|
||||
|
||||
Arguments:
|
||||
`node_position` - position of the node the cart is interacting with
|
||||
`cart_luaentity` - The luaentity of the cart that is entering this block. Will
|
||||
- `node_position` - position of the node the cart is interacting with
|
||||
- `cart_luaentity` - The luaentity of the cart that is entering this block. Will
|
||||
be nil for minecarts moving thru unloaded blocks
|
||||
`cart_direction` - The direction the cart is moving
|
||||
`cart_position` - The location of the cart
|
||||
`cart_data` - Information about the cart. This will always be defined.
|
||||
- `cart_direction` - The direction the cart is moving
|
||||
- `cart_position` - The location of the cart
|
||||
- `cart_data` - Information about the cart. This will always be defined.
|
||||
|
||||
There are several variants of this handler:
|
||||
`_mcl_minecarts_on_enter` - The cart enters this block
|
||||
`_mcl_minecarts_on_enter_below` - The cart enters above this block
|
||||
`_mcl_minecarts_on_enter_above` - The cart enters below this block
|
||||
`_mcl_minecarts_on_enter_side` - The cart enters beside this block
|
||||
- `_mcl_minecarts_on_enter` - The cart enters this block
|
||||
- `_mcl_minecarts_on_enter_below` - The cart enters above this block
|
||||
- `_mcl_minecarts_on_enter_above` - The cart enters below this block
|
||||
- `_mcl_minecarts_on_enter_side` - The cart enters beside this block
|
||||
|
||||
Mods can also define global handlers that are called for every node. These
|
||||
handlers are defined as:
|
||||
|
@ -26,13 +26,13 @@ handlers are defined as:
|
|||
`function(node_position, cart_luaentity, cart_direction, node_definition, cart_data)`
|
||||
|
||||
Arguments:
|
||||
`node_position` - position of the node the cart is interacting with
|
||||
`cart_luaentity` - The luaentity of the cart that is entering this block. Will
|
||||
- `node_position` - position of the node the cart is interacting with
|
||||
- `cart_luaentity` - The luaentity of the cart that is entering this block. Will
|
||||
be nil for minecarts moving thru unloaded blocks
|
||||
`cart_direction` - The direction the cart is moving
|
||||
`cart_position` - The location of the cart
|
||||
`cart_data` - Information about the cart. This will always be defined.
|
||||
`node_definition` - The definition of the node at `node_position`
|
||||
- `cart_direction` - The direction the cart is moving
|
||||
- `cart_position` - The location of the cart
|
||||
- `cart_data` - Information about the cart. This will always be defined.
|
||||
- `node_definition` - The definition of the node at `node_position`
|
||||
|
||||
The available hooks are:
|
||||
`_mcl_minecarts.on_enter` - The cart enters this block
|
||||
|
|
|
@ -249,7 +249,7 @@ function DEFAULT_CART_DEF:on_step(dtime)
|
|||
mod.update_cart_orientation(self)
|
||||
|
||||
end
|
||||
local function kill_cart(staticdata)
|
||||
function mod.kill_cart(staticdata)
|
||||
local pos
|
||||
minetest.log("action", "cart #"..staticdata.uuid.." was killed")
|
||||
|
||||
|
@ -272,6 +272,9 @@ local function kill_cart(staticdata)
|
|||
local mob = le._passenger.object
|
||||
mob:set_detach()
|
||||
end
|
||||
|
||||
-- Remove the entity
|
||||
le.object:remove()
|
||||
else
|
||||
pos = mod.get_cart_position(staticdata)
|
||||
end
|
||||
|
@ -292,8 +295,9 @@ local function kill_cart(staticdata)
|
|||
|
||||
-- Remove data
|
||||
destroy_cart_data(staticdata.uuid)
|
||||
|
||||
end
|
||||
local kill_cart = mod.kill_cart
|
||||
|
||||
function DEFAULT_CART_DEF:on_death(killer)
|
||||
kill_cart(self._staticdata)
|
||||
end
|
||||
|
@ -561,26 +565,6 @@ minetest.register_globalstep(function(dtime)
|
|||
--- Non-entity code
|
||||
if staticdata.connected_at then
|
||||
do_movement(staticdata, dtime)
|
||||
|
||||
-- TODO: move this into mcl_core:cactus _mcl_minecarts_on_enter_side
|
||||
-- Drop minecart if it collides with a cactus node
|
||||
local pos = mod.get_cart_position(staticdata)
|
||||
if pos then
|
||||
local r = 0.6
|
||||
for _, node_pos in pairs({{r, 0}, {0, r}, {-r, 0}, {0, -r}}) do
|
||||
if minetest.get_node(vector.offset(pos, node_pos[1], 0, node_pos[2])).name == "mcl_core:cactus" then
|
||||
kill_cart(staticdata)
|
||||
local le = mcl_util.get_luaentity_from_uuid(staticdata.uuid)
|
||||
if le then
|
||||
le:on_death()
|
||||
le.object:remove()
|
||||
else
|
||||
kill_cart(staticdata)
|
||||
end
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
|
|
@ -48,6 +48,11 @@ minetest.register_node("mcl_core:cactus", {
|
|||
end),
|
||||
_mcl_blast_resistance = 0.4,
|
||||
_mcl_hardness = 0.4,
|
||||
_mcl_minecarts_on_enter_side = function(pos, _, _, _, cart_data)
|
||||
if mcl_minecarts then
|
||||
mcl_minecarts.kill_cart(cart_data)
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("mcl_core:reeds", {
|
||||
|
|
Loading…
Reference in New Issue