cleanup / wip

This commit is contained in:
BuckarooBanzay 2023-06-21 16:54:58 +02:00
parent 3e95d5830e
commit d998058bcd
4 changed files with 30 additions and 46 deletions

View File

@ -7,5 +7,4 @@ dofile(MP .. "/serialize.lua")
dofile(MP .. "/entity.lua")
dofile(MP .. "/node.lua")
dofile(MP .. "/tool.lua")
dofile(MP .. "/wield_check.lua")
dofile(MP .. "/preview.lua")

View File

@ -1,3 +1,25 @@
-- TODO: pickup node with WE marker selection formspec
-- TODO: dispense "pick_and_place:placer" tool with schematic, size and id
minetest.register_node("pick_and_place:handle", {
description = "Pick and place handle",
tiles = {"pick_and_place_plus.png"},
drawtype = "allfaces",
use_texture_alpha = "blend",
paramtype = "light",
sunlight_propagates = true,
groups = {
oddly_breakable_by_hand = 3
}
})
minetest.register_node("pick_and_place:handle_configured", {
description = "Pick and place handle (configured)",
tiles = {"pick_and_place_plus.png^[colorize:#00ff00"},
drawtype = "allfaces",
use_texture_alpha = "blend",
paramtype = "light",
sunlight_propagates = true,
groups = {
oddly_breakable_by_hand = 3,
not_in_creative_inventory = 1
}
})

View File

@ -6,10 +6,10 @@ minetest.register_tool("pick_and_place:placer", {
range = 0,
on_use = function(itemstack, player)
end,
on_focus = function(itemstack, player)
end,
on_step = function(itemstack, player)
end,
on_blur = function(player)
end
})
function pick_and_place.on_step()
end
function pick_and_place.on_blur()
end

View File

@ -1,37 +0,0 @@
-- playername -> name
local last_wielded_item = {}
-- check for tools
local function wield_check()
for _, player in ipairs(minetest.get_connected_players()) do
local itemstack = player:get_wielded_item()
local playername = player:get_player_name()
local id, name
if itemstack then
name = itemstack:get_name()
local meta = itemstack:get_meta()
id = meta:get_int("id")
end
local is_placer = name == "pick_and_place:placer"
if last_wielded_item[playername] and name ~= last_wielded_item[playername] then
-- last item got out of focus
local item_def = minetest.registered_items[last_wielded_item[playername]]
if item_def and type(item_def.on_blur) == "function" then
item_def.on_blur(player)
end
end
if is_placer then
pick_and_place.on_step(itemstack, player)
end
last_wielded_item[playername] = name
end
minetest.after(0, wield_check)
end
minetest.after(0, wield_check)
minetest.register_on_leaveplayer(function(player)
last_wielded_item[player:get_player_name()] = nil
end)