Return "correct" drops when digging a flowerpot (#14)
This returns the result of digging the actual node in the world. the "downside" of that is that digging grass in a flowerpot might give you seeds or something now, but at least it's not a weird "not_in_creative_inventory" item.
This commit is contained in:
parent
1431a640b2
commit
7d2fecdb4a
69
init.lua
69
init.lua
@ -12,32 +12,34 @@
|
||||
|
||||
flowerpot = {}
|
||||
|
||||
local f = string.format
|
||||
|
||||
-- Translation
|
||||
local S = minetest.get_translator("flowerpot")
|
||||
|
||||
local flower_items_by_pot = {}
|
||||
|
||||
-- handle plant insertion into flowerpot
|
||||
local function flowerpot_on_rightclick(pos, node, clicker, itemstack, pointed_thing)
|
||||
if clicker and not minetest.check_player_privs(clicker, "protection_bypass") then
|
||||
local name = clicker:get_player_name()
|
||||
if minetest.is_protected(pos, name) then
|
||||
minetest.record_protection_violation(pos, name)
|
||||
return itemstack
|
||||
end
|
||||
if not minetest.is_player(clicker) then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local nodename = itemstack:get_name()
|
||||
local player_name = clicker:get_player_name()
|
||||
|
||||
if nodename:match("grass_1") then
|
||||
nodename = nodename:gsub("grass_1", "grass_" .. math.random(5))
|
||||
if minetest.is_protected(pos, player_name) then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
local name = "flowerpot:" .. nodename:gsub(":", "_")
|
||||
local def = minetest.registered_nodes[name]
|
||||
local item_name = itemstack:get_name()
|
||||
|
||||
local pot_name = "flowerpot:" .. item_name:gsub(":", "_")
|
||||
local def = minetest.registered_nodes[pot_name]
|
||||
if not def then
|
||||
return itemstack
|
||||
end
|
||||
minetest.sound_play(def.sounds.place, {pos = pos})
|
||||
minetest.swap_node(pos, {name = name})
|
||||
minetest.swap_node(pos, {name = pot_name})
|
||||
if not minetest.settings:get_bool("creative_mode") then
|
||||
itemstack:take_item()
|
||||
end
|
||||
@ -52,12 +54,33 @@ local function get_tile(def)
|
||||
return tile
|
||||
end
|
||||
|
||||
local old_get_node_drops = minetest.get_node_drops
|
||||
|
||||
function minetest.get_node_drops(node, toolname)
|
||||
local node_name
|
||||
if type(node) == "table" then
|
||||
node_name = node.name
|
||||
|
||||
elseif type(node) == "string" then
|
||||
node_name = node
|
||||
end
|
||||
|
||||
if node_name then
|
||||
local flower_item = flower_items_by_pot[node_name]
|
||||
if flower_item then
|
||||
return old_get_node_drops(flower_item, toolname)
|
||||
end
|
||||
end
|
||||
|
||||
return old_get_node_drops(node, toolname)
|
||||
end
|
||||
|
||||
function flowerpot.register_node(nodename)
|
||||
assert(nodename, "no nodename passed")
|
||||
local nodedef = minetest.registered_nodes[nodename]
|
||||
|
||||
if not nodedef then
|
||||
minetest.log("error", S("@1 is not a known node, unable to register flowerpot", nodename))
|
||||
return false
|
||||
error(f("%s is not a known node, unable to register flowerpot", nodename))
|
||||
end
|
||||
|
||||
local desc = nodedef.description
|
||||
@ -78,7 +101,7 @@ function flowerpot.register_node(nodename)
|
||||
}
|
||||
end
|
||||
|
||||
local dropname = nodename:gsub("grass_%d", "grass_1")
|
||||
flower_items_by_pot["flowerpot:" .. name] = nodename
|
||||
|
||||
minetest.register_node(":flowerpot:" .. name, {
|
||||
description = S("Flowerpot with @1", desc),
|
||||
@ -99,20 +122,10 @@ function flowerpot.register_node(nodename)
|
||||
sounds = default.node_sound_defaults(),
|
||||
groups = {attached_node = 1, oddly_breakable_by_hand = 1, snappy = 3, not_in_creative_inventory = 1},
|
||||
flowerpot_plantname = nodename,
|
||||
on_dig = function(pos, node, digger)
|
||||
minetest.set_node(pos, {name = "flowerpot:empty"})
|
||||
local def = minetest.registered_nodes[node.name]
|
||||
minetest.add_item(pos, dropname)
|
||||
node_dig_prediction = "flowerpot:empty",
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
minetest.swap_node(pos, {name = "flowerpot:empty"})
|
||||
end,
|
||||
drop = {
|
||||
max_items = 2,
|
||||
items = {
|
||||
{
|
||||
items = {"flowerpot:empty", dropname},
|
||||
rarity = 1,
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user