forked from Mirrorlandia_minetest/mod-sneeker
Update for Minetest 5.x API
This commit is contained in:
parent
6efa22caf4
commit
45b0bf5f08
48
init.lua
48
init.lua
@ -9,9 +9,9 @@ dofile(minetest.get_modpath("creeper").."/tnt_function.lua")
|
|||||||
dofile(minetest.get_modpath("creeper").."/spawn.lua")
|
dofile(minetest.get_modpath("creeper").."/spawn.lua")
|
||||||
|
|
||||||
local function jump(self,pos,direction)
|
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
|
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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ local function jump(self,pos,direction)
|
|||||||
if def and def.walkable
|
if def and def.walkable
|
||||||
and def2 and not def2.walkable
|
and def2 and not def2.walkable
|
||||||
and def.drawtype ~= "fencelike" then
|
and def.drawtype ~= "fencelike" then
|
||||||
self.object:setvelocity({
|
self.object:set_velocity({
|
||||||
x=velocity.x*2.2,
|
x=velocity.x*2.2,
|
||||||
y=self.jump_height,
|
y=self.jump_height,
|
||||||
z=velocity.z*2.2
|
z=velocity.z*2.2
|
||||||
@ -85,7 +85,7 @@ def.on_activate = function(self,staticdata)
|
|||||||
self.powered = false
|
self.powered = false
|
||||||
self.knockback = false
|
self.knockback = false
|
||||||
self.state = math.random(1,2)
|
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)
|
local data = minetest.deserialize(staticdata)
|
||||||
if data and type(data) == "table" then
|
if data and type(data) == "table" then
|
||||||
@ -109,13 +109,13 @@ def.on_step = function(self, dtime)
|
|||||||
local ANIM_STAND = 1
|
local ANIM_STAND = 1
|
||||||
local ANIM_WALK = 2
|
local ANIM_WALK = 2
|
||||||
|
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:get_pos()
|
||||||
local yaw = self.object:getyaw()
|
local yaw = self.object:get_yaw()
|
||||||
local inside = minetest.get_objects_inside_radius(pos,10)
|
local inside = minetest.get_objects_inside_radius(pos,10)
|
||||||
local walk_speed = self.walk_speed
|
local walk_speed = self.walk_speed
|
||||||
local animation = self.animation
|
local animation = self.animation
|
||||||
local anim_speed = self.animation_speed
|
local anim_speed = self.animation_speed
|
||||||
local velocity = self.object:getvelocity()
|
local velocity = self.object:get_velocity()
|
||||||
|
|
||||||
self.timer = self.timer+0.01
|
self.timer = self.timer+0.01
|
||||||
self.turn_timer = self.turn_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
|
if self.turn == "right" then
|
||||||
self.yaw = self.yaw+self.turn_speed
|
self.yaw = self.yaw+self.turn_speed
|
||||||
self.object:setyaw(self.yaw)
|
self.object:set_yaw(self.yaw)
|
||||||
elseif self.turn == "left" then
|
elseif self.turn == "left" then
|
||||||
self.yaw = self.yaw-self.turn_speed
|
self.yaw = self.yaw-self.turn_speed
|
||||||
self.object:setyaw(self.yaw)
|
self.object:set_yaw(self.yaw)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.chase and self.visualx < 2 then
|
if self.chase and self.visualx < 2 then
|
||||||
@ -174,7 +174,7 @@ def.on_step = function(self, dtime)
|
|||||||
|
|
||||||
if velocity.x ~= 0
|
if velocity.x ~= 0
|
||||||
or velocity.z ~= 0 then
|
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
|
||||||
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)}
|
self.direction = {x=math.sin(yaw)*-1,y=-10,z=math.cos(yaw)}
|
||||||
if self.direction then
|
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
|
end
|
||||||
|
|
||||||
random_turn(self)
|
random_turn(self)
|
||||||
|
|
||||||
local velocity = self.object:getvelocity()
|
local velocity = self.object:get_velocity()
|
||||||
|
|
||||||
if self.turn_timer > 1 then
|
if self.turn_timer > 1 then
|
||||||
local direction = self.direction
|
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.object:set_animation({x=animation.stand_START,y=animation.stand_END},anim_speed,0)
|
||||||
self.anim = ANIM_STAND
|
self.anim = ANIM_STAND
|
||||||
end
|
end
|
||||||
self.object:setvelocity({x=0,y=velocity.y,z=0})
|
self.object:set_velocity({x=0,y=velocity.y,z=0})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
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.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
|
self.yaw = math.atan(self.vec.z/self.vec.x)+math.pi^2
|
||||||
if ppos.x > pos.x then
|
if ppos.x > pos.x then
|
||||||
self.yaw = self.yaw+math.pi
|
self.yaw = self.yaw+math.pi
|
||||||
end
|
end
|
||||||
self.yaw = self.yaw-2
|
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)}
|
self.direction = {x=math.sin(self.yaw)*-1,y=0,z=math.cos(self.yaw)}
|
||||||
|
|
||||||
local direction = self.direction
|
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
|
-- Jump
|
||||||
if self.jump_timer > 0.2 then
|
if self.jump_timer > 0.2 then
|
||||||
@ -283,29 +283,29 @@ def.on_step = function(self, dtime)
|
|||||||
-- Swim
|
-- Swim
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
if minetest.get_item_group(node.name,"water") ~= 0 then
|
if minetest.get_item_group(node.name,"water") ~= 0 then
|
||||||
self.object:setacceleration({x=0,y=1,z=0})
|
self.object:set_acceleration({x=0,y=1,z=0})
|
||||||
local velocity = self.object:getvelocity()
|
local velocity = self.object:get_velocity()
|
||||||
if self.object:getvelocity().y > 5 then
|
if self.object:get_velocity().y > 5 then
|
||||||
self.object:setvelocity({x=0,y=velocity.y-velocity.y/2,z=0})
|
self.object:set_velocity({x=0,y=velocity.y-velocity.y/2,z=0})
|
||||||
else
|
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
|
end
|
||||||
else
|
else
|
||||||
self.object:setacceleration({x=0,y=-10,z=0})
|
self.object:set_acceleration({x=0,y=-10,z=0})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def.on_punch = function(self,puncher,time_from_last_punch,tool_capabilities,dir)
|
def.on_punch = function(self,puncher,time_from_last_punch,tool_capabilities,dir)
|
||||||
if self.knockback == false then
|
if self.knockback == false then
|
||||||
local knockback_level = self.knockback_level
|
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
|
self.knockback = true
|
||||||
minetest.after(0.6,function()
|
minetest.after(0.6,function()
|
||||||
self.knockback = false
|
self.knockback = false
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
if self.object:get_hp() < 1 then
|
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 x = 1/math.random(1,5)*dir.x
|
||||||
local z = 1/math.random(1,5)*dir.z
|
local z = 1/math.random(1,5)*dir.z
|
||||||
local p = {x=pos.x+x,y=pos.y,z=pos.z+z}
|
local p = {x=pos.x+x,y=pos.y,z=pos.z+z}
|
||||||
|
@ -37,8 +37,8 @@ local function eject_drops(drops, pos, radius)
|
|||||||
local obj = minetest.add_item(drop_pos, item)
|
local obj = minetest.add_item(drop_pos, item)
|
||||||
if obj then
|
if obj then
|
||||||
obj:get_luaentity().collect = true
|
obj:get_luaentity().collect = true
|
||||||
obj:setacceleration({x=0, y=-10, z=0})
|
obj:set_acceleration({x=0, y=-10, z=0})
|
||||||
obj:setvelocity({x=math.random(-3, 3), y=10,
|
obj:set_velocity({x=math.random(-3, 3), y=10,
|
||||||
z=math.random(-3, 3)})
|
z=math.random(-3, 3)})
|
||||||
end
|
end
|
||||||
count = count - max
|
count = count - max
|
||||||
@ -100,12 +100,12 @@ local function entity_physics(pos, radius)
|
|||||||
radius = radius * 2
|
radius = radius * 2
|
||||||
local objs = minetest.get_objects_inside_radius(pos, radius)
|
local objs = minetest.get_objects_inside_radius(pos, radius)
|
||||||
for _, obj in pairs(objs) do
|
for _, obj in pairs(objs) do
|
||||||
local obj_pos = obj:getpos()
|
local obj_pos = obj:get_pos()
|
||||||
local obj_vel = obj:getvelocity()
|
local obj_vel = obj:get_velocity()
|
||||||
local dist = math.max(1, vector.distance(pos, obj_pos))
|
local dist = math.max(1, vector.distance(pos, obj_pos))
|
||||||
|
|
||||||
if obj_vel ~= nil then
|
if obj_vel ~= nil then
|
||||||
obj:setvelocity(calc_velocity(pos, obj_pos,
|
obj:set_velocity(calc_velocity(pos, obj_pos,
|
||||||
obj_vel, radius * 10))
|
obj_vel, radius * 10))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user