From ddbc3353a25eaeb110b862c6afb1e4fb93b9fb29 Mon Sep 17 00:00:00 2001 From: Gustavo Ramos Rehermann Date: Wed, 9 Feb 2022 02:44:39 -0300 Subject: [PATCH] Change item on flowing water physics adding momentum and drag (experimental) --- mods/ENTITIES/mcl_item_entity/init.lua | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 678f8e2b7..9f50f9806 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -27,6 +27,8 @@ local mcl_item_entity = {} local item_drop_settings = {} --settings table item_drop_settings.dug_buffer = 0.65 -- the warm up period before a dug item can be collected item_drop_settings.age = 1.0 --how old a dropped item (_insta_collect==false) has to be before collecting +item_drop_settings.fluid_flow_rate = 1.39 --the speed of a flowing fluid, used when computing push and drag forces of water on items; default is tuned to Minecraft +item_drop_settings.fluid_drag = 0.8 --how much drag water has on items (how quickly an item's motion will settle onto the water's flow speed) item_drop_settings.radius_magnet = 2.0 --radius of item magnet. MUST BE LARGER THAN radius_collect! item_drop_settings.xp_radius_magnet = 7.25 --radius of xp magnet. MUST BE LARGER THAN radius_collect! item_drop_settings.radius_collect = 0.2 --radius of collection @@ -778,11 +780,26 @@ minetest.register_entity(":__builtin:item", { -- Just to make sure we don't manipulate the speed for no reason if vec.x ~= 0 or vec.y ~= 0 or vec.z ~= 0 then -- Minecraft Wiki: Flowing speed is "about 1.39 meters per second" - local f = 1.39 - -- Set new item moving speed into the direciton of the liquid - local newv = vector.multiply(vec, f) + local f = item_drop_settings.fluid_flow_rate --1.39 + + -- Apply the force of the flowing liquid onto the item's velocity + local newv = vector.multiply(vec, f) self.object:set_acceleration({x = 0, y = 0, z = 0}) - self.object:set_velocity({x = newv.x, y = -0.22, z = newv.z}) + + local oldvel = self.object:get_velocity() -- v is vector, vel is velocity + + -- drag + newv.x = newv.x - (oldvel.x - newv.x) * item_drop_settings.fluid_drag + newv.y = newv.y - (oldvel.y - newv.y) * item_drop_settings.fluid_drag + newv.z = newv.z - (oldvel.z - newv.z) * item_drop_settings.fluid_drag + + newv.y = newv.y + -0.22 -- (keep slight downward thrust from previous version of code) + -- NOTE: is there any particular reason we have this, anyway? + -- since fluid drag is now on, we could as well just + -- apply gravity here; drag will slow down the fall + -- realistically + + self.object:set_velocity({x = oldvel.x + newv.x, y = oldvel.y + newv.y, z = oldvel.z + newv.z}) self.physical_state = true self._flowing = true