2014-08-31 14:44:42 +02:00
|
|
|
local time = tonumber(os.clock())+10
|
|
|
|
local lastpos = vector.zero or {x=0, y=0, z=0}
|
2015-06-05 11:30:34 +02:00
|
|
|
local last_tab, always_test
|
|
|
|
|
|
|
|
if not core.get_gravity then
|
|
|
|
local gravity,grav_updating = 10
|
|
|
|
function core.get_gravity()
|
|
|
|
if not grav_updating then
|
|
|
|
gravity = tonumber(core.setting_get("movement_gravity")) or gravity
|
|
|
|
grav_updating = true
|
|
|
|
core.after(50, function()
|
|
|
|
grav_updating = false
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
return gravity
|
|
|
|
end
|
|
|
|
local set_setting = core.setting_set
|
|
|
|
function core.setting_set(name, v, ...)
|
|
|
|
if name == "gravity" then
|
|
|
|
name = "movement_gravity"
|
|
|
|
gravity = tonumber(v) or gravity
|
|
|
|
end
|
|
|
|
return set_setting(name, v, ...)
|
|
|
|
end
|
|
|
|
local get_setting = core.setting_get
|
|
|
|
function core.setting_get(name, ...)
|
|
|
|
if name == "gravity" then
|
|
|
|
name = "movement_gravity"
|
|
|
|
end
|
|
|
|
return get_setting(name, ...)
|
|
|
|
end
|
|
|
|
end
|
2014-08-31 14:44:42 +02:00
|
|
|
|
2014-08-31 14:12:32 +02:00
|
|
|
local function get_nodes(pos)
|
2014-08-31 14:59:40 +02:00
|
|
|
if not always_test then
|
|
|
|
local rnd_pos = vector.round(pos)
|
|
|
|
local t = tonumber(os.clock())
|
|
|
|
if vector.equals(rnd_pos, lastpos)
|
|
|
|
and t-time < 10 then
|
|
|
|
return last_tab
|
|
|
|
end
|
2014-08-31 14:49:25 +02:00
|
|
|
time = t
|
2014-08-31 14:59:40 +02:00
|
|
|
lastpos = rnd_pos
|
|
|
|
local near_objects = minetest.get_objects_inside_radius(pos, 1)
|
|
|
|
if #near_objects >= 2 then
|
|
|
|
always_test = true
|
|
|
|
minetest.after(10, function() always_test = false end)
|
|
|
|
end
|
2014-08-31 14:49:25 +02:00
|
|
|
end
|
2014-08-31 14:12:32 +02:00
|
|
|
local tab,n = {},1
|
|
|
|
for i = -1,1,2 do
|
|
|
|
for _,p in pairs({
|
|
|
|
{x=pos.x+i, y=pos.y, z=pos.z},
|
|
|
|
{x=pos.x, y=pos.y, z=pos.z+i}
|
|
|
|
}) do
|
|
|
|
tab[n] = {p, minetest.get_node(p)}
|
|
|
|
n = n+1
|
|
|
|
end
|
|
|
|
end
|
2014-08-31 14:59:40 +02:00
|
|
|
if not always_test then
|
|
|
|
last_tab = tab
|
|
|
|
end
|
2014-08-31 14:12:32 +02:00
|
|
|
return tab
|
|
|
|
end
|
2012-09-25 16:29:37 +02:00
|
|
|
|
2014-08-31 14:12:32 +02:00
|
|
|
local function get_flowing_dir(pos)
|
|
|
|
local data = get_nodes(pos)
|
|
|
|
local param2 = minetest.get_node(pos).param2
|
|
|
|
if param2 > 7 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
for _,i in pairs(data) do
|
|
|
|
local nd = i[2]
|
|
|
|
local name = nd.name
|
|
|
|
local par2 = nd.param2
|
|
|
|
if name == "default:water_flowing"
|
|
|
|
and par2 < param2 then
|
|
|
|
return i[1]
|
2012-09-25 16:29:37 +02:00
|
|
|
end
|
2014-08-31 14:12:32 +02:00
|
|
|
end
|
|
|
|
for _,i in pairs(data) do
|
|
|
|
local nd = i[2]
|
|
|
|
local name = nd.name
|
|
|
|
local par2 = nd.param2
|
|
|
|
if name == "default:water_flowing"
|
|
|
|
and par2 >= 11 then
|
|
|
|
return i[1]
|
2012-09-25 16:29:37 +02:00
|
|
|
end
|
2014-08-31 14:12:32 +02:00
|
|
|
end
|
|
|
|
for _,i in pairs(data) do
|
|
|
|
local nd = i[2]
|
|
|
|
local name = nd.name
|
|
|
|
local par2 = nd.param2
|
|
|
|
local tmp = minetest.registered_nodes[name]
|
|
|
|
if tmp
|
|
|
|
and not tmp.walkable
|
|
|
|
and name ~= "default:water_flowing" then
|
|
|
|
return i[1]
|
2012-09-25 16:29:37 +02:00
|
|
|
end
|
2014-08-31 14:12:32 +02:00
|
|
|
end
|
|
|
|
end
|
2012-09-25 16:29:37 +02:00
|
|
|
|
2014-08-31 14:12:32 +02:00
|
|
|
local item_entity = minetest.registered_entities["__builtin:item"]
|
|
|
|
local old_on_step = item_entity.on_step or function()end
|
2012-09-25 16:29:37 +02:00
|
|
|
|
2016-02-18 18:45:59 +01:00
|
|
|
item_entity.makes_footstep_sound = true
|
2014-08-31 14:12:32 +02:00
|
|
|
item_entity.on_step = function(self, dtime)
|
|
|
|
old_on_step(self, dtime)
|
2015-06-05 11:30:34 +02:00
|
|
|
|
2014-08-31 14:12:32 +02:00
|
|
|
local p = self.object:getpos()
|
2015-06-05 11:30:34 +02:00
|
|
|
|
2014-08-31 14:12:32 +02:00
|
|
|
local name = minetest.get_node(p).name
|
|
|
|
if name == "default:lava_flowing"
|
|
|
|
or name == "default:lava_source" then
|
|
|
|
minetest.sound_play("builtin_item_lava", {pos=p})
|
2015-04-09 22:31:21 +02:00
|
|
|
minetest.add_particlespawner({
|
|
|
|
amount = 3,
|
|
|
|
time = 0.1,
|
|
|
|
minpos = {x=p.x, y=p.y, z=p.z},
|
|
|
|
maxpos = {x=p.x, y=p.y+0.2, z=p.z},
|
|
|
|
minacc = {x=-0.5,y=5,z=-0.5},
|
|
|
|
maxacc = {x=0.5,y=5,z=0.5},
|
|
|
|
minexptime = 0.1,
|
|
|
|
minsize = 2,
|
|
|
|
maxsize = 4,
|
|
|
|
texture = "smoke_puff.png"
|
|
|
|
})
|
2015-04-09 21:55:14 +02:00
|
|
|
minetest.add_particlespawner ({
|
|
|
|
amount = 1, time = 0.4,
|
|
|
|
minpos = {x = p.x, y= p.y + 0.25, z= p.z},
|
|
|
|
maxpos = {x = p.x, y= p.y + 0.5, z= p.z},
|
|
|
|
minexptime = 0.2, maxexptime = 0.4,
|
|
|
|
minsize = 4, maxsize = 6,
|
|
|
|
collisiondetection = false,
|
|
|
|
vertical = false,
|
|
|
|
texture = "fire_basic_flame.png",
|
|
|
|
})
|
2014-08-31 14:12:32 +02:00
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
2012-09-25 16:29:37 +02:00
|
|
|
|
2014-08-31 14:12:32 +02:00
|
|
|
local tmp = minetest.registered_nodes[name]
|
|
|
|
if tmp
|
|
|
|
and tmp.liquidtype == "flowing" then
|
|
|
|
local vec = get_flowing_dir(self.object:getpos())
|
|
|
|
if vec then
|
|
|
|
local v = self.object:getvelocity()
|
|
|
|
if vec.x-p.x > 0 then
|
|
|
|
self.object:setvelocity({x=0.5,y=v.y,z=0})
|
|
|
|
elseif vec.x-p.x < 0 then
|
|
|
|
self.object:setvelocity({x=-0.5,y=v.y,z=0})
|
|
|
|
elseif vec.z-p.z > 0 then
|
|
|
|
self.object:setvelocity({x=0,y=v.y,z=0.5})
|
|
|
|
elseif vec.z-p.z < 0 then
|
|
|
|
self.object:setvelocity({x=0,y=v.y,z=-0.5})
|
2013-04-19 21:07:02 +02:00
|
|
|
end
|
2015-06-05 11:30:34 +02:00
|
|
|
self.object:setacceleration({x=0, y=-core.get_gravity(), z=0})
|
2014-08-31 14:12:32 +02:00
|
|
|
self.physical_state = true
|
|
|
|
self.object:set_properties({
|
|
|
|
physical = true
|
|
|
|
})
|
2012-09-25 16:29:37 +02:00
|
|
|
end
|
2014-08-31 14:12:32 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_entity(":__builtin:item", item_entity)
|
2012-10-07 19:42:41 +02:00
|
|
|
|
|
|
|
if minetest.setting_get("log_mods") then
|
|
|
|
minetest.log("action", "builtin_item loaded")
|
|
|
|
end
|