From fbc2282debf31bd81217e9944dc278bf4a0e3929 Mon Sep 17 00:00:00 2001 From: arpruss Date: Fri, 25 Sep 2015 23:08:53 -0500 Subject: [PATCH] foo --- raspberryjammod/init.lua | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/raspberryjammod/init.lua b/raspberryjammod/init.lua index 742e336..c6cae97 100644 --- a/raspberryjammod/init.lua +++ b/raspberryjammod/init.lua @@ -46,7 +46,7 @@ function getplayer(id) end function handle_entity(cmd, id, args) - entity = getplayer(id) + local entity = getplayer(id) if cmd == "getPos" then local pos = entity:getpos() return ""..(-pos.x)..","..(pos.y)..","..(pos.z) @@ -59,6 +59,30 @@ function handle_entity(cmd, id, args) elseif cmd == "getDirection" then local dir = entity:get_look_dir() return ""..(-dir.x)..","..(dir.y)..","..(dir.z) + elseif cmd == "setPitch" then + -- TODO: For mysterious reasons, set_look_pitch() and get_look_pitch() + -- values are opposite sign, so we don't negate here. Ideally, the mod + -- would detect this to make sure that if it's fixed in the next version + -- this wouldn't be an issue. + entity:set_look_pitch(tonumber(args[1]) * math.pi / 180) + elseif cmd == "setRotation" then + -- TODO: For mysterious reasons, set_look_yaw() and get_look_yaw() + -- values differ by pi/2. Ideally, the mod + -- would detect this to make sure that if it's fixed in the next version + -- this wouldn't be an issue. + entity:set_look_yaw((-tonumber(args[1])) * math.pi / 180) + elseif cmd == "setDirection" then + -- TODO: Fix set_look_yaw() and get_look_yaw() compensation. + local x = tonumber(args[1]) + local y = tonumber(args[2]) + local z = tonumber(args[3]) + local xz = math.sqrt(x*x+z*z) + if xz >= 1e-9 then + entity:set_look_yaw(- math.atan2(-x,z)) + end + if x*x + y*y + z*z >= 1e-18 then + entity:set_look_pitch(math.atan2(-y, xz)) + end end return nil end