mirror of
https://github.com/Splizard/minetest-mod-snow.git
synced 2024-12-28 07:30:17 +01:00
Prod snowballs when they are stuck
This commit is contained in:
parent
5b4e705055
commit
11364a550c
@ -129,7 +129,7 @@ end
|
|||||||
|
|
||||||
--Snowball_entity.on_step()--> called when snowball is moving.
|
--Snowball_entity.on_step()--> called when snowball is moving.
|
||||||
function snow_snowball_ENTITY.on_step(self, dtime)
|
function snow_snowball_ENTITY.on_step(self, dtime)
|
||||||
self.timer = self.timer+dtime
|
self.timer = self.timer + dtime
|
||||||
if self.timer > 600 then
|
if self.timer > 600 then
|
||||||
-- 10 minutes are too long for a snowball to fly somewhere
|
-- 10 minutes are too long for a snowball to fly somewhere
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
@ -137,14 +137,32 @@ function snow_snowball_ENTITY.on_step(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if self.physical then
|
if self.physical then
|
||||||
local fell = self.object:getvelocity().y == 0
|
local vel = self.object:getvelocity()
|
||||||
|
local fell = vel.y == 0
|
||||||
if not fell then
|
if not fell then
|
||||||
|
if self.probably_stuck then
|
||||||
|
self.probably_stuck = nil
|
||||||
|
end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if self.probably_stuck
|
||||||
|
and vel.x == 0
|
||||||
|
and vel.z == 0 then
|
||||||
|
-- add a small velocity to move it from the corner
|
||||||
|
vel.x = math.random() - 0.5
|
||||||
|
vel.z = math.random() - 0.5
|
||||||
|
self.object:set_velocity(vel)
|
||||||
|
self.probably_stuck = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local pos = vector.round(self.object:getpos())
|
local pos = vector.round(self.object:getpos())
|
||||||
if minetest.get_node(pos).name == "air" then
|
if minetest.get_node(pos).name == "air" then
|
||||||
pos.y = pos.y-1
|
pos.y = pos.y-1
|
||||||
if minetest.get_node(pos).name == "air" then
|
if minetest.get_node(pos).name == "air" then
|
||||||
|
if vel.x == 0
|
||||||
|
and vel.z == 0 then
|
||||||
|
self.probably_stuck = true
|
||||||
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user