diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index f323fa9f9..6b7fc2cf2 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -89,7 +89,6 @@ local function enable_physics(object, luaentity, ignore_check) object:set_properties({ physical = true }) - object:set_acceleration(vector.new(0, -get_gravity(), 0)) end end @@ -863,7 +862,6 @@ minetest.register_entity(":__builtin:item", { self.object:set_armor_groups({ immortal = 1 }) -- self.object:set_velocity(vector.new(0, 2, 0)) - self.object:set_acceleration(vector.new(0, -get_gravity(), 0)) self:set_item(self.itemstring) end, diff --git a/mods/ENVIRONMENT/mcl_physics/api.lua b/mods/ENVIRONMENT/mcl_physics/api.lua index 6453cdac4..86a46ad9b 100644 --- a/mods/ENVIRONMENT/mcl_physics/api.lua +++ b/mods/ENVIRONMENT/mcl_physics/api.lua @@ -22,11 +22,11 @@ function mod.get_environment_effect(pos, vel, staticdata, mass) end end - if vector.length(v) > 0.01 or vector.length(a) > 0.01 then - return v,a - else - return -- nil,nil - end + -- 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 end 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 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 self._flowing = data.flowing diff --git a/mods/ENVIRONMENT/mcl_physics/init.lua b/mods/ENVIRONMENT/mcl_physics/init.lua index 4652466b1..6ba227b86 100644 --- a/mods/ENVIRONMENT/mcl_physics/init.lua +++ b/mods/ENVIRONMENT/mcl_physics/init.lua @@ -5,36 +5,46 @@ mcl_physics = mod dofile(modpath.."/api.lua") +-- Flowing water -- TODO: move to Flowlib local FLOW_SPEED = 1.39 +local BOUANCY = 3 mod.register_environment_effect(function(pos, vel, staticdata) -- Get the node and node definition - local node = minetest.get_node_or_nil(pos) - if not node then return end - local nodedef = minetest.registered_nodes[node.name] - if not nodedef then return end + local node = minetest.get_node_or_nil(pos); if not node 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 local is_flowing = (nodedef.liquidtype == "flowing") staticdata.flowing = is_flowing - if not is_flowing then - -- 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 + if not is_flowing then return end -- Get liquid flow direction local vec = vector.multiply(flowlib.quick_flow(pos, node), FLOW_SPEED) return vector.new(vec.x, -0.22, vec.z),nil 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 mod.register_environment_effect(function(pos, vel, staticdata) local pos_r = vector.round(pos)