Added realtest.register_on_updatenode function and added dropping_like_stone group
This commit is contained in:
parent
98577f8931
commit
2c652a48e3
@ -26,6 +26,88 @@ function minetest.register_node(name, nodedef)
|
||||
minetest.register_item(name, nodedef)
|
||||
end
|
||||
|
||||
realtest.registered_on_updatenodes = {}
|
||||
function realtest.register_on_updatenode(func)
|
||||
table.insert(realtest.registered_on_updatenodes, func)
|
||||
end
|
||||
minetest.register_on_updatenode = realtest.register_on_updatenode
|
||||
|
||||
function nodeupdate_single(pos)
|
||||
for _, callback in ipairs(realtest.registered_on_updatenodes) do
|
||||
callback(pos)
|
||||
end
|
||||
end
|
||||
|
||||
function nodeupdate(pos)
|
||||
for x = -1,1 do
|
||||
for y = -1,1 do
|
||||
for z = -1,1 do
|
||||
pos2 = {x=pos.x+x, y=pos.y+y, z=pos.z+z}
|
||||
nodeupdate_single(pos2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
realtest.register_on_updatenode(function(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
if minetest.get_node_group(node.name, "dropping_node") ~= 0 then
|
||||
if minetest.registered_nodes[node.name].cause_drop(pos, node) then
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
if minetest.registered_nodes[node.name].on_dropping then
|
||||
minetest.registered_nodes[node.name].on_dropping(pos, node)
|
||||
else
|
||||
local drops = minetest.registered_nodes[node.name].drop_on_dropping or
|
||||
minetest.registered_nodes[node.name].drop or node.name
|
||||
if type(drops) == "string" then drops = {drops} end
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.handle_node_drops(pos, drops)
|
||||
end
|
||||
if minetest.registered_nodes[node.name].after_dig_node then
|
||||
minetest.registered_nodes[node.name].after_dig_node(pos, node, meta, nil)
|
||||
end
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
realtest.register_on_updatenode(function(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
local b_node = minetest.env:get_node({x=pos.x,y=pos.y-1,z=pos.z})
|
||||
if minetest.get_node_group(node.name, "dropping_like_stone") ~= 0 and
|
||||
(minetest.registered_nodes[b_node.name].walkable == false or
|
||||
minetest.registered_nodes[b_node.name].buildable_to) then
|
||||
local sides = {{x=-1,y=0,z=0}, {x=1,y=0,z=0}, {x=0,y=0,z=-1}, {x=0,y=0,z=1}, {x=0,y=-1,z=0}, {x=0,y=1,z=0}}
|
||||
local fall = true
|
||||
for _, s in ipairs(sides) do
|
||||
if minetest.get_node_group(minetest.env:get_node({x=pos.x+s.x,y=pos.y+s.y,z=pos.z+s.z}).name, "dropping_like_stone") ~= 0 then
|
||||
fall = false
|
||||
break
|
||||
end
|
||||
end
|
||||
if fall then
|
||||
minetest.env:remove_node({x=pos.x,y=pos.y,z=pos.z})
|
||||
minetest.handle_node_drops(pos, {node.name})
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
realtest.register_on_updatenode(function(pos)
|
||||
local node = minetest.env:get_node(pos)
|
||||
if minetest.get_node_group(node.name, "falling_node") ~= 0 then
|
||||
if minetest.registered_nodes[node.name].cause_fall(pos, node) then
|
||||
if minetest.registered_nodes[node.name].on_falling then
|
||||
minetest.registered_nodes[node.name].on_falling(pos, node)
|
||||
else
|
||||
minetest.env:remove_node(pos)
|
||||
spawn_falling_node(pos, node.name)
|
||||
end
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_entity(":__builtin:falling_node", {
|
||||
initial_properties = {
|
||||
physical = true,
|
||||
@ -111,48 +193,4 @@ minetest.register_entity(":__builtin:falling_node", {
|
||||
-- Do nothing
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
function nodeupdate_single(p)
|
||||
n = minetest.env:get_node(p)
|
||||
if minetest.get_node_group(n.name, "falling_node") ~= 0 then
|
||||
if minetest.registered_nodes[n.name].cause_fall(p, n) then
|
||||
if minetest.registered_nodes[n.name].on_falling then
|
||||
minetest.registered_nodes[n.name].on_falling(p, n)
|
||||
else
|
||||
minetest.env:remove_node(p)
|
||||
spawn_falling_node(p, n.name)
|
||||
end
|
||||
nodeupdate(p)
|
||||
end
|
||||
end
|
||||
if minetest.get_node_group(n.name, "dropping_node") ~= 0 then
|
||||
if minetest.registered_nodes[n.name].cause_drop(p, n) then
|
||||
local meta = minetest.env:get_meta(p)
|
||||
if minetest.registered_nodes[n.name].on_dropping then
|
||||
minetest.registered_nodes[n.name].on_dropping(p, n)
|
||||
else
|
||||
local drops = minetest.registered_nodes[n.name].drop_on_dropping or
|
||||
minetest.registered_nodes[n.name].drop or n.name
|
||||
if type(drops) == "string" then drops = {drops} end
|
||||
minetest.env:remove_node(p)
|
||||
minetest.handle_node_drops(p, drops)
|
||||
end
|
||||
if minetest.registered_nodes[n.name].after_dig_node then
|
||||
minetest.registered_nodes[n.name].after_dig_node(p, n, meta, nil)
|
||||
end
|
||||
nodeupdate(p)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function nodeupdate(p)
|
||||
for x = -1,1 do
|
||||
for y = -1,1 do
|
||||
for z = -1,1 do
|
||||
p2 = {x=p.x+x, y=p.y+y, z=p.z+z}
|
||||
nodeupdate_single(p2)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
@ -23,7 +23,7 @@ function realtest.register_stone(name, StoneRef)
|
||||
description = stone.description,
|
||||
tiles = {name_..".png"},
|
||||
particle_image = {name_.."_small_rock.png"},
|
||||
groups = {cracky=3, drop_on_dig=1, stone=1},
|
||||
groups = {cracky=3, drop_on_dig=1, stone=1, dropping_like_stone=1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
drop = {
|
||||
max_items = 1,
|
||||
@ -150,25 +150,6 @@ function realtest.register_stone(name, StoneRef)
|
||||
instruments.chisel_pairs[name.."_slab_r"] = name.."_flat_slab_r"
|
||||
instruments.chisel_pairs[name.."_stair"] = name.."_flat_stair"
|
||||
instruments.chisel_pairs[name.."_stair_r"] = name.."_flat_stair_r"
|
||||
|
||||
minetest.register_on_dignode(function(pos, oldnode, digger)
|
||||
local sides = {{x=-1,y=0,z=0}, {x=1,y=0,z=0}, {x=0,y=0,z=-1}, {x=0,y=0,z=1}, {x=0,y=-1,z=0}, {x=0,y=1,z=0},}
|
||||
for _, s in ipairs(sides) do
|
||||
if minetest.env:get_node({x=pos.x+s.x,y=pos.y+s.y,z=pos.z+s.z}).name == name then
|
||||
local fall = true
|
||||
for _2, s2 in ipairs(sides) do
|
||||
if minetest.env:get_node({x=pos.x+s.x+s2.x,y=pos.y+s.y+s2.y,z=pos.z+s.z+s2.z}).name ~= "air" then
|
||||
fall = false
|
||||
break
|
||||
end
|
||||
end
|
||||
if fall then
|
||||
minetest.env:remove_node({x=pos.x+s.x,y=pos.y+s.y,z=pos.z+s.z})
|
||||
minetest.env:add_item({x=pos.x+s.x,y=pos.y+s.y,z=pos.z+s.z}, name)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
realtest.register_stone("default:stone")
|
||||
@ -177,7 +158,7 @@ minetest.register_node(":default:stone", {
|
||||
description = "Stone",
|
||||
tiles = {"default_stone.png"},
|
||||
particle_image = {"default_stone_small_rock.png"},
|
||||
groups = {cracky=3, drop_on_dig=1, stone=1},
|
||||
groups = {cracky=3, drop_on_dig=1, stone=1, dropping_like_stone=1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
drop = {
|
||||
max_items = 1,
|
||||
|
@ -39,7 +39,7 @@ function realtest.register_ore(name, OreDef)
|
||||
description = ore.description .. " Ore",
|
||||
tiles = wherein_textures,
|
||||
particle_image = {ore.particle_image},
|
||||
groups = {cracky=3,drop_on_dig=1,ore=1},
|
||||
groups = {cracky=3,drop_on_dig=1,ore=1,dropping_like_stone=1},
|
||||
drop = {
|
||||
max_items = 1,
|
||||
items = {
|
||||
|
Loading…
x
Reference in New Issue
Block a user