From cf8d9fb2465e4906d2a143b12a4fb6a4b5f6a77b Mon Sep 17 00:00:00 2001 From: tacigar Date: Wed, 21 Dec 2016 15:57:33 +0900 Subject: [PATCH 1/7] Delete nametag system --- maidroid/api.lua | 29 ----------------------------- 1 file changed, 29 deletions(-) diff --git a/maidroid/api.lua b/maidroid/api.lua index c0f088e..ea1faab 100644 --- a/maidroid/api.lua +++ b/maidroid/api.lua @@ -179,32 +179,6 @@ maidroid.manufacturing_data = (function() return {} end) () --- formspec_opened_selves represents a table that contains player names and --- maidroids whose formspec is opened. -local formspec_opened_maidroids = {} - -minetest.register_on_player_receive_fields(function(player, formname, fields) - if formname ~= "maidroid:gui" then - return - end - - local self = formspec_opened_maidroids[player] - if not self then -- if the maidroid is dead now. - return - end - - if fields.name then - if fields.name == "" then - self.nametag = self.inventory_name - else - self.nametag = fields.name - end - self.object:set_nametag_attributes{ - text = self.nametag - } - end -end) - -------------------------------------------------------------------- -- register empty item entity definition. @@ -372,7 +346,6 @@ function maidroid.register_maidroid(product_name, def) -- create_formspec_string returns a string that represents a formspec definition. local function create_formspec_string(self) - local nametag = self.object:get_nametag_attributes().text return "size[8,9]" .. default.gui_bg .. default.gui_bg_img @@ -383,7 +356,6 @@ function maidroid.register_maidroid(product_name, def) .. "list[current_player;main;0,5;8,1;]" .. "list[current_player;main;0,6.2;8,3;8]" .. "button[7,0.25;1,0.875;apply_name;Apply]" - .. "field[4.5,0.5;2.75,1;name;name;" .. nametag .. "]" .. "label[5.5,1;wield]" .. "list[detached:"..self.inventory_name..";wield_item;5.5,1.5;1,1;]" end @@ -396,7 +368,6 @@ function maidroid.register_maidroid(product_name, def) self.manufacturing_number = maidroid.manufacturing_data[product_name] maidroid.manufacturing_data[product_name] = maidroid.manufacturing_data[product_name] + 1 create_inventory(self) - self.nametag = self.inventory_name -- attach dummy item to new maidroid. minetest.add_entity(self.object:getpos(), "maidroid:dummy_item") From 57192805af424c38db4d631d1222bf01f0223633 Mon Sep 17 00:00:00 2001 From: tacigar Date: Wed, 21 Dec 2016 16:31:45 +0900 Subject: [PATCH 2/7] Add is_named method --- maidroid/api.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/maidroid/api.lua b/maidroid/api.lua index ea1faab..2fd7fb5 100644 --- a/maidroid/api.lua +++ b/maidroid/api.lua @@ -156,6 +156,11 @@ function maidroid.maidroid.move_main_to_wield(self, itemname) return false end +-- maidroid.maidroid.is_named reports the maidroid is still named. +function maidroid.maidroid.is_named(self) + return self.nametag ~= "" +end + --------------------------------------------------------------------- -- maidroid.manufacturing_data represents a table that contains manufacturing data. @@ -542,6 +547,7 @@ function maidroid.register_maidroid(product_name, def) set_yaw_by_direction = maidroid.maidroid.set_yaw_by_direction, get_wield_item_stack = maidroid.maidroid.get_wield_item_stack, move_main_to_wield = maidroid.maidroid.move_main_to_wield, + is_named = maidroid.maidroid.is_named, }) -- register maidroid egg. From 5f64a877e87440cb8c9162020b7c5adcc753c724 Mon Sep 17 00:00:00 2001 From: tacigar Date: Wed, 21 Dec 2016 16:47:31 +0900 Subject: [PATCH 3/7] fix maidroid/api --- maidroid/api.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/maidroid/api.lua b/maidroid/api.lua index 2fd7fb5..d2bf535 100644 --- a/maidroid/api.lua +++ b/maidroid/api.lua @@ -360,7 +360,6 @@ function maidroid.register_maidroid(product_name, def) .. "list[detached:"..self.inventory_name..";core;4.5,1.5;1,1;]" .. "list[current_player;main;0,5;8,1;]" .. "list[current_player;main;0,6.2;8,3;8]" - .. "button[7,0.25;1,0.875;apply_name;Apply]" .. "label[5.5,1;wield]" .. "list[detached:"..self.inventory_name..";wield_item;5.5,1.5;1,1;]" end @@ -479,7 +478,6 @@ function maidroid.register_maidroid(product_name, def) -- on_rightclick is a callback function that is called when a player right-click them. local function on_rightclick(self, clicker) - formspec_opened_maidroids[clicker] = self minetest.show_formspec( clicker:get_player_name(), "maidroid:gui", From dbaa1c5ad20715bc85f995e7f06ceaed8957e52e Mon Sep 17 00:00:00 2001 From: tacigar Date: Wed, 21 Dec 2016 16:47:43 +0900 Subject: [PATCH 4/7] Add Nametag --- maidroid_tool/init.lua | 1 + maidroid_tool/nametag.lua | 58 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 maidroid_tool/nametag.lua diff --git a/maidroid_tool/init.lua b/maidroid_tool/init.lua index a7ae94e..55daad7 100644 --- a/maidroid_tool/init.lua +++ b/maidroid_tool/init.lua @@ -12,3 +12,4 @@ dofile(maidroid_tool.modpath .. "/api.lua") dofile(maidroid_tool.modpath .. "/core_writer.lua") dofile(maidroid_tool.modpath .. "/egg_writer.lua") dofile(maidroid_tool.modpath .. "/crafting.lua") +dofile(maidroid_tool.modpath .. "/nametag.lua") diff --git a/maidroid_tool/nametag.lua b/maidroid_tool/nametag.lua new file mode 100644 index 0000000..a62baed --- /dev/null +++ b/maidroid_tool/nametag.lua @@ -0,0 +1,58 @@ +------------------------------------------------------------ +-- Copyright (c) 2016 tacigar. All rights reserved. +-- https://github.com/tacigar/maidroid +------------------------------------------------------------ + +local formspec = "size[4,1.25]" + .. default.gui_bg + .. default.gui_bg_img + .. default.gui_slots + .. "button_exit[3,0.25;1,0.875;apply_name;Apply]" + .. "field[0.5,0.5;2.75,1;name;name;]" + +local maidroid_buf = {} -- for buffer of target maidroids. + +minetest.register_craftitem("maidroid_tool:nametag", { + description = "maidroid tool : nametag", + inventory_image = "maidroid_tool_nametag.png", + stack_max = 1, + + on_use = function(itemstack, user, pointed_thing) + if pointed_thing.type ~= "object" then + return nil + end + + local obj = pointed_thing.ref + local luaentity = obj:get_luaentity() + + if not obj:is_player() and luaentity then + local name = luaentity.name + print(name) + print(luaentity:is_named()) + + if maidroid.registered_maidroids[name] and not luaentity:is_named() then + local player_name = user:get_player_name() + + minetest.show_formspec(player_name, "maidroid_tool:nametag", formspec) + maidroid_buf[player_name] = luaentity + return itemstack + end + end + return nil + end, +}) + +minetest.register_on_player_receive_fields(function(player, formname, fields) + if formname ~= "maidroid_tool:nametag" then + return + end + + if fields.name then + local luaentity = maidroid_buf[player:get_player_name()] + luaentity.nametag = fields.name + + luaentity.object:set_nametag_attributes{ + text = fields.name, + } + end +end) From f081e55ba035e24fe846b3399a5a3f5361505d0c Mon Sep 17 00:00:00 2001 From: tacigar Date: Wed, 21 Dec 2016 16:49:10 +0900 Subject: [PATCH 5/7] Delete lines --- maidroid_tool/nametag.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/maidroid_tool/nametag.lua b/maidroid_tool/nametag.lua index a62baed..b9e9c0a 100644 --- a/maidroid_tool/nametag.lua +++ b/maidroid_tool/nametag.lua @@ -27,8 +27,6 @@ minetest.register_craftitem("maidroid_tool:nametag", { if not obj:is_player() and luaentity then local name = luaentity.name - print(name) - print(luaentity:is_named()) if maidroid.registered_maidroids[name] and not luaentity:is_named() then local player_name = user:get_player_name() From d01cc4f61ef6ae82019c99f35c4aed55275d1b04 Mon Sep 17 00:00:00 2001 From: tacigar Date: Wed, 21 Dec 2016 16:54:52 +0900 Subject: [PATCH 6/7] Add nametag recipe --- maidroid_tool/crafting.lua | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/maidroid_tool/crafting.lua b/maidroid_tool/crafting.lua index 9463329..482e188 100644 --- a/maidroid_tool/crafting.lua +++ b/maidroid_tool/crafting.lua @@ -20,3 +20,12 @@ minetest.register_craft{ {"default:steel_ingot", "default:cobble", "default:steel_ingot"}, }, } + +minetest.register_craft{ + output = "maidroid_tool:nametag", + recipe = { + { "", "farming:cotton", ""}, + { "default:paper", "default:paper", "default:paper"}, + {"default:steel_ingot", "dye:black", "default:steel_ingot"}, + }, +} From a63d9c1aeee12541c4a4b089809db116075e503e Mon Sep 17 00:00:00 2001 From: tacigar Date: Wed, 21 Dec 2016 17:15:57 +0900 Subject: [PATCH 7/7] Add nametag img --- maidroid_tool/textures/maidroid_tool_nametag.png | Bin 0 -> 419 bytes maidroid_tool/textures/maidroid_tool_nametag.xcf | Bin 0 -> 1325 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 maidroid_tool/textures/maidroid_tool_nametag.png create mode 100644 maidroid_tool/textures/maidroid_tool_nametag.xcf diff --git a/maidroid_tool/textures/maidroid_tool_nametag.png b/maidroid_tool/textures/maidroid_tool_nametag.png new file mode 100644 index 0000000000000000000000000000000000000000..ee91113ac42a52e5bc990eb1e17f8a6634a841bc GIT binary patch literal 419 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmPNk0=Kp>x|f9bD)rHW=KSdbAE1aYF-JD%fR4Vl$uzQ znxasiS(2gP?&%wlqL<3fz`)4v>Eak-aeC_Hjb4WXMB4TXTa~R<*l}g!g&w;`3y-7E z3r-7hiQU(b z?K|LGwot?G#HXgW?+*OE+Zz*O|A&)j&%a+AroLXV^6eppMXN$mZwZvN?v<5L=$h=e zL48I3cJ7?{3?Ke|TNFOMHvjhW2W*YQWq@CE?)q$ zy!E$uiIAnNC=!As!@1)zO+^^#j?cO0jAxELz8YLOmz|!|Q+UEv>YI^RRzJBwTl|y4y zgSPLr{ITkC4{kxt$#mBDoXM!Kx<`#>&+m--qp{O8kJi{fYdgp8u^BtSiItA9^lZn{ zLU;ZTcSo?n|RZ|2jtcNw(`#1rTiW2 z5T6T#XYqgdi`KqF zh%h0ar0<{sV9o{oW;qZ6YzaGvb*4dUYTrg@Z<5n;-sfGWV8BMQq( zs2i+d2eHmnrO`Dvz(p#QNSDk>r;&oDQX_K|G$iB|%N)gQU^z#@i>=#4xsGJChSfy5 z-lV&t#J5r6Fw|ij=TTxtgei{#>H_8*QCN0`dxJIXAl8|>aX9A&xQK--;w5v^ap*#G zV=#4nTIl5!)l_;H?fWK96za!|08Il(W>Y*_O4J(SE;Tm Yw1>;qz#Yr03|>LM3cU_5-_2+A2Lea3y#N3J literal 0 HcmV?d00001