From 18d7be4a4f3b0215f306dc95da4486cf8b3fc288 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Sat, 3 Apr 2021 00:42:20 -0400 Subject: [PATCH 1/7] More fixes to item collection on laggy servers --- mods/ENTITIES/mcl_item_entity/init.lua | 88 +++++++++++--------------- 1 file changed, 38 insertions(+), 50 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index a05bb1ffd..cee2fda69 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -4,6 +4,7 @@ local mcl_item_entity = {} --basic settings 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.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! @@ -74,69 +75,50 @@ local disable_physics = function(object, luaentity, ignore_check, reset_movement end end ---this is a 0.2 second tick globally across all players -local item_check_ticker = 0 minetest.register_globalstep(function(dtime) - item_check_ticker = item_check_ticker + dtime - if item_check_ticker >= 0.2 then - item_check_ticker = 0 + for _,player in pairs(minetest.get_connected_players()) do + if player:get_hp() > 0 or not minetest.settings:get_bool("enable_damage") then + local pos = player:get_pos() + local inv = player:get_inventory() + local checkpos = {x=pos.x,y=pos.y + item_drop_settings.player_collect_height,z=pos.z} - for _,player in pairs(minetest.get_connected_players()) do - if player:get_hp() > 0 or not minetest.settings:get_bool("enable_damage") then - local pos = player:get_pos() - local inv = player:get_inventory() - local checkpos = {x=pos.x,y=pos.y + item_drop_settings.player_collect_height,z=pos.z} + --magnet and collection + for _,object in pairs(minetest.get_objects_inside_radius(checkpos, item_drop_settings.xp_radius_magnet)) do + if not object:is_player() and vector.distance(checkpos, object:get_pos()) < item_drop_settings.radius_magnet and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" and object:get_luaentity()._magnet_timer and (object:get_luaentity()._insta_collect or (object:get_luaentity().age > item_drop_settings.age)) then - --magnet and collection - for _,object in pairs(minetest.get_objects_inside_radius(checkpos, item_drop_settings.xp_radius_magnet)) do - if not object:is_player() and vector.distance(checkpos, object:get_pos()) < item_drop_settings.radius_magnet and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" and object:get_luaentity()._magnet_timer and (object:get_luaentity()._insta_collect or (object:get_luaentity().age > item_drop_settings.age)) then - object:get_luaentity()._magnet_timer = object:get_luaentity()._magnet_timer + dtime - local collected = false - if object:get_luaentity()._magnet_timer >= 0 and object:get_luaentity()._magnet_timer < item_drop_settings.magnet_time and inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then + if object:get_luaentity()._magnet_timer >= 0 and object:get_luaentity()._magnet_timer < item_drop_settings.magnet_time and inv and inv:room_for_item("main", ItemStack(object:get_luaentity().itemstring)) then - -- Collection - if not object:get_luaentity()._removed then - -- Ignore if itemstring is not set yet - if object:get_luaentity().itemstring ~= "" then - inv:add_item("main", ItemStack(object:get_luaentity().itemstring)) - minetest.sound_play("item_drop_pickup", { - pos = pos, - max_hear_distance = 16, - gain = 1.0, - }, true) - check_pickup_achievements(object, player) + -- Collection + if not object:get_luaentity()._removed then + -- Ignore if itemstring is not set yet + if object:get_luaentity().itemstring ~= "" then + inv:add_item("main", ItemStack(object:get_luaentity().itemstring)) + minetest.sound_play("item_drop_pickup", { + pos = pos, + max_hear_distance = 16, + gain = 1.0, + }, true) + check_pickup_achievements(object, player) - object:move_to(checkpos, false) + 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()._removed = true - - collected = true - end + -- Destroy entity + -- This just prevents this section to be run again because object:remove() doesn't remove the item immediately. + object:get_luaentity()._removed = true end end - - if not collected then - if object:get_luaentity()._magnet_timer > 1 then - object:get_luaentity()._magnet_timer = -item_drop_settings.magnet_time - object:get_luaentity()._magnet_active = false - elseif object:get_luaentity()._magnet_timer < 0 then - object:get_luaentity()._magnet_timer = object:get_luaentity()._magnet_timer + dtime - end - end - - elseif not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "mcl_experience:orb" then - local entity = object:get_luaentity() - entity.collector = player:get_player_name() - entity.collected = true - end - end + elseif not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "mcl_experience:orb" then + local entity = object:get_luaentity() + entity.collector = player:get_player_name() + entity.collected = true + + end end + end end end) @@ -291,6 +273,12 @@ function minetest.handle_node_drops(pos, drops, digger) z = -z end obj:set_velocity({x=1/x, y=obj:get_velocity().y, z=1/z}) + + obj:get_luaentity().age = item_drop_settings.dug_buffer + + obj:get_luaentity()._insta_collect = false + + print(obj:get_luaentity().age) end end end From 61e812e40a963bcc4492be4df02957891629931a Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 2 Apr 2021 21:40:04 -0400 Subject: [PATCH 2/7] 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 cee2fda69..a955f928b 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 3/7] 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 a955f928b..582690ea7 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 From 0840ad98a2f5521599efce69eecdf0003be796be Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 2 Apr 2021 21:57:38 -0400 Subject: [PATCH 4/7] Adjust the item collection magnet even more --- mods/ENTITIES/mcl_item_entity/init.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 582690ea7..acd714d19 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.1 --added to their pos y value +item_drop_settings.player_collect_height = 0.8 --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 @@ -527,9 +527,9 @@ minetest.register_entity(":__builtin:item", { else local pos = self.object:get_pos() - self.object:move_to(vector.add(pos, vector.multiply(vector.subtract(self.target, pos), 0.5))) + self.object:move_to(vector.add(pos, vector.multiply(vector.subtract(self.target, pos), 0.75))) - if self.collection_age >= 1 or vector.distance(pos, self.target) <= 0.06 then + if self.collection_age >= 1 or vector.distance(pos, self.target) <= 0.07 then self.object:remove() end end From 844db8aa7b6fb745a5c9040e4c0b2b7a2b65cb64 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 2 Apr 2021 22:02:19 -0400 Subject: [PATCH 5/7] Revert to previous style of interpolated move_to with tweaks --- mods/ENTITIES/mcl_item_entity/init.lua | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index acd714d19..9184b50bd 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -108,6 +108,15 @@ minetest.register_globalstep(function(dtime) object:set_velocity({x=0,y=0,z=0}) object:set_acceleration({x=0,y=0,z=0}) + + object:move_to(checkpos) + + minetest.after(0.25, function() + --safety check + if object and object:get_luaentity() then + object:remove() + end + end) end end end @@ -512,28 +521,11 @@ minetest.register_entity(":__builtin:item", { on_step = function(self, dtime) if self._removed then - 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:move_to(vector.add(pos, vector.multiply(vector.subtract(self.target, pos), 0.75))) - - if self.collection_age >= 1 or vector.distance(pos, self.target) <= 0.07 then - self.object:remove() - end - end - return end self.age = self.age + dtime From da3d5025a8a1d37ca6fb5eebc2d414a0c1639f45 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Sat, 3 Apr 2021 01:22:13 -0400 Subject: [PATCH 6/7] Update tick rate to 0.05 ticks per second (20 tps) --- minetest.conf | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/minetest.conf b/minetest.conf index e122db7b3..1788cf992 100644 --- a/minetest.conf +++ b/minetest.conf @@ -1,5 +1,8 @@ # This is a game specific minetest.conf file, do not edit +# If any of these settings are set in your minetest.conf file in .minetest (Linux) or in the root directory of the game (Run in place/Windows) +# They will override these settings + # Basic game rules time_speed = 72 @@ -33,7 +36,7 @@ mgvalleys_spflags = noaltitude_chill,noaltitude_dry,nohumid_rivers,vary_river_de keepInventory = false # Performance settings -# dedicated_server_step = 0.001 +dedicated_server_step = 0.05 #tick rate # abm_interval = 0.25 # max_objects_per_block = 4096 # max_packets_per_iteration = 10096 From b14bc2182946cfdab4716afd7ed46904611629b0 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Sat, 3 Apr 2021 05:26:08 +0000 Subject: [PATCH 7/7] Minor update to home directory warning in minetest.conf --- minetest.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/minetest.conf b/minetest.conf index 1788cf992..223587f4d 100644 --- a/minetest.conf +++ b/minetest.conf @@ -1,6 +1,6 @@ # This is a game specific minetest.conf file, do not edit -# If any of these settings are set in your minetest.conf file in .minetest (Linux) or in the root directory of the game (Run in place/Windows) +# If any of these settings are set in your minetest.conf file in ~/.minetest (Linux) or in the root directory of the game (Run in place/Windows) # They will override these settings # Basic game rules