diff --git a/mods/core/drop.lua b/mods/core/drop.lua index bff330c..ec1b090 100644 --- a/mods/core/drop.lua +++ b/mods/core/drop.lua @@ -31,7 +31,7 @@ function minetest.handle_node_drops(pos, drops, digger) end if minetest.get_node_group(minetest.env:get_node(pos).name, "drop_on_dig") == 1 then drop_all() - elseif digger:get_inventory() then + elseif digger and digger:get_inventory() then for _, dropped_item in ipairs(drops) do if digger:get_inventory():room_for_item("main", dropped_item) then digger:get_inventory():add_item("main", dropped_item) @@ -39,5 +39,7 @@ function minetest.handle_node_drops(pos, drops, digger) drop(dropped_item) end end + else + drop_all() end end diff --git a/mods/core/falling.lua b/mods/core/falling.lua index afbcd24..54fc1d0 100644 --- a/mods/core/falling.lua +++ b/mods/core/falling.lua @@ -1,31 +1,53 @@ +function minetest.register_node(name, nodedef) + nodedef.type = "node" + if not nodedef.cause_drop then + nodedef.cause_drop = function(pos, node) + local b_pos = {x=pos.x,y=pos.y-1,z=pos.z} + local b_node = minetest.env:get_node(b_pos) + if minetest.registered_nodes[b_node.name].walkable == false then + return true + end + end + end + if not nodedef.cause_fall then + nodedef.cause_fall = function(pos, node) + local b_pos = {x=pos.x,y=pos.y-1,z=pos.z} + local b_node = minetest.env:get_node(b_pos) + if minetest.registered_nodes[b_node.name].walkable == false then + return true + end + end + end + minetest.register_item(name, nodedef) +end + function nodeupdate_single(p) n = minetest.env:get_node(p) if minetest.get_node_group(n.name, "falling_node") ~= 0 then - p_bottom = {x=p.x, y=p.y-1, z=p.z} - n_bottom = minetest.env:get_node(p_bottom) - -- Note: walkable is in the node definition, not in item groups - if minetest.registered_nodes[n_bottom.name] and - not minetest.registered_nodes[n_bottom.name].walkable then - minetest.env:remove_node(p) - spawn_falling_node(p, n.name) + 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 - p_bottom = {x=p.x, y=p.y-1, z=p.z} - n_bottom = minetest.env:get_node(p_bottom) - if not minetest.registered_nodes[n_bottom.name].walkable and n_bottom.name ~= n.name then - if not minetest.registered_nodes[n.name].drop_on_dropping then - minetest.env:dig_node(p) + 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) - local stack = ItemStack(minetest.registered_nodes[n.name].drop_on_dropping) - for i = 1,stack:get_count() do - local obj = minetest.env:add_item(p, stack:get_name()) - local x = math.random(-5,5) - local z = math.random(-5,5) - obj:setvelocity({x=1/x, y=obj:getvelocity().y, z=1/z}) - end + 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 diff --git a/mods/default/init.lua b/mods/default/init.lua index e7b7905..f54c5be 100644 --- a/mods/default/init.lua +++ b/mods/default/init.lua @@ -441,6 +441,13 @@ minetest.register_node("default:papyrus", { walkable = false, groups = {snappy=3,flammable=2, dropping_node=1,drop_on_dig=1}, sounds = default.node_sound_leaves_defaults(), + cause_drop = function(pos, node) + local b_pos = {x=pos.x,y=pos.y-1,z=pos.z} + local b_node = minetest.env:get_node(b_pos) + if b_node.name ~= node.name and minetest.registered_nodes[b_node.name].walkable == false then + return true + end + end }) minetest.register_node("default:glass", { @@ -662,6 +669,7 @@ minetest.register_node("default:cobble_node", { }, drop = "default:cobble", groups = {dig_immediate=2,dropping_node=1,drop_on_dig=1}, + buildable_to = true, sounds = default.node_sound_stone_defaults(), }) diff --git a/mods/trees/init.lua b/mods/trees/init.lua index 795273d..b4b50dd 100644 --- a/mods/trees/init.lua +++ b/mods/trees/init.lua @@ -13,9 +13,10 @@ function trees.make_tree(pos, tree) return end end - for i = 0,height do + for i = 0,height-1 do minetest.env:add_node({x=pos.x, y=pos.y+i, z=pos.z}, {name=tree.name.."_trunk"}) end + minetest.env:add_node({x=pos.x, y=pos.y+height, z=pos.z}, {name=tree.name.."_trunk_top"}) for i = 1,#tree.leaves do local p = {x=pos.x+tree.leaves[i][1], y=pos.y+height+tree.leaves[i][2], z=pos.z+tree.leaves[i][3]} if minetest.env:get_node(p).name == "air" or minetest.env:get_node(p).name == "ignore" then diff --git a/mods/trees/registration.lua b/mods/trees/registration.lua index bff5f14..059519b 100644 --- a/mods/trees/registration.lua +++ b/mods/trees/registration.lua @@ -180,6 +180,27 @@ function realtest.register_tree(name, TreeDef) {-0.4,-0.5,-0.4,0.4,0.5,0.4}, }, }, + }) + + minetest.register_node(tree.name.."_trunk_top", { + tiles = tree.textures.trunk, + groups = {tree=1,snappy=1,choppy=2,flammable=2,dropping_node=1,drop_on_dig=1}, + sounds = default.node_sound_wood_defaults(), + drop = tree.name.."_log", + drawtype = "nodebox", + paramtype = "light", + node_box = { + type = "fixed", + fixed = { + {-0.4,-0.5,-0.4,0.4,0.5,0.4}, + }, + }, + selection_box = { + type = "fixed", + fixed = { + {-0.4,-0.5,-0.4,0.4,0.5,0.4}, + }, + }, after_dig_node = function(pos, oldnode, oldmetadata, digger) for i = 1,#tree.leaves do local p = {x=pos.x+tree.leaves[i][1], y=pos.y+tree.leaves[i][2], z=pos.z+tree.leaves[i][3]}