use wield_events
mod
This commit is contained in:
parent
a3cb98fa01
commit
60a6ec7caa
@ -124,7 +124,7 @@ minetest.register_tool("building_lib:autoplace", {
|
|||||||
rotation
|
rotation
|
||||||
)
|
)
|
||||||
end,
|
end,
|
||||||
on_blur = function(player)
|
on_deselect = function(player)
|
||||||
local playername = player:get_player_name()
|
local playername = player:get_player_name()
|
||||||
building_lib.clear_preview(playername)
|
building_lib.clear_preview(playername)
|
||||||
end
|
end
|
||||||
|
@ -151,7 +151,7 @@ minetest.register_tool("building_lib:place", {
|
|||||||
rotation
|
rotation
|
||||||
)
|
)
|
||||||
end,
|
end,
|
||||||
on_blur = function(player)
|
on_deselect = function(player)
|
||||||
local playername = player:get_player_name()
|
local playername = player:get_player_name()
|
||||||
building_lib.clear_preview(playername)
|
building_lib.clear_preview(playername)
|
||||||
end
|
end
|
||||||
|
1
init.lua
1
init.lua
@ -12,7 +12,6 @@ dofile(MP .. "/memoize.lua")
|
|||||||
dofile(MP .. "/entity.lua")
|
dofile(MP .. "/entity.lua")
|
||||||
dofile(MP .. "/preview.lua")
|
dofile(MP .. "/preview.lua")
|
||||||
dofile(MP .. "/api.lua")
|
dofile(MP .. "/api.lua")
|
||||||
dofile(MP .. "/wield_events.lua")
|
|
||||||
dofile(MP .. "/common.lua")
|
dofile(MP .. "/common.lua")
|
||||||
dofile(MP .. "/placements/mapblock_lib.lua")
|
dofile(MP .. "/placements/mapblock_lib.lua")
|
||||||
dofile(MP .. "/placements/dummy.lua")
|
dofile(MP .. "/placements/dummy.lua")
|
||||||
|
2
mod.conf
2
mod.conf
@ -1,4 +1,4 @@
|
|||||||
name = building_lib
|
name = building_lib
|
||||||
description = Mapblock granular building placement and tools
|
description = Mapblock granular building placement and tools
|
||||||
depends = mapblock_lib, promise
|
depends = mapblock_lib, promise, wield_events
|
||||||
optional_depends = mtt
|
optional_depends = mtt
|
@ -42,7 +42,7 @@ minetest.register_tool("building_lib:remove", {
|
|||||||
building_info.rotation
|
building_info.rotation
|
||||||
)
|
)
|
||||||
end,
|
end,
|
||||||
on_blur = function(player)
|
on_deselect = function(player)
|
||||||
local playername = player:get_player_name()
|
local playername = player:get_player_name()
|
||||||
building_lib.clear_preview(playername)
|
building_lib.clear_preview(playername)
|
||||||
end
|
end
|
||||||
|
@ -1,34 +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 name = itemstack and itemstack:get_name()
|
|
||||||
-- TODO: check player:get_wield_index() to differenciate same-named items
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
local item_def = minetest.registered_items[name]
|
|
||||||
if item_def and type(item_def.on_step) == "function" then
|
|
||||||
item_def.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)
|
|
Loading…
x
Reference in New Issue
Block a user