forked from mtcontrib/maidroid
Fix nametag
Set default value from existing data. Change item decrement timing. Use is_maidroid() method.
This commit is contained in:
parent
cb5305573d
commit
0525e26809
@ -8,7 +8,7 @@ local formspec = "size[4,1.25]"
|
|||||||
.. default.gui_bg_img
|
.. default.gui_bg_img
|
||||||
.. default.gui_slots
|
.. default.gui_slots
|
||||||
.. "button_exit[3,0.25;1,0.875;apply_name;Apply]"
|
.. "button_exit[3,0.25;1,0.875;apply_name;Apply]"
|
||||||
.. "field[0.5,0.5;2.75,1;name;name;]"
|
.. "field[0.5,0.5;2.75,1;name;name;%s]"
|
||||||
|
|
||||||
local maidroid_buf = {} -- for buffer of target maidroids.
|
local maidroid_buf = {} -- for buffer of target maidroids.
|
||||||
|
|
||||||
@ -28,14 +28,15 @@ minetest.register_craftitem("maidroid_tool:nametag", {
|
|||||||
if not obj:is_player() and luaentity then
|
if not obj:is_player() and luaentity then
|
||||||
local name = luaentity.name
|
local name = luaentity.name
|
||||||
|
|
||||||
if maidroid.registered_maidroids[name] then
|
if maidroid.is_maidroid(name) then
|
||||||
local player_name = user:get_player_name()
|
local player_name = user:get_player_name()
|
||||||
|
local nametag = luaentity.nametag or ""
|
||||||
|
|
||||||
minetest.show_formspec(player_name, "maidroid_tool:nametag", formspec)
|
minetest.show_formspec(player_name, "maidroid_tool:nametag", formspec:format(nametag))
|
||||||
maidroid_buf[player_name] = luaentity
|
maidroid_buf[player_name] = {
|
||||||
|
object = obj,
|
||||||
itemstack:take_item()
|
itemstack = itemstack
|
||||||
return itemstack
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return nil
|
return nil
|
||||||
@ -47,12 +48,21 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local player_name = player:get_player_name()
|
||||||
if fields.name then
|
if fields.name then
|
||||||
local luaentity = maidroid_buf[player:get_player_name()]
|
local luaentity = maidroid_buf[player_name].object:get_luaentity()
|
||||||
|
if luaentity then
|
||||||
luaentity.nametag = fields.name
|
luaentity.nametag = fields.name
|
||||||
|
|
||||||
luaentity.object:set_properties{
|
luaentity.object:set_properties{
|
||||||
nametag = fields.name,
|
nametag = fields.name,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local itemstack = maidroid_buf[player_name].itemstack
|
||||||
|
itemstack:take_item()
|
||||||
|
player:set_wielded_item(itemstack)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
maidroid_buf[player_name] = nil
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user