From e2bf995a74f4ec44c3a1554fd8525b696b8c23c5 Mon Sep 17 00:00:00 2001 From: tacigar Date: Tue, 13 Sep 2016 22:33:02 +0900 Subject: [PATCH] [FIX] Fix bugs --- maidroid/api.lua | 23 +++++++++++++++++------ maidroid_core_basic/register.lua | 5 +++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/maidroid/api.lua b/maidroid/api.lua index e4b9570..fa4f11b 100644 --- a/maidroid/api.lua +++ b/maidroid/api.lua @@ -85,9 +85,7 @@ end -- maidroid.maidroid.get_front_node returns a node that exists in front of the maidroid. function maidroid.maidroid.get_front_node(self) - local direction = self.object:get_look_dir() - direction.y = 0 - direction = vector.normalize(direction) + local direction = self:get_look_direction() if direction.x >= 0.5 then if direction.x > 0 then direction.x = 1 else direction.x = -1 end @@ -105,6 +103,13 @@ function maidroid.maidroid.get_front_node(self) return minetest.get_node(front) end +-- maidroid.maidroid.get_look_direction returns a normalized vector that is +-- the maidroid's looking direction. +function maidroid.maidroid.get_look_direction(self) + local yaw = self.object:getyaw() + return vector.normalize{x = math.sin(yaw), y = 0.0, z = -math.cos(yaw)} +end + -- maidroid.maidroid.set_animation sets the maidroid's animation. -- this method is wrapper for self.object:set_animation. function maidroid.maidroid.set_animation(self, frame) @@ -180,7 +185,6 @@ function maidroid.register_maidroid(product_name, def) elseif listname == "core" and maidroid.is_core(stack:get_name()) then return stack:get_count() end - print("KOKO", listname, maidroid.is_core(stack:get_name())) return 0 end, @@ -214,7 +218,6 @@ function maidroid.register_maidroid(product_name, def) if staticdata == "" then self.product_name = product_name self.manufacturing_number = maidroid.manufacturing_data[product_name] - print(self.manufacturing_number, "KOKO") maidroid.manufacturing_data[product_name] = maidroid.manufacturing_data[product_name] + 1 create_inventory(self) else @@ -243,6 +246,14 @@ function maidroid.register_maidroid(product_name, def) end self.formspec_string = create_formspec_string(self) + + local core = self:get_core() + if core ~= nil then + core.on_start(self) + else + self.object:setvelocity{x = 0, y = 0, z = 0} + self.object:setacceleration{x = 0, y = -10, z = 0} + end end -- get_staticdata is a callback function that is called when the object is destroyed. @@ -287,7 +298,6 @@ function maidroid.register_maidroid(product_name, def) -- on_punch is a callback function that is called when a player punch then. function on_punch(self, puncher, time_from_last_punch, tool_capabilities, dir) - print(self.product_name .. tostring(self.manufacturing_number)) if self.pause == true then self.pause = false if self.core_name ~= "" then @@ -336,6 +346,7 @@ function maidroid.register_maidroid(product_name, def) get_core_name = maidroid.maidroid.get_core_name, get_nearest_player = maidroid.maidroid.get_nearest_player, get_front_node = maidroid.maidroid.get_front_node, + get_look_direction = maidroid.maidroid.get_look_direction, set_animation = maidroid.maidroid.set_animation, set_yaw_by_direction = maidroid.maidroid.set_yaw_by_direction, }) diff --git a/maidroid_core_basic/register.lua b/maidroid_core_basic/register.lua index f63b460..62a1367 100644 --- a/maidroid_core_basic/register.lua +++ b/maidroid_core_basic/register.lua @@ -47,10 +47,11 @@ local function on_step(self, dtime) self:set_yaw_by_direction(direction) -- if maidroid is stoped by obstacle, the maidroid must jump. - if velocity == 0 and self.state == state.ACCOMPANY then + if velocity.y == 0 and self.state == state.ACCOMPANY then local front_node = self:get_front_node() + print(front_node.name) if front_node.name ~= "air" then - self.object:setvelocity{x = direction.x, y = 3, z = direction.z} + self.object:setvelocity{x = direction.x, y = 5, z = direction.z} end end end