1
0
mirror of https://github.com/HybridDog/builtin_item.git synced 2024-12-22 17:00:27 +01:00
This commit is contained in:
HybridDog 2016-05-26 12:17:00 +02:00
parent bd97071dc6
commit bb90a38c2e

View File

@ -1,5 +1,5 @@
local time = tonumber(os.clock())+10 local time = minetest.get_us_time()+10*1000000
local lastpos = vector.zero or {x=0, y=0, z=0} local lastpos = {x=0, y=0, z=0}
local last_tab, always_test local last_tab, always_test
if not core.get_gravity then if not core.get_gravity then
@ -33,14 +33,13 @@ end
local function get_nodes(pos) local function get_nodes(pos)
if not always_test then if not always_test then
local rnd_pos = vector.round(pos) local t = minetest.get_us_time()
local t = tonumber(os.clock()) if vector.equals(pos, lastpos)
if vector.equals(rnd_pos, lastpos) and t-time < 10*1000000 then
and t-time < 10 then
return last_tab return last_tab
end end
time = t time = t
lastpos = rnd_pos lastpos = pos
local near_objects = minetest.get_objects_inside_radius(pos, 1) local near_objects = minetest.get_objects_inside_radius(pos, 1)
if #near_objects >= 2 then if #near_objects >= 2 then
always_test = true always_test = true
@ -108,6 +107,22 @@ item_entity.bt_timer = 0
item_entity.on_step = function(self, dtime) item_entity.on_step = function(self, dtime)
old_on_step(self, dtime) old_on_step(self, dtime)
if self.bt_acc
and not vector.equals(self.object:getacceleration(), self.bt_acc) then
self.object:setacceleration(self.bt_acc)
end
if self.bt_vel
and not vector.equals(self.object:getvelocity(), self.bt_vel) then
self.object:setvelocity(self.bt_vel)
end
if self.bt_phys ~= nil
and self.physical_state ~= self.bt_phys then
self.physical_state = self.bt_phys
self.object:set_properties({
physical = self.bt_phys
})
end
self.bt_timer = self.bt_timer+dtime self.bt_timer = self.bt_timer+dtime
if self.bt_timer < 1 then if self.bt_timer < 1 then
return return
@ -115,8 +130,9 @@ item_entity.on_step = function(self, dtime)
self.bt_timer = 0 self.bt_timer = 0
local p = self.object:getpos() local p = self.object:getpos()
local pos = vector.round(p)
local name = minetest.get_node(p).name local name = minetest.get_node(pos).name
if name == "default:lava_flowing" if name == "default:lava_flowing"
or name == "default:lava_source" then or name == "default:lava_source" then
minetest.sound_play("builtin_item_lava", {pos=p}) minetest.sound_play("builtin_item_lava", {pos=p})
@ -147,27 +163,32 @@ item_entity.on_step = function(self, dtime)
end end
local tmp = minetest.registered_nodes[name] local tmp = minetest.registered_nodes[name]
if tmp if not tmp then
and tmp.liquidtype == "flowing" then return
local vec = get_flowing_dir(self.object:getpos()) end
local acc
if tmp.liquidtype then
acc = {x=0, y=core.get_gravity()*(((p.y-.5)%1)*.9-1), z=0}
self.object:setacceleration(acc)
self.bt_acc = acc
else
self.bt_acc = nil
end
if tmp.liquidtype == "flowing" then
local vec = get_flowing_dir(pos)
if vec then if vec then
local v = self.object:getvelocity() local v = vector.add(self.object:getvelocity(), vector.multiply(vector.subtract(vec, pos),.5))
if vec.x-p.x > 0 then self.bt_vel = v
self.object:setvelocity({x=0.5,y=v.y,z=0}) self.object:setvelocity(v)
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})
end
self.object:setacceleration({x=0, y=-core.get_gravity(), z=0})
self.physical_state = true self.physical_state = true
self.bt_phys = true
self.object:set_properties({ self.object:set_properties({
physical = true physical = true
}) })
return
end end
end end
self.bt_vel = nil
end end
minetest.register_entity(":__builtin:item", item_entity) minetest.register_entity(":__builtin:item", item_entity)