Unified custom falling checks
This commit is contained in:
parent
ce99412270
commit
443bade6d6
@ -67,10 +67,6 @@ IDEAS: Possible future additions/improvements to the game
|
||||
- Upconvert dirt to humus nearby?
|
||||
- Rushes to reeds to windchimes?
|
||||
|
||||
- Rework falling_node (or build alternative) with customizability
|
||||
- Allow lode rods, ladders to hang from ceilings?
|
||||
- Add on_fall_check hook, hook in check_single_for_falling
|
||||
|
||||
- A pure white concrete material?
|
||||
- Use crude glass for recipe? Flow wet concrete into crude
|
||||
glass from above?
|
||||
|
@ -141,9 +141,6 @@ ISSUES-CODE: Issues related to code quality and APIs
|
||||
modified copy of another definition, e.g. for planted eggcorns copying
|
||||
dirt, door panels copying original materials, etc.
|
||||
|
||||
- Add an on_falling_check handler to replace check_single_for_falling custom
|
||||
hook in writing, and possibly other places.
|
||||
|
||||
- Should we create "recipe groups" to make it easier to specify
|
||||
equivalent recipes for hint purposes?
|
||||
|
||||
|
@ -13,9 +13,16 @@ function minetest.check_single_for_falling(pos, ...)
|
||||
if not def then return n end
|
||||
return (not (def and def.groups and def.groups.support_falling)) and n or nil
|
||||
end
|
||||
local function helper(...)
|
||||
local function helper(fell, ...)
|
||||
minetest.get_node_or_nil = gnon
|
||||
return ...
|
||||
if not fell then
|
||||
local node = minetest.get_node(pos)
|
||||
local def = minetest.registered_nodes[node.name] or {}
|
||||
if def.on_falling_check then
|
||||
return def.on_falling_check(pos, node)
|
||||
end
|
||||
end
|
||||
return fell, ...
|
||||
end
|
||||
return helper(csff(pos, ...))
|
||||
end
|
||||
|
@ -129,25 +129,6 @@ function minetest.item_drop(item, player, ...)
|
||||
return helper(olddrop(item, player, ...))
|
||||
end
|
||||
|
||||
local oldfallcheck = minetest.check_single_for_falling
|
||||
function minetest.check_single_for_falling(pos, ...)
|
||||
local function helper(...)
|
||||
if minetest.get_node(pos).name ~= modname .. ":stack" then return ... end
|
||||
local stack = nodecore.stack_get(pos)
|
||||
local below = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||
if minetest.get_node(below).name == modname .. ":stack" then
|
||||
stack = nodecore.stack_add(below, stack)
|
||||
if stack:is_empty() then
|
||||
minetest.remove_node(pos)
|
||||
else
|
||||
nodecore.stack_set(pos, stack)
|
||||
end
|
||||
return ...
|
||||
end
|
||||
end
|
||||
return helper(oldfallcheck(pos, ...))
|
||||
end
|
||||
|
||||
local oldlog = minetest.log
|
||||
function minetest.log(...)
|
||||
local args = {...}
|
||||
|
@ -70,6 +70,19 @@ minetest.register_node(modname .. ":stack", {
|
||||
after_dig_node = pezdispense,
|
||||
on_settle_item = function(pos, _, stack)
|
||||
return nodecore.stack_add(pos, stack)
|
||||
end,
|
||||
on_falling_check = function(pos)
|
||||
local stack = nodecore.stack_get(pos)
|
||||
local below = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||
if minetest.get_node(below).name == modname .. ":stack" then
|
||||
stack = nodecore.stack_add(below, stack)
|
||||
if stack:is_empty() then
|
||||
minetest.remove_node(pos)
|
||||
else
|
||||
nodecore.stack_set(pos, stack)
|
||||
end
|
||||
return false
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
|
@ -50,20 +50,14 @@ for i = 1, #nodecore.writing_glyphs do
|
||||
return raw .. "\n" .. desc
|
||||
end
|
||||
return raw
|
||||
end,
|
||||
on_falling_check = function(pos, node)
|
||||
local dp = vector.add(pos, nodecore.facedirs[node.param2].b)
|
||||
if not nodecore.writing_writable(dp, nil, true) then
|
||||
minetest.remove_node(pos)
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
local oldcsff = minetest.check_single_for_falling
|
||||
function minetest.check_single_for_falling(pos, ...)
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
if not node then return oldcsff(pos, ...) end
|
||||
if minetest.get_item_group(node.name, "alpha_glyph") ~= 0 then
|
||||
local dp = vector.add(pos, nodecore.facedirs[node.param2].b)
|
||||
if not nodecore.writing_writable(dp, nil, true) then
|
||||
minetest.remove_node(pos)
|
||||
return true
|
||||
end
|
||||
end
|
||||
return oldcsff(pos, ...)
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user