From 45b0bf5f081ebaccf5189c0a0255a84b560f65fe Mon Sep 17 00:00:00 2001 From: Jordan Irwin Date: Thu, 6 May 2021 17:58:47 -0700 Subject: [PATCH] Update for Minetest 5.x API --- init.lua | 48 ++++++++++++++++++++++++------------------------ tnt_function.lua | 10 +++++----- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/init.lua b/init.lua index 5c1af2c..2a79ab4 100644 --- a/init.lua +++ b/init.lua @@ -9,9 +9,9 @@ dofile(minetest.get_modpath("creeper").."/tnt_function.lua") dofile(minetest.get_modpath("creeper").."/spawn.lua") local function jump(self,pos,direction) - local velocity = self.object:getvelocity() + local velocity = self.object:get_velocity() if minetest.registered_nodes[minetest.get_node(pos).name].climbable then - self.object:setvelocity({x=velocity.x,y=4,z=velocity.z}) + self.object:set_velocity({x=velocity.x,y=4,z=velocity.z}) return end @@ -29,7 +29,7 @@ local function jump(self,pos,direction) if def and def.walkable and def2 and not def2.walkable and def.drawtype ~= "fencelike" then - self.object:setvelocity({ + self.object:set_velocity({ x=velocity.x*2.2, y=self.jump_height, z=velocity.z*2.2 @@ -85,7 +85,7 @@ def.on_activate = function(self,staticdata) self.powered = false self.knockback = false self.state = math.random(1,2) - self.old_y = self.object:getpos().y + self.old_y = self.object:get_pos().y local data = minetest.deserialize(staticdata) if data and type(data) == "table" then @@ -109,13 +109,13 @@ def.on_step = function(self, dtime) local ANIM_STAND = 1 local ANIM_WALK = 2 - local pos = self.object:getpos() - local yaw = self.object:getyaw() + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() local inside = minetest.get_objects_inside_radius(pos,10) local walk_speed = self.walk_speed local animation = self.animation local anim_speed = self.animation_speed - local velocity = self.object:getvelocity() + local velocity = self.object:get_velocity() self.timer = self.timer+0.01 self.turn_timer = self.turn_timer+0.01 @@ -133,10 +133,10 @@ def.on_step = function(self, dtime) if self.turn == "right" then self.yaw = self.yaw+self.turn_speed - self.object:setyaw(self.yaw) + self.object:set_yaw(self.yaw) elseif self.turn == "left" then self.yaw = self.yaw-self.turn_speed - self.object:setyaw(self.yaw) + self.object:set_yaw(self.yaw) end if self.chase and self.visualx < 2 then @@ -174,7 +174,7 @@ def.on_step = function(self, dtime) if velocity.x ~= 0 or velocity.z ~= 0 then - self.object:setvelocity({x=0,y=velocity.y,z=0}) + self.object:set_velocity({x=0,y=velocity.y,z=0}) end end @@ -186,12 +186,12 @@ def.on_step = function(self, dtime) self.direction = {x=math.sin(yaw)*-1,y=-10,z=math.cos(yaw)} if self.direction then - self.object:setvelocity({x=self.direction.x*walk_speed,y=velocity.y,z=self.direction.z*walk_speed}) + self.object:set_velocity({x=self.direction.x*walk_speed,y=velocity.y,z=self.direction.z*walk_speed}) end random_turn(self) - local velocity = self.object:getvelocity() + local velocity = self.object:get_velocity() if self.turn_timer > 1 then local direction = self.direction @@ -250,24 +250,24 @@ def.on_step = function(self, dtime) self.object:set_animation({x=animation.stand_START,y=animation.stand_END},anim_speed,0) self.anim = ANIM_STAND end - self.object:setvelocity({x=0,y=velocity.y,z=0}) + self.object:set_velocity({x=0,y=velocity.y,z=0}) return end end end - local ppos = object:getpos() + local ppos = object:get_pos() self.vec = {x=ppos.x-pos.x,y=ppos.y-pos.y,z=ppos.z-pos.z} self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2 if ppos.x > pos.x then self.yaw = self.yaw+math.pi end self.yaw = self.yaw-2 - self.object:setyaw(self.yaw) + self.object:set_yaw(self.yaw) self.direction = {x=math.sin(self.yaw)*-1,y=0,z=math.cos(self.yaw)} local direction = self.direction - self.object:setvelocity({x=direction.x*2.5,y=velocity.y,z=direction.z*2.5}) + self.object:set_velocity({x=direction.x*2.5,y=velocity.y,z=direction.z*2.5}) -- Jump if self.jump_timer > 0.2 then @@ -283,29 +283,29 @@ def.on_step = function(self, dtime) -- Swim local node = minetest.get_node(pos) if minetest.get_item_group(node.name,"water") ~= 0 then - self.object:setacceleration({x=0,y=1,z=0}) - local velocity = self.object:getvelocity() - if self.object:getvelocity().y > 5 then - self.object:setvelocity({x=0,y=velocity.y-velocity.y/2,z=0}) + self.object:set_acceleration({x=0,y=1,z=0}) + local velocity = self.object:get_velocity() + if self.object:get_velocity().y > 5 then + self.object:set_velocity({x=0,y=velocity.y-velocity.y/2,z=0}) else - self.object:setvelocity({x=0,y=velocity.y+1,z=0}) + self.object:set_velocity({x=0,y=velocity.y+1,z=0}) end else - self.object:setacceleration({x=0,y=-10,z=0}) + self.object:set_acceleration({x=0,y=-10,z=0}) end end def.on_punch = function(self,puncher,time_from_last_punch,tool_capabilities,dir) if self.knockback == false then local knockback_level = self.knockback_level - self.object:setvelocity({x=dir.x*knockback_level,y=3,z=dir.z*knockback_level}) + self.object:set_velocity({x=dir.x*knockback_level,y=3,z=dir.z*knockback_level}) self.knockback = true minetest.after(0.6,function() self.knockback = false end) end if self.object:get_hp() < 1 then - local pos = self.object:getpos() + local pos = self.object:get_pos() local x = 1/math.random(1,5)*dir.x local z = 1/math.random(1,5)*dir.z local p = {x=pos.x+x,y=pos.y,z=pos.z+z} diff --git a/tnt_function.lua b/tnt_function.lua index fa933d0..82de27e 100644 --- a/tnt_function.lua +++ b/tnt_function.lua @@ -37,8 +37,8 @@ local function eject_drops(drops, pos, radius) local obj = minetest.add_item(drop_pos, item) if obj then obj:get_luaentity().collect = true - obj:setacceleration({x=0, y=-10, z=0}) - obj:setvelocity({x=math.random(-3, 3), y=10, + obj:set_acceleration({x=0, y=-10, z=0}) + obj:set_velocity({x=math.random(-3, 3), y=10, z=math.random(-3, 3)}) end count = count - max @@ -100,12 +100,12 @@ local function entity_physics(pos, radius) radius = radius * 2 local objs = minetest.get_objects_inside_radius(pos, radius) for _, obj in pairs(objs) do - local obj_pos = obj:getpos() - local obj_vel = obj:getvelocity() + local obj_pos = obj:get_pos() + local obj_vel = obj:get_velocity() local dist = math.max(1, vector.distance(pos, obj_pos)) if obj_vel ~= nil then - obj:setvelocity(calc_velocity(pos, obj_pos, + obj:set_velocity(calc_velocity(pos, obj_pos, obj_vel, radius * 10)) end