mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-26 04:21:07 +01:00
Remove hardcoded gravity from item entity, fix bouancy in environmental effects
This commit is contained in:
parent
5f233819f8
commit
23e2da6a41
3 changed files with 34 additions and 23 deletions
|
@ -89,7 +89,6 @@ local function enable_physics(object, luaentity, ignore_check)
|
||||||
object:set_properties({
|
object:set_properties({
|
||||||
physical = true
|
physical = true
|
||||||
})
|
})
|
||||||
object:set_acceleration(vector.new(0, -get_gravity(), 0))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -863,7 +862,6 @@ minetest.register_entity(":__builtin:item", {
|
||||||
|
|
||||||
self.object:set_armor_groups({ immortal = 1 })
|
self.object:set_armor_groups({ immortal = 1 })
|
||||||
-- self.object:set_velocity(vector.new(0, 2, 0))
|
-- self.object:set_velocity(vector.new(0, 2, 0))
|
||||||
self.object:set_acceleration(vector.new(0, -get_gravity(), 0))
|
|
||||||
self:set_item(self.itemstring)
|
self:set_item(self.itemstring)
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
|
@ -22,11 +22,11 @@ function mod.get_environment_effect(pos, vel, staticdata, mass)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if vector.length(v) > 0.01 or vector.length(a) > 0.01 then
|
-- Disable small effects
|
||||||
|
if vector.length(v) < 0.01 then v = nil end
|
||||||
|
if vector.length(a) < 0.01 then a = nil end
|
||||||
|
|
||||||
return v,a
|
return v,a
|
||||||
else
|
|
||||||
return -- nil,nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function mod.apply_entity_environmental_physics(self, data)
|
function mod.apply_entity_environmental_physics(self, data)
|
||||||
|
@ -36,6 +36,9 @@ function mod.apply_entity_environmental_physics(self, data)
|
||||||
local vel = self.object:get_velocity()
|
local vel = self.object:get_velocity()
|
||||||
local new_velocity,new_acceleration = mcl_physics.get_environment_effect(pos, vel, data, 1)
|
local new_velocity,new_acceleration = mcl_physics.get_environment_effect(pos, vel, data, 1)
|
||||||
|
|
||||||
|
if new_velocity then print("new_velocity="..tostring(new_velocity)) end
|
||||||
|
if new_acceleration then print("new_acceleration="..tostring(new_acceleration)) end
|
||||||
|
|
||||||
-- Update entity states
|
-- Update entity states
|
||||||
self._flowing = data.flowing
|
self._flowing = data.flowing
|
||||||
|
|
||||||
|
|
|
@ -5,36 +5,46 @@ mcl_physics = mod
|
||||||
|
|
||||||
dofile(modpath.."/api.lua")
|
dofile(modpath.."/api.lua")
|
||||||
|
|
||||||
|
-- Flowing water
|
||||||
-- TODO: move to Flowlib
|
-- TODO: move to Flowlib
|
||||||
local FLOW_SPEED = 1.39
|
local FLOW_SPEED = 1.39
|
||||||
|
local BOUANCY = 3
|
||||||
mod.register_environment_effect(function(pos, vel, staticdata)
|
mod.register_environment_effect(function(pos, vel, staticdata)
|
||||||
-- Get the node and node definition
|
-- Get the node and node definition
|
||||||
local node = minetest.get_node_or_nil(pos)
|
local node = minetest.get_node_or_nil(pos); if not node then return end
|
||||||
if not node then return end
|
local nodedef = minetest.registered_nodes[node.name]; if not nodedef then return end
|
||||||
local nodedef = minetest.registered_nodes[node.name]
|
|
||||||
if not nodedef then return end
|
|
||||||
|
|
||||||
-- Make sure we are in a liquid before continuing
|
-- Make sure we are in a liquid before continuing
|
||||||
local is_flowing = (nodedef.liquidtype == "flowing")
|
local is_flowing = (nodedef.liquidtype == "flowing")
|
||||||
staticdata.flowing = is_flowing
|
staticdata.flowing = is_flowing
|
||||||
if not is_flowing then
|
if not is_flowing then return end
|
||||||
-- Apply decelleration if the entity moved from flowing water to
|
|
||||||
-- stationary water
|
|
||||||
if nodedef.liquidtype == "source" then
|
|
||||||
return nil,vector.new(
|
|
||||||
0 - vel.x * 0.9,
|
|
||||||
3 - vel.y * 0.9,
|
|
||||||
0 - vel.z * 0.9
|
|
||||||
)
|
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Get liquid flow direction
|
-- Get liquid flow direction
|
||||||
local vec = vector.multiply(flowlib.quick_flow(pos, node), FLOW_SPEED)
|
local vec = vector.multiply(flowlib.quick_flow(pos, node), FLOW_SPEED)
|
||||||
return vector.new(vec.x, -0.22, vec.z),nil
|
return vector.new(vec.x, -0.22, vec.z),nil
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Simple gravity and bouency
|
||||||
|
mod.register_environment_effect(function(pos, vel, staticdata)
|
||||||
|
-- Get the node and node definition
|
||||||
|
local node = minetest.get_node_or_nil(pos);
|
||||||
|
local nodedef = nil
|
||||||
|
if node then nodedef = minetest.registered_nodes[node.name] end
|
||||||
|
|
||||||
|
if nodedef and nodedef.liquidtype == "source" then
|
||||||
|
-- Apply decceleration and bouancy if the entity moved from flowing water to
|
||||||
|
-- stationary water
|
||||||
|
return nil,vector.new(
|
||||||
|
0 - vel.x * 0.9,
|
||||||
|
BOUANCY - vel.y * 0.9,
|
||||||
|
0 - vel.z * 0.9
|
||||||
|
)
|
||||||
|
else
|
||||||
|
local gravity = tonumber(minetest.settings:get("movement_gravity")) or 9.81
|
||||||
|
return nil,vector.new(0,-gravity,0)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
-- Node effects
|
-- Node effects
|
||||||
mod.register_environment_effect(function(pos, vel, staticdata)
|
mod.register_environment_effect(function(pos, vel, staticdata)
|
||||||
local pos_r = vector.round(pos)
|
local pos_r = vector.round(pos)
|
||||||
|
|
Loading…
Reference in a new issue