Clean up toolheads, refac pummel extension.
@ -1,6 +1,6 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local minetest, nodecore, vector
|
||||
= minetest, nodecore, vector
|
||||
= minetest, nodecore, vector
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local pummeling = {}
|
||||
@ -81,3 +81,21 @@ minetest.register_on_punchnode(function(pos, node, puncher, pointed)
|
||||
pummeling[pname] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
function nodecore.add_pummel(nodedef, check, commit)
|
||||
local sym = {}
|
||||
local oc = nodedef.can_pummel or function() end
|
||||
nodedef.can_pummel = function(...)
|
||||
return check(...) and sym or oc(...)
|
||||
end
|
||||
local op = nodedef.on_pummel or function() end
|
||||
nodedef.on_pummel = function(pos, node, stats, ...)
|
||||
return stats.check == sym and commit(pos, node, stats, ...)
|
||||
or op(pos, node, stats, ...)
|
||||
end
|
||||
end
|
||||
function nodecore.extend_pummel(name, check, commit)
|
||||
nodecore.extend_node(name, function(copy)
|
||||
return nodecore.add_pummel(copy, check, commit)
|
||||
end)
|
||||
end
|
||||
|
@ -1,6 +1,6 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local ItemStack, ipairs, minetest, nodecore
|
||||
= ItemStack, ipairs, minetest, nodecore
|
||||
= ItemStack, ipairs, minetest, nodecore
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
@ -14,37 +14,29 @@ minetest.register_node(plank, {
|
||||
}
|
||||
})
|
||||
|
||||
nodecore.extend_node("nc_tree:tree", function(copy, orig)
|
||||
local oc = orig.can_pummel or function() end
|
||||
copy.can_pummel = function(pos, node, stats, ...)
|
||||
if (stats.pointed.above.y - stats.pointed.under.y) == 1
|
||||
and nodecore.wieldgroup(stats.puncher, "choppy") then
|
||||
return plank
|
||||
nodecore.extend_pummel("nc_tree:tree",
|
||||
function(pos, node, stats)
|
||||
return (stats.pointed.above.y - stats.pointed.under.y) == 1
|
||||
and nodecore.wieldgroup(stats.puncher, "choppy")
|
||||
end,
|
||||
function(pos, node, stats)
|
||||
if stats.duration < 5 then return end
|
||||
minetest.remove_node(pos)
|
||||
local defer = 0
|
||||
for _, v in ipairs({
|
||||
{x = pos.x + 1, y = pos.y, z = pos.z},
|
||||
{x = pos.x - 1, y = pos.y, z = pos.z},
|
||||
{x = pos.x, y = pos.y, z = pos.z + 1},
|
||||
{x = pos.x, y = pos.y, z = pos.z - 1}
|
||||
}) do
|
||||
if nodecore.buildable_to(v) then
|
||||
minetest.item_drop(ItemStack(plank), nil, v)
|
||||
else
|
||||
defer = defer + 1
|
||||
end
|
||||
return oc(pos, node, stats)
|
||||
end
|
||||
local op = orig.on_pummel or function() end
|
||||
copy.on_pummel = function(pos, node, stats, ...)
|
||||
if stats.check ~= plank or stats.duration < 5 then
|
||||
return op(pos, node, stats, ...)
|
||||
end
|
||||
minetest.remove_node(pos)
|
||||
local defer = 0
|
||||
for _, v in ipairs({
|
||||
{x = pos.x + 1, y = pos.y, z = pos.z},
|
||||
{x = pos.x - 1, y = pos.y, z = pos.z},
|
||||
{x = pos.x, y = pos.y, z = pos.z + 1},
|
||||
{x = pos.x, y = pos.y, z = pos.z - 1}
|
||||
}) do
|
||||
if nodecore.buildable_to(v) then
|
||||
minetest.item_drop(ItemStack(plank), nil, v)
|
||||
else
|
||||
defer = defer + 1
|
||||
end
|
||||
end
|
||||
if defer > 0 then
|
||||
minetest.item_drop(ItemStack(plank .. " " .. defer), nil, pos)
|
||||
end
|
||||
return true
|
||||
if defer > 0 then
|
||||
minetest.item_drop(ItemStack(plank .. " " .. defer), nil, pos)
|
||||
end
|
||||
return true
|
||||
end)
|
||||
|
Before Width: | Height: | Size: 608 B After Width: | Height: | Size: 514 B |
BIN
mods/nc_woodwork/textures/nc_woodwork_toolhead_mallet.png
Normal file
After Width: | Height: | Size: 643 B |
Before Width: | Height: | Size: 328 B After Width: | Height: | Size: 331 B |
Before Width: | Height: | Size: 296 B After Width: | Height: | Size: 652 B |
@ -1,41 +1,39 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local ItemStack, minetest, nodecore
|
||||
= ItemStack, minetest, nodecore
|
||||
= ItemStack, minetest, nodecore
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
|
||||
local function toolhead(name, from, sticks)
|
||||
local n = modname .. ":toolhead_" .. name:lower()
|
||||
local t = n:gsub(":", "_") .. ".png"
|
||||
minetest.register_craftitem(n, {
|
||||
description = "Plank " .. name .. " Head",
|
||||
inventory_image = t
|
||||
})
|
||||
nodecore.extend_item(from, function(copy, orig)
|
||||
local oc = orig.can_pummel or function() end
|
||||
copy.can_pummel = function(pos, node, stats, ...)
|
||||
if nodecore.wieldgroup(stats.puncher, "choppy") then
|
||||
return n
|
||||
end
|
||||
return oc(pos, node, stats)
|
||||
end
|
||||
local op = orig.on_pummel or function() end
|
||||
copy.on_pummel = function(pos, node, stats, ...)
|
||||
if stats.check ~= n or stats.duration < 5 then
|
||||
return op(pos, node, stats, ...)
|
||||
end
|
||||
minetest.remove_node(pos)
|
||||
minetest.item_drop(ItemStack(n), nil, pos)
|
||||
if sticks then
|
||||
minetest.item_drop(ItemStack("nc_tree:stick " .. sticks),
|
||||
nil, {x = pos.x, y = pos.y + 1, z = pos.z})
|
||||
end
|
||||
return true
|
||||
local n
|
||||
if name then
|
||||
local n = modname .. ":toolhead_" .. name:lower()
|
||||
local t = n:gsub(":", "_") .. ".png"
|
||||
minetest.register_craftitem(n, {
|
||||
description = "Plank " .. name .. " Head",
|
||||
inventory_image = t,
|
||||
stack_max = 1
|
||||
})
|
||||
end
|
||||
nodecore.extend_pummel(from,
|
||||
function(pos, node, stats)
|
||||
return nodecore.wieldgroup(stats.puncher, "choppy")
|
||||
end,
|
||||
function(pos, node, stats)
|
||||
if stats.duration < 5 then return end
|
||||
minetest.remove_node(pos)
|
||||
if n then minetest.item_drop(ItemStack(n), nil, pos) end
|
||||
if sticks then
|
||||
minetest.item_drop(ItemStack("nc_tree:stick " .. sticks),
|
||||
nil, {x = pos.x, y = pos.y + 1, z = pos.z})
|
||||
end
|
||||
return true
|
||||
end)
|
||||
end
|
||||
|
||||
toolhead("Spade", modname .. ":plank", 1)
|
||||
toolhead("Axe", modname .. ":toolhead_spade")
|
||||
toolhead("Mallet", modname .. ":plank", 2)
|
||||
toolhead("Spade", modname .. ":toolhead_mallet", 1)
|
||||
toolhead("Axe", modname .. ":toolhead_spade", 1)
|
||||
toolhead("Pick", modname .. ":toolhead_axe", 2)
|
||||
toolhead(nil, modname.. ":toolhead_pick", 2)
|