Door crafting hints and witnessing

This commit is contained in:
Aaron Suen 2020-09-11 01:08:20 -04:00
parent ce4a77ab79
commit de87702497
5 changed files with 62 additions and 41 deletions

View File

@ -125,13 +125,14 @@ local function craftcheck(recipe, pos, node, data, xx, xz, zx, zz)
if recipe.after then recipe.after(pos, data) end
if data.after then data.after(pos, data) end
nodecore.player_discover(data.crafter, "craft:" .. recipe.label)
if recipe.witness then
local witness = data.witness or recipe.witness
if witness then
local lut = {}
for _, v in pairs(recipe.nodes) do
lut[minetest.hash_node_position(v)] = true
end
nodecore.witness(pos, {recipe.action, recipe.label},
type(recipe.witness) == "number" and recipe.witness or nil,
nodecore.witness(pos, {recipe.action, recipe.label, data.label},
type(witness) == "number" and witness or nil,
function(p) return lut[minetest.hash_node_position(p)] end
)
end

View File

@ -8,11 +8,11 @@ function minetest.item_place_node(itemstack, placer, pointed_thing, ...)
local old_add = minetest.add_node
minetest.add_node = function(pos, node, ...)
local function helper2(...)
nodecore.craft_check(pos, node, {
action = "place",
crafter = placer,
pointed = pointed_thing
})
nodecore.craft_check(pos, node, nodecore.underride({
action = "place",
crafter = placer,
pointed = pointed_thing
}, pointed_thing.craftdata or {}))
return ...
end
return helper2(old_add(pos, node, ...))

View File

@ -1,8 +1,8 @@
-- LUALOCALS < ---------------------------------------------------------
local math, minetest, nodecore, pairs, type, vector
= math, minetest, nodecore, pairs, type, vector
local math_pi
= math.pi
local math, minetest, nodecore, pairs, string, type, vector
= math, minetest, nodecore, pairs, string, type, vector
local math_pi, string_format, string_gsub
= math.pi, string.format, string.gsub
-- LUALOCALS > ---------------------------------------------------------
local function playercheck(player, pos, maxdist, check)
@ -35,10 +35,16 @@ local function playercheck(player, pos, maxdist, check)
end
function nodecore.witness(pos, label, maxdist, check)
maxdist = maxdist or 16
nodecore.log("action", string_format("witness %s at %s range %d",
string_gsub(minetest.serialize(label), "^return ", ""),
minetest.pos_to_string(pos), maxdist))
for _, player in pairs(minetest.get_connected_players()) do
if playercheck(player, pos, maxdist or 32, check) then
if playercheck(player, pos, maxdist, check) then
for _, l in pairs(type(label) == "table" and label or {label}) do
nodecore.player_discover(player, "witness:" .. l)
if l then
nodecore.player_discover(player, "witness:" .. l)
end
end
end
end

View File

@ -37,3 +37,13 @@ nodecore.register_hint("propel hinged panel with focused light",
"door ablation",
{"nc_optics:lens_on", "group:door"}
)
nodecore.register_hint("place a node with a door",
"witness:door placement",
"group:door"
)
nodecore.register_hint("complete a craft with a door",
"witness:door place-craft",
"group:door"
)

View File

@ -69,6 +69,7 @@ local function pressify(rc)
nr.action = "press"
nr.toolgroups = nil
nr.witness = 16
local oldcheck = nr.check
nr.check = function(pos, data)
@ -102,6 +103,28 @@ nodecore.register_craft = function(def, ...)
return helper(oldreg(def, ...))
end
nodecore.register_craft({
action = "press",
label = "press node craft",
priority = -1,
nodes = {{match = {groups = {stack_as_node = true}}}},
check = function(pos, data)
if not backstop(pos, vector.subtract(data.pointed.under,
data.pointed.above), 4) then return end
return true
end,
after = function(pos, data)
return nodecore.craft_check(pos,
minetest.get_node(pos),
{
action = "place",
pointed = data.pointed,
witness = 16,
label = "door place-craft"
})
end
})
local checkedstack = {}
nodecore.register_craft({
action = "press",
@ -126,36 +149,17 @@ nodecore.register_craft({
local stack = data[checkedstack]
if not stack then return end
minetest.remove_node(pos)
stack = minetest.item_place_node(stack, nil, data.pointed)
nodecore.witness(pos, "door placement")
local pt = {}
for k, v in pairs(data.pointed) do pt[k] = v end
pt.craftdata = {
witness = 16,
label = "door place-craft"
}
stack = minetest.item_place_node(stack, nil, pt)
nodecore.node_sound(pos, "place")
if not stack:is_empty() then
nodecore.item_eject(pos, stack)
end
return nodecore.craft_check(pos,
minetest.get_node(pos),
{
action = "place",
pointed = data.pointed
})
end
})
nodecore.register_craft({
action = "press",
label = "press node craft",
priority = -1,
nodes = {{match = {groups = {stack_as_node = true}}}},
check = function(pos, data)
if not backstop(pos, vector.subtract(data.pointed.under,
data.pointed.above), 4) then return end
return true
end,
after = function(pos, data)
return nodecore.craft_check(pos,
minetest.get_node(pos),
{
action = "place",
pointed = data.pointed
})
end
})