Make all entities flow
This commit is contained in:
parent
a8d3e798d8
commit
039e90d08a
@ -16,46 +16,6 @@ local level2
|
||||
local nodename
|
||||
local acceleration
|
||||
|
||||
local function flow(self)
|
||||
pos = self.object:get_pos()
|
||||
pos.y = pos.y + self.object:get_properties().collisionbox[2]
|
||||
pos = vector.round(pos)
|
||||
node = minetest.get_node(pos).name
|
||||
node_above = minetest.get_node(vector.new(pos.x,pos.y+1,pos.z)).name
|
||||
goalx = 0
|
||||
goalz = 0
|
||||
found = false
|
||||
if node == "main:waterflow" then
|
||||
currentvel = self.object:get_velocity()
|
||||
level = minetest.get_node_level(pos)
|
||||
for x = -1,1 do
|
||||
for z = -1,1 do
|
||||
if found == false then
|
||||
nodename = minetest.get_node(vector.new(pos.x+x,pos.y,pos.z+z)).name
|
||||
level2 = minetest.get_node_level(vector.new(pos.x+x,pos.y,pos.z+z))
|
||||
if level2 > level and nodename == "main:waterflow" or nodename == "main:water" then
|
||||
goalx = -x
|
||||
goalz = -z
|
||||
--diagonal flow
|
||||
if goalx ~= 0 and goalz ~= 0 then
|
||||
found = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--only add velocity if there is one
|
||||
--else this stops the player
|
||||
if goalx ~= 0 and goalz ~= 0 then
|
||||
acceleration = vector.new(goalx-currentvel.x,0,goalz-currentvel.z)
|
||||
self.object:add_velocity(acceleration)
|
||||
elseif goalx ~= 0 or goalz ~= 0 then
|
||||
acceleration = vector.new(goalx-currentvel.x,0,goalz-currentvel.z)
|
||||
self.object:add_velocity(acceleration)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function lavaflow(self)
|
||||
pos = self.object:get_pos()
|
||||
pos.y = pos.y + self.object:get_properties().collisionbox[2]
|
||||
|
58
mods/flow_lib/init.lua
Normal file
58
mods/flow_lib/init.lua
Normal file
@ -0,0 +1,58 @@
|
||||
|
||||
local
|
||||
minetest,vector,math,pairs
|
||||
=
|
||||
minetest,vector,math,pairs
|
||||
--
|
||||
local name
|
||||
local pos
|
||||
local node
|
||||
local node_above
|
||||
local goalx
|
||||
local goalz
|
||||
local currentvel
|
||||
local level
|
||||
local level2
|
||||
local nodename
|
||||
local acceleration
|
||||
|
||||
function flow(self)
|
||||
pos = self.object:get_pos()
|
||||
pos.y = pos.y + self.object:get_properties().collisionbox[2]
|
||||
pos = vector.round(pos)
|
||||
node = minetest.get_node(pos).name
|
||||
node_above = minetest.get_node(vector.new(pos.x,pos.y+1,pos.z)).name
|
||||
goalx = 0
|
||||
goalz = 0
|
||||
found = false
|
||||
if node == "main:waterflow" then
|
||||
currentvel = self.object:get_velocity()
|
||||
level = minetest.get_node_level(pos)
|
||||
for x = -1,1 do
|
||||
for z = -1,1 do
|
||||
if found == false then
|
||||
nodename = minetest.get_node(vector.new(pos.x+x,pos.y,pos.z+z)).name
|
||||
level2 = minetest.get_node_level(vector.new(pos.x+x,pos.y,pos.z+z))
|
||||
if level2 > level and nodename == "main:waterflow" or nodename == "main:water" then
|
||||
goalx = -x
|
||||
goalz = -z
|
||||
--diagonal flow
|
||||
if goalx ~= 0 and goalz ~= 0 then
|
||||
found = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--only add velocity if there is one
|
||||
--else this stops the player
|
||||
if goalx ~= 0 and goalz ~= 0 then
|
||||
acceleration = vector.new(goalx/1.5,0,goalz/1.5)
|
||||
self.object:add_velocity(acceleration)
|
||||
elseif goalx ~= 0 or goalz ~= 0 then
|
||||
acceleration = vector.new(goalx,0,goalz)
|
||||
self.object:add_velocity(acceleration)
|
||||
end
|
||||
end
|
||||
end
|
||||
--
|
@ -170,59 +170,6 @@ local set_item = function(self, item)
|
||||
})
|
||||
end
|
||||
|
||||
--
|
||||
local name
|
||||
local pos
|
||||
local node
|
||||
local node_above
|
||||
local goalx
|
||||
local goalz
|
||||
local currentvel
|
||||
local level
|
||||
local level2
|
||||
local nodename
|
||||
local acceleration
|
||||
|
||||
local function flow(self)
|
||||
pos = self.object:get_pos()
|
||||
pos.y = pos.y + self.object:get_properties().collisionbox[2]
|
||||
pos = vector.round(pos)
|
||||
node = minetest.get_node(pos).name
|
||||
node_above = minetest.get_node(vector.new(pos.x,pos.y+1,pos.z)).name
|
||||
goalx = 0
|
||||
goalz = 0
|
||||
found = false
|
||||
if node == "main:waterflow" then
|
||||
currentvel = self.object:get_velocity()
|
||||
level = minetest.get_node_level(pos)
|
||||
for x = -1,1 do
|
||||
for z = -1,1 do
|
||||
if found == false then
|
||||
nodename = minetest.get_node(vector.new(pos.x+x,pos.y,pos.z+z)).name
|
||||
level2 = minetest.get_node_level(vector.new(pos.x+x,pos.y,pos.z+z))
|
||||
if level2 > level and nodename == "main:waterflow" or nodename == "main:water" then
|
||||
goalx = -x
|
||||
goalz = -z
|
||||
--diagonal flow
|
||||
if goalx ~= 0 and goalz ~= 0 then
|
||||
found = true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
--only add velocity if there is one
|
||||
--else this stops the player
|
||||
if goalx ~= 0 and goalz ~= 0 then
|
||||
acceleration = vector.new(goalx-currentvel.x,0,goalz-currentvel.z)
|
||||
self.object:add_velocity(acceleration)
|
||||
elseif goalx ~= 0 or goalz ~= 0 then
|
||||
acceleration = vector.new(goalx-currentvel.x,0,goalz-currentvel.z)
|
||||
self.object:add_velocity(acceleration)
|
||||
end
|
||||
end
|
||||
end
|
||||
--
|
||||
|
||||
local get_staticdata = function(self)
|
||||
return minetest.serialize({
|
||||
|
@ -168,6 +168,7 @@ mob_register.on_step = function(self, dtime,moveresult)
|
||||
self.custom_function_begin(self,dtime)
|
||||
end
|
||||
|
||||
flow(self)
|
||||
self.collision_detection(self)
|
||||
if self.fall_damage then
|
||||
self.fall_damage(self)
|
||||
|
@ -47,10 +47,10 @@ local function flow(player)
|
||||
--only add velocity if there is one
|
||||
--else this stops the player
|
||||
if goalx ~= 0 and goalz ~= 0 then
|
||||
acceleration = vector.new(goalx/3,0,goalz/3)
|
||||
acceleration = vector.new(goalx/1.5,0,goalz/1.5)
|
||||
player:add_player_velocity(acceleration)
|
||||
elseif goalx ~= 0 or goalz ~= 0 then
|
||||
acceleration = vector.new(goalx/2.25,0,goalz/2.25)
|
||||
acceleration = vector.new(goalx,0,goalz)
|
||||
player:add_player_velocity(acceleration)
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user