Fixed various right-click-place issues, stub for new wood tools.

This commit is contained in:
Aaron Suen 2019-01-04 20:11:04 -05:00
parent 614a96b1cc
commit 3b0d6b4b57
4 changed files with 42 additions and 24 deletions

View File

@ -22,11 +22,15 @@ end
local node_is_skip = {name = true, param2 = true, param = true, groups = true}
function nodecore.node_is(node_or_pos, match)
if not node_or_pos.name then node_or_pos = minetest.get_node(node_or_pos) end
if not node_or_pos.name then
for k, v in pairs(minetest.get_node(node_or_pos)) do
node_or_pos[k] = v
end
end
while type(match) == "function" do
match = match(node_or_pos)
if not match then return end
if match == true then return true end
if match == true then return node_or_pos end
end
if type(match) == "string" then match = {name = match} end
if match.name and node_or_pos.name ~= match.name then return end
@ -48,7 +52,7 @@ function nodecore.node_is(node_or_pos, match)
if def[k] ~= v then return end
end
end
return true
return node_or_pos
end
function nodecore.buildable_to(node_or_pos)
return nodecore.node_is(node_or_pos, {buildable_to = true})

View File

@ -66,20 +66,17 @@ function nodecore.place_stack(pos, stack, placer, pointed_thing)
minetest.check_for_falling(pos)
end
local function buildable_to(pos)
return minetest.registered_nodes[minetest.get_node(pos).name].buildable_to and pos
end
local bii = minetest.registered_entities["__builtin:item"]
local item = {
on_step = function(self, dtime)
bii.on_step(self, dtime)
if self.physical_state then return end
local pos = vector.round(self.object:getpos())
pos = buildable_to(pos)
or buildable_to({x = pos.x + 1, y = pos.y, z = pos.z})
or buildable_to({x = pos.x - 1, y = pos.y, z = pos.z})
or buildable_to({x = pos.x, y = pos.y, z = pos.z + 1})
or buildable_to({x = pos.x, y = pos.y, z = pos.z - 1})
pos = nodecore.buildable_to(pos)
or nodecore.buildable_to({x = pos.x + 1, y = pos.y, z = pos.z})
or nodecore.buildable_to({x = pos.x - 1, y = pos.y, z = pos.z})
or nodecore.buildable_to({x = pos.x, y = pos.y, z = pos.z + 1})
or nodecore.buildable_to({x = pos.x, y = pos.y, z = pos.z - 1})
if not pos then return end
nodecore.place_stack(pos, self.itemstring)
self.itemstring = ""
@ -121,8 +118,10 @@ function minetest.item_place(itemstack, placer, pointed_thing, param2)
return minetest.item_place_node(itemstack, placer, pointed_thing, param2)
end
if not itemstack:is_empty() then
nodecore.place_stack(minetest.get_pointed_thing_position(pointed_thing, true),
itemstack:take_item(), placer, pointed_thing)
local above = minetest.get_pointed_thing_position(pointed_thing, true)
if above and nodecore.buildable_to(above) then
nodecore.place_stack(above, itemstack:take_item(), placer, pointed_thing)
end
end
return itemstack
end

View File

@ -1,6 +1,6 @@
-- LUALOCALS < ---------------------------------------------------------
local ipairs, minetest, pairs
= ipairs, minetest, pairs
= ipairs, minetest, pairs
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
@ -61,6 +61,9 @@ regterrain({
"stair_desert_stone",
"mossycobble"
},
groups = {
cracky = 3
},
})
for _, v in ipairs({

View File

@ -5,25 +5,37 @@ local ItemStack, minetest, nodecore
local modname = minetest.get_current_modname()
local function toolhead(name, from, sticks)
local function toolhead(name, from, group, sticks)
local n
if name then
n = modname .. ":toolhead_" .. name:lower()
local t = n:gsub(":", "_") .. ".png"
minetest.register_craftitem(n, {
description = "Plank " .. name .. " Head",
description = "Wooden " .. name .. " Head",
inventory_image = t,
stack_max = 1
})
--[[
local m = modname .. ":tool_" .. name:lower()
local u = m:gsub(":", "_") .. ".png"
minetest.register_tool(m, {
description = "Wooden " .. name,
inventory_image = u,
tool_capabilities = {
groupcaps={
[group] = {times={[1]=4.00, [2]=1.60, [3]=0.80}, uses=20},
},
},
})
nodecore.register_craft({
normal = {y = 1},
nodes = {
{match = n, replace = "air"},
{y = -1, match = modname .. ":staff", replace = error("TOOLDEF")}
{y = -1, match = modname .. ":staff", replace = "air"},
},
items = {
{y = -1, name = m},
}
})
--]]
end
nodecore.extend_pummel(from,
function(pos, node, stats)
@ -41,8 +53,8 @@ local function toolhead(name, from, sticks)
end)
end
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)
toolhead("Mallet", modname .. ":plank", "poundy", 2)
toolhead("Spade", modname .. ":toolhead_mallet", "crumbly", 1)
toolhead("Axe", modname .. ":toolhead_spade", "choppy", 1)
toolhead("Pick", modname .. ":toolhead_axe", "cracky", 2)
toolhead(nil, modname.. ":toolhead_pick", nil, 2)