From 61e812e40a963bcc4492be4df02957891629931a Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 2 Apr 2021 21:40:04 -0400 Subject: [PATCH 1/2] Add in manual interpolation into the item magnet --- mods/ENTITIES/mcl_item_entity/init.lua | 27 +++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index cee2fda69c..a955f928bc 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -9,7 +9,7 @@ item_drop_settings.age = 1.0 --how old a dropped item (_insta_ 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 -item_drop_settings.player_collect_height = 1.0 --added to their pos y value +item_drop_settings.player_collect_height = 1.1 --added to their pos y value item_drop_settings.collection_safety = false --do this to prevent items from flying away on laggy servers item_drop_settings.random_item_velocity = true --this sets random item velocity if velocity is 0 item_drop_settings.drop_single_item = false --if true, the drop control drops 1 item instead of the entire stack, and sneak+drop drops the stack @@ -101,12 +101,13 @@ minetest.register_globalstep(function(dtime) }, true) check_pickup_achievements(object, player) - - object:move_to(checkpos, true) - -- Destroy entity -- This just prevents this section to be run again because object:remove() doesn't remove the item immediately. + object:get_luaentity().target = checkpos object:get_luaentity()._removed = true + + object:set_velocity(vector.multiply(vector.subtract(checkpos, object:get_pos()), 10)) + object:set_acceleration(vector.multiply(vector.subtract(checkpos, object:get_pos()), 20)) end end end @@ -513,12 +514,24 @@ minetest.register_entity(":__builtin:item", { on_step = function(self, dtime) if self._removed then - self.object:set_acceleration({x=0,y=0,z=0}) - self.object:set_velocity({x=0,y=0,z=0}) + + self.object:set_properties({ + physical = false + }) self.collection_age = self.collection_age + dtime - if self.collection_age > 0.15 then + if not self.target then self.object:remove() + else + local pos = self.object:get_pos() + + self.object:set_acceleration(vector.multiply(vector.subtract(self.target, pos), 20)) + self.object:set_velocity(vector.multiply(vector.subtract(self.target, pos), 10)) + + if self.collection_age >= 0.3 or vector.distance(pos, self.target) <= 0.08 then + self.object:remove() + end end + return end self.age = self.age + dtime From 1cbd3a998da0014cf14fd746f3e37980f5c93272 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 2 Apr 2021 21:50:47 -0400 Subject: [PATCH 2/2] Use manual move_to to account for move_to interpolation issues --- mods/ENTITIES/mcl_item_entity/init.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index a955f928bc..582690ea78 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -106,8 +106,8 @@ minetest.register_globalstep(function(dtime) object:get_luaentity().target = checkpos object:get_luaentity()._removed = true - object:set_velocity(vector.multiply(vector.subtract(checkpos, object:get_pos()), 10)) - object:set_acceleration(vector.multiply(vector.subtract(checkpos, object:get_pos()), 20)) + object:set_velocity({x=0,y=0,z=0}) + object:set_acceleration({x=0,y=0,z=0}) end end end @@ -278,8 +278,6 @@ function minetest.handle_node_drops(pos, drops, digger) obj:get_luaentity().age = item_drop_settings.dug_buffer obj:get_luaentity()._insta_collect = false - - print(obj:get_luaentity().age) end end end @@ -518,16 +516,20 @@ minetest.register_entity(":__builtin:item", { self.object:set_properties({ physical = false }) + + self.object:set_velocity({x=0,y=0,z=0}) + self.object:set_acceleration({x=0,y=0,z=0}) + self.collection_age = self.collection_age + dtime + if not self.target then self.object:remove() else local pos = self.object:get_pos() - self.object:set_acceleration(vector.multiply(vector.subtract(self.target, pos), 20)) - self.object:set_velocity(vector.multiply(vector.subtract(self.target, pos), 10)) + self.object:move_to(vector.add(pos, vector.multiply(vector.subtract(self.target, pos), 0.5))) - if self.collection_age >= 0.3 or vector.distance(pos, self.target) <= 0.08 then + if self.collection_age >= 1 or vector.distance(pos, self.target) <= 0.06 then self.object:remove() end end