1
0
mirror of https://github.com/Splizard/minetest-mod-snow.git synced 2024-12-27 15:10:20 +01:00

Prod snowballs when they are stuck

This commit is contained in:
HybridDog 2018-08-07 15:02:30 +02:00
parent 5b4e705055
commit 11364a550c

View File

@ -129,7 +129,7 @@ end
--Snowball_entity.on_step()--> called when snowball is moving.
function snow_snowball_ENTITY.on_step(self, dtime)
self.timer = self.timer+dtime
self.timer = self.timer + dtime
if self.timer > 600 then
-- 10 minutes are too long for a snowball to fly somewhere
self.object:remove()
@ -137,14 +137,32 @@ function snow_snowball_ENTITY.on_step(self, dtime)
end
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 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
end
local pos = vector.round(self.object:getpos())
if minetest.get_node(pos).name == "air" then
pos.y = pos.y-1
if minetest.get_node(pos).name == "air" then
if vel.x == 0
and vel.z == 0 then
self.probably_stuck = true
end
return
end
end