From fbf93ecf2d6c2be1fae147409380b3c4f552c625 Mon Sep 17 00:00:00 2001 From: tacigar Date: Sat, 7 Jan 2017 19:34:31 +0900 Subject: [PATCH 1/5] Add maidroid#get_front method --- maidroid/api.lua | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/maidroid/api.lua b/maidroid/api.lua index d4e0f8a..aab2c5e 100644 --- a/maidroid/api.lua +++ b/maidroid/api.lua @@ -95,8 +95,8 @@ function maidroid.maidroid.get_nearest_player(self, range_distance) return player end --- maidroid.maidroid.get_front_node returns a node that exists in front of the maidroid. -function maidroid.maidroid.get_front_node(self) +-- maidroid.maidroid.get_front returns a position in front of the maidroid. +function maidroid.maidroid.get_front(self) local direction = self:get_look_direction() if math.abs(direction.x) >= 0.5 then if direction.x > 0 then direction.x = 1 else direction.x = -1 end @@ -110,7 +110,12 @@ function maidroid.maidroid.get_front_node(self) direction.z = 0 end - local front = vector.add(vector.round(self.object:getpos()), direction) + return vector.add(vector.round(self.object:getpos()), direction) +end + +-- maidroid.maidroid.get_front_node returns a node that exists in front of the maidroid. +function maidroid.maidroid.get_front_node(self) + local front = self:get_front() return minetest.get_node(front) end @@ -624,6 +629,7 @@ function maidroid.register_maidroid(product_name, def) get_core = maidroid.maidroid.get_core, get_core_name = maidroid.maidroid.get_core_name, get_nearest_player = maidroid.maidroid.get_nearest_player, + get_front = maidroid.maidroid.get_front, get_front_node = maidroid.maidroid.get_front_node, get_look_direction = maidroid.maidroid.get_look_direction, set_animation = maidroid.maidroid.set_animation, From 11305efe5960f45fcc2c6ba107c69fd7e5aa987f Mon Sep 17 00:00:00 2001 From: tacigar Date: Sat, 7 Jan 2017 19:45:31 +0900 Subject: [PATCH 2/5] Add torcher core --- maidroid_core/cores/torcher.lua | 136 ++++++++++++++++++++++++++++++++ maidroid_core/init.lua | 1 + 2 files changed, 137 insertions(+) create mode 100644 maidroid_core/cores/torcher.lua diff --git a/maidroid_core/cores/torcher.lua b/maidroid_core/cores/torcher.lua new file mode 100644 index 0000000..9b84563 --- /dev/null +++ b/maidroid_core/cores/torcher.lua @@ -0,0 +1,136 @@ +------------------------------------------------------------ +-- Copyright (c) 2016 tacigar. All rights reserved. +-- https://github.com/tacigar/maidroid +------------------------------------------------------------ + +local state = {IDLE = 0, ACCOMPANY = 1} + +local PLACE_TIME = 4 + +local function on_start(self) + self.state = state.IDLE + self.object:setacceleration{x = 0, y = -10, z = 0} + self.object:setvelocity{x = 0, y = 0, z = 0} + self.time_counter = -1 + self.is_placing = false +end + +local function on_stop(self) + self.state = nil + self.object:setvelocity{x = 0, y = 0, z = 0} + self:set_animation(maidroid.animation_frames.STAND) + self.time_counter = nil + self.is_placing = nil +end + +local function is_dark(pos) + local light_level = minetest.get_node_light(pos) + return light_level <= 5 +end + +local function on_step(self, dtime) + if self.is_placing then + if self.time_counter >= PLACE_TIME then + self.time_counter = -1 + if self.state == state.IDLE then + self:set_animation(maidroid.animation_frames.STAND) + elseif self.state == state.ACCOMPANY then + self:set_animation(maidroid.animation_frames.WALK) + end + + local owner = minetest.get_player_by_name(self.owner_name) + local wield_stack = self:get_wield_item_stack() + local front = self:get_front() + + local pointed_thing = { + type = "node", + under = vector.add(front, {x = 0, y = -1, z = 0}), + above = front, + } + + if wield_stack:get_name() == "default:torch" then + local res_stack, success = minetest.item_place_node(wield_stack, owner, pointed_thing) + if success then + res_stack:take_item(1) + self:set_wield_item_stack(res_stack) + end + end + self.is_placing = false + else + self.time_counter = self.time_counter + 1 + end + end + + local player = self:get_nearest_player(10) + if player == nil then + self:set_animation(maidroid.animation_frames.STAND) + return + end + + local position = self.object:getpos() + local player_position = player:getpos() + local direction = vector.subtract(player_position, position) + local velocity = self.object:getvelocity() + + if vector.length(direction) < 3 then + if self.state == state.ACCOMPANY then + self:set_animation(maidroid.animation_frames.STAND) + self.state = state.IDLE + self.object:setvelocity{x = 0, y = velocity.y, z = 0} + end + + if not self.is_placing then + local front = self:get_front() -- if it is dark, set touch. + local wield_stack = self:get_wield_item_stack() + + if is_dark(front) + and (wield_stack:get_name() == "default:torch" + or self:move_main_to_wield(function (itemname) return itemname == "default:torch" end)) then + self.time_counter = 0 + self.is_placing = true + self:set_animation(maidroid.animation_frames.MINE) + end + end + + else + if self.state == state.IDLE then + self:set_animation(maidroid.animation_frames.WALK) + self.state = state.ACCOMPANY + end + self.object:setvelocity{x = direction.x, y = velocity.y, z = direction.z} -- TODO + + if not self.is_placing then + local front = self:get_front() -- if it is dark, set touch. + local wield_stack = self:get_wield_item_stack() + + if is_dark(front) + and (wield_stack:get_name() == "default:torch" + or self:move_main_to_wield(function (itemname) return itemname == "default:torch" end)) then + self.time_counter = 0 + self.is_placing = true + self:set_animation(maidroid.animation_frames.WALK_MINE) + end + end + end + self:set_yaw_by_direction(direction) + + -- if maidroid is stoped by obstacle, the maidroid must jump. + if velocity.y == 0 and self.state == state.ACCOMPANY then + local front_node = self:get_front_node() + if front_node.name ~= "air" and minetest.registered_nodes[front_node.name] ~= nil + and minetest.registered_nodes[front_node.name].walkable then + self.object:setvelocity{x = direction.x, y = 5, z = direction.z} + end + end +end + +-- register a definition of a new core. +maidroid.register_core("maidroid_core:torcher", { + description = "maidroid core : torcher", + inventory_image = "maidroid_core_torcher.png", + on_start = on_start, + on_stop = on_stop, + on_resume = on_start, + on_pause = on_stop, + on_step = on_step, +}) diff --git a/maidroid_core/init.lua b/maidroid_core/init.lua index 7d16105..7932b0b 100644 --- a/maidroid_core/init.lua +++ b/maidroid_core/init.lua @@ -12,6 +12,7 @@ dofile(maidroid_core.modpath .. "/cores/_aux.lua") dofile(maidroid_core.modpath .. "/cores/empty.lua") dofile(maidroid_core.modpath .. "/cores/basic.lua") dofile(maidroid_core.modpath .. "/cores/farming.lua") +dofile(maidroid_core.modpath .. "/cores/torcher.lua") if pdisc then dofile(maidroid_core.modpath .. "/cores/ocr.lua") end From 0cc9807d048a728aa2a296cebc9d39b209512777 Mon Sep 17 00:00:00 2001 From: tacigar Date: Sat, 7 Jan 2017 20:46:29 +0900 Subject: [PATCH 3/5] Add toucher core texture --- maidroid_core/textures/maidroid_core_torcher.png | Bin 0 -> 864 bytes maidroid_core/xcf/maidroid_core_torcher.xcf | Bin 0 -> 1513 bytes 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 maidroid_core/textures/maidroid_core_torcher.png create mode 100644 maidroid_core/xcf/maidroid_core_torcher.xcf diff --git a/maidroid_core/textures/maidroid_core_torcher.png b/maidroid_core/textures/maidroid_core_torcher.png new file mode 100644 index 0000000000000000000000000000000000000000..d0284ee4b0115536925383708b980b71e7a450b5 GIT binary patch literal 864 zcmV-m1E2hfP)WFU8GbZ8()Nlj2>E@cM*00P8GL_t(I%XO1oOB-nv z$A8b$IO9As!OXf91P!)Jlm;Rqh~gF_S@4CnK^Oc2ORn~EKY+Ii?Ki01oA?pD^CAQ+ zzN8uj!JS+PcHN8EMuHv9#5gm1Q8u(&dv4G9|2QxIBf>D`z9<%pUnSD%w79QM1VMlh z;$GqQ_BMuLFfuaoU68oCxA=r|6MNQB|xVY<4yC=?0+3=Iu^1u7H@KSAEhuySpiu%f#dH&mE-G zX;CZ|L$Be{Xn54?b)=M}QYl`&d^R0Vj!-WVPIQRU%^XI$Y@1E~mGjHu+ z+(r{);w>CODVCJtBd7`mK8~X1pB*NID#|g`JV{F>OY@FnegoPfGj3aLv|Fv5&4p`1 zgC+G2&fwx$rjvKIGYw4_F49PGI+eE?%v`nE!L!td*$PtObah!c#%Z_kY^AosWH#C@ zb_Y|DHq{Pun}Ml0S(BC=pjHZ1Vrg5BQaR528_-g>v%_HIZDyuceiu5saycbm^;H}1 zVtAXeopaK9yUFC_T)PLP)q7okJ=vx7J4m7k$_TC8ANoZ#pFKA>eIXiE(g(^RRN5Ip z&6hAuEs!u8Ql5de8CaKr3o~$020o0K?kkH10ev48`BunhL6LwSnRE@`%O6URIeAJk<~}Bgy)uh@$sBD6dYcfn|>G+eSVoZu<&gTC0v#kjZi%1* tF`YnXB*ha@!}rwAPBJBmWw?zRev1eJe+4?+U4y%8tJFB0D!`#D{R0lxXC(jt literal 0 HcmV?d00001 From d94f6fa8b7c1c5cb6ea1547220a8c98a87ae6373 Mon Sep 17 00:00:00 2001 From: tacigar Date: Sat, 7 Jan 2017 20:47:41 +0900 Subject: [PATCH 4/5] Update dye_item_map of core_writer --- maidroid_tool/core_writer.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/maidroid_tool/core_writer.lua b/maidroid_tool/core_writer.lua index daa7ebd..9b6898f 100644 --- a/maidroid_tool/core_writer.lua +++ b/maidroid_tool/core_writer.lua @@ -9,6 +9,7 @@ do -- register core writer ["dye:red"] = "maidroid_core:basic", ["dye:yellow"] = "maidroid_core:farming", ["dye:white"] = "maidroid_core:ocr", + ["dye:orange"] = "maidroid_core:torcher" } local node_box = { From 7e090ce75d010c54eb0a47bdc8907382ba14ac0d Mon Sep 17 00:00:00 2001 From: tacigar Date: Sun, 8 Jan 2017 11:41:38 +0900 Subject: [PATCH 5/5] Update set_attach rotation --- maidroid/api.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maidroid/api.lua b/maidroid/api.lua index aab2c5e..5484818 100644 --- a/maidroid/api.lua +++ b/maidroid/api.lua @@ -274,7 +274,7 @@ do local luaentity = obj:get_luaentity() if maidroid.is_maidroid(luaentity.name) then - self.object:set_attach(obj, "Arm_R", {x = 0.075, y = 0.60, z = -0.20}, {x = 0, y = 90, z = 0}) + self.object:set_attach(obj, "Arm_R", {x = 0.065, y = 0.50, z = -0.15}, {x = -45, y = 0, z = 0}) self.object:set_properties{textures={"maidroid:dummy_empty_craftitem"}} return end