From 9daac0aff16e5d389ce17af04bec214557204b64 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 22 Jul 2022 15:34:58 +1000 Subject: [PATCH 01/12] make items float in water sources --- mods/ENTITIES/mcl_item_entity/init.lua | 32 ++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 260b71286..f145ef6eb 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -666,6 +666,7 @@ minetest.register_entity(":__builtin:item", { -- Destroy item in lava, fire or special nodes local nn = node.name + local is_in_water = (minetest.get_item_group(nn, "water") ~= 0) local def = minetest.registered_nodes[nn] local lg = minetest.get_item_group(nn, "lava") local fg = minetest.get_item_group(nn, "fire") @@ -695,7 +696,7 @@ minetest.register_entity(":__builtin:item", { end -- Push item out when stuck inside solid opaque node - if def and def.walkable and def.groups and def.groups.opaque == 1 then + if not is_in_water and def and def.walkable and def.groups and def.groups.opaque == 1 then local shootdir local cx = (p.x % 1) - 0.5 local cz = (p.z % 1) - 0.5 @@ -775,8 +776,10 @@ minetest.register_entity(":__builtin:item", { return end + local is_floating_on_water = false -- Move item around on flowing liquids; add 'source' check to allow items to continue flowing a bit in the source block of flowing water. - if def and def.liquidtype == "flowing" or def.liquidtype == "source" then + if def and (def.liquidtype == "flowing" or def.liquidtype == "source") then + self._flowing = true --[[ Get flowing direction (function call from flowlib), if there's a liquid. NOTE: According to Qwertymine, flowlib.quickflow is only reliable for liquids with a flowing distance of 7. @@ -798,10 +801,27 @@ minetest.register_entity(":__builtin:item", { }) return end - elseif self._flowing == true then + if is_in_water and def.liquidtype == "source" then + local cur_vec = self.object:get_velocity() + -- apply some acceleration in the opposite direction so it doesn't slide forever + local vec = { + x = 0 -cur_vec.x*0.9, + y = 3 -cur_vec.y*0.9, + z = 0 -cur_vec.z*0.9} + self.object:set_acceleration(vec) + if self.physical_state ~= false or self._flowing ~= true then + self.physical_state = true + self._flowing = true + self.object:set_properties({ + physical = true + }) + end + end + elseif self._flowing == true and not is_in_water then -- Disable flowing physics if not on/in flowing liquid self._flowing = false - enable_physics(self.object, self, true) + local pos = self.object:get_pos() + disable_physics(self.object, self, false, false) return end @@ -822,7 +842,9 @@ minetest.register_entity(":__builtin:item", { end end end - disable_physics(self.object, self) + if not is_in_water then + disable_physics(self.object, self) + end end else if self._magnet_active == false then From 70aca4c3cae1b3060277d226b557f4ce8dd6490e Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 22 Jul 2022 16:19:50 +1000 Subject: [PATCH 02/12] fix infinite bobbing --- mods/ENTITIES/mcl_item_entity/init.lua | 35 ++++++++++++++++++++------ 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index f145ef6eb..8e808610a 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -652,6 +652,22 @@ minetest.register_entity(":__builtin:item", { }) end + local nn = node.name + local is_in_water = (minetest.get_item_group(nn, "water") ~= 0) + local nn_above = minetest.get_node({x=p.x, y=p.y+0.1, z=p.z}).name + -- make sure it's more or less stationary and is at water level + local sleep_threshold = 0.3 + local is_stationary = math.abs(self.object:get_velocity().x) < sleep_threshold + and math.abs(self.object:get_velocity().y) < sleep_threshold + and math.abs(self.object:get_velocity().z) < sleep_threshold + local is_floating = (is_stationary + and is_in_water + and nn_above == "air") + if is_floating then + self.object:set_velocity({x = 0, y = 0, z = 0}) + self.object:set_acceleration({x = 0, y = 0, z = 0}) + disable_physics(self.object, self) + end -- If no collector was found for a long enough time, declare the magnet as disabled if self._magnet_active and (self._collector_timer == nil or (self._collector_timer > item_drop_settings.magnet_time)) then self._magnet_active = false @@ -665,8 +681,7 @@ minetest.register_entity(":__builtin:item", { end -- Destroy item in lava, fire or special nodes - local nn = node.name - local is_in_water = (minetest.get_item_group(nn, "water") ~= 0) + local def = minetest.registered_nodes[nn] local lg = minetest.get_item_group(nn, "lava") local fg = minetest.get_item_group(nn, "fire") @@ -737,9 +752,9 @@ minetest.register_entity(":__builtin:item", { local newv = vector.multiply(shootdir, 3) self.object:set_acceleration({x = 0, y = 0, z = 0}) self.object:set_velocity(newv) - disable_physics(self.object, self, false, false) + if shootdir.y == 0 then self._force = newv p.x = math.floor(p.x) @@ -776,9 +791,8 @@ minetest.register_entity(":__builtin:item", { return end - local is_floating_on_water = false -- Move item around on flowing liquids; add 'source' check to allow items to continue flowing a bit in the source block of flowing water. - if def and (def.liquidtype == "flowing" or def.liquidtype == "source") then + if def and not is_floating and (def.liquidtype == "flowing" or def.liquidtype == "source") then self._flowing = true --[[ Get flowing direction (function call from flowlib), if there's a liquid. @@ -809,6 +823,12 @@ minetest.register_entity(":__builtin:item", { y = 3 -cur_vec.y*0.9, z = 0 -cur_vec.z*0.9} self.object:set_acceleration(vec) + -- slow down the item in water + local vel = self.object:get_velocity() + if vel.y < 0 then + vel.y = vel.y * 0.9 + end + self.object:set_velocity(vel) if self.physical_state ~= false or self._flowing ~= true then self.physical_state = true self._flowing = true @@ -817,7 +837,7 @@ minetest.register_entity(":__builtin:item", { }) end end - elseif self._flowing == true and not is_in_water then + elseif self._flowing == true and not is_in_water and not is_floating then -- Disable flowing physics if not on/in flowing liquid self._flowing = false local pos = self.object:get_pos() @@ -847,10 +867,11 @@ minetest.register_entity(":__builtin:item", { end end else - if self._magnet_active == false then + if self._magnet_active == false and not is_floating then enable_physics(self.object, self) end end + end, -- Note: on_punch intentionally left out. The player should *not* be able to collect items by punching From dc6fbeeafd3d18ca187b9c2f8bab0e643ecff65c Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 22 Jul 2022 16:55:42 +1000 Subject: [PATCH 03/12] items will go into sleep mode even if there's a block above as long as it's not a liquid --- mods/ENTITIES/mcl_item_entity/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 8e808610a..60e0a7391 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -662,7 +662,7 @@ minetest.register_entity(":__builtin:item", { and math.abs(self.object:get_velocity().z) < sleep_threshold local is_floating = (is_stationary and is_in_water - and nn_above == "air") + and (minetest.get_item_group(nn_above, "liquid") == 0)) if is_floating then self.object:set_velocity({x = 0, y = 0, z = 0}) self.object:set_acceleration({x = 0, y = 0, z = 0}) From 65fc5b6f28d340a610ea8bf576a6ae77650f8117 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 22 Jul 2022 22:38:36 +1000 Subject: [PATCH 04/12] droppers and dispensers actually shoot items out, items will merge with eachother even when floating --- mods/ENTITIES/mcl_item_entity/init.lua | 33 ++++++--------------- mods/ITEMS/REDSTONE/mcl_dispensers/init.lua | 22 ++++++++++++-- mods/ITEMS/REDSTONE/mcl_droppers/init.lua | 11 ++++++- 3 files changed, 39 insertions(+), 27 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 60e0a7391..0d27d91a0 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -464,24 +464,6 @@ minetest.register_entity(":__builtin:item", { } self.object:set_properties(prop) if item_drop_settings.random_item_velocity == true then - minetest.after(0, function(self) - if not self or not self.object or not self.object:get_luaentity() then - return - end - local vel = self.object:get_velocity() - if vel and vel.x == 0 and vel.z == 0 then - local x = math.random(1, 5) - if math.random(1,2) == 1 then - x = -x - end - local z = math.random(1, 5) - if math.random(1,2) == 1 then - z = -z - end - local y = math.random(2,4) - self.object:set_velocity({x=1/x, y=y, z=1/z}) - end - end, self) end end, @@ -602,9 +584,9 @@ minetest.register_entity(":__builtin:item", { end -- Merge the remote stack into this one - local pos = object:get_pos() - pos.y = pos.y + ((total_count - count) / max_count) * 0.15 - self.object:move_to(pos) + -- local pos = object:get_pos() + -- pos.y = pos.y + ((total_count - count) / max_count) * 0.15 + -- self.object:move_to(pos) self.age = 0 -- Handle as new entity own_stack:set_count(total_count) @@ -848,9 +830,12 @@ minetest.register_entity(":__builtin:item", { -- If node is not registered or node is walkably solid and resting on nodebox local nn = minetest.get_node({x=p.x, y=p.y-0.5, z=p.z}).name local v = self.object:get_velocity() + local is_on_floor = (minetest.registered_nodes[nn].walkable + and not minetest.registered_nodes[nn].groups.slippery and v.y == 0) - if not minetest.registered_nodes[nn] or minetest.registered_nodes[nn].walkable and not minetest.registered_nodes[nn].groups.slippery and v.y == 0 then - if self.physical_state then + if not minetest.registered_nodes[nn] + or is_floating or is_on_floor then + if true then local own_stack = ItemStack(self.object:get_luaentity().itemstring) -- Merge with close entities of the same item for _, object in pairs(minetest.get_objects_inside_radius(p, 0.8)) do @@ -867,7 +852,7 @@ minetest.register_entity(":__builtin:item", { end end else - if self._magnet_active == false and not is_floating then + if self._magnet_active == false and not is_floating and not is_in_water then enable_physics(self.object, self) end end diff --git a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua index aa20fc813..94f0fcd8d 100644 --- a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua @@ -252,7 +252,16 @@ local dispenserdef = { elseif inv:room_for_item("main", od_ret) then inv:add_item("main", od_ret) else - minetest.add_item(droppos, dropitem) + local pos_variation = 100 + droppos = { + x = droppos.x + math.random(-pos_variation, pos_variation) / 1000, + y = droppos.y + math.random(-pos_variation, pos_variation) / 1000, + z = droppos.z + math.random(-pos_variation, pos_variation) / 1000, + } + local item_entity = minetest.add_item(droppos, dropitem) + local drop_vel = vector.subtract(droppos, pos) + local speed = 3 + item_entity:set_velocity(drop_vel * speed) end else stack:take_item() @@ -260,7 +269,16 @@ local dispenserdef = { end else -- Drop item otherwise - minetest.add_item(droppos, dropitem) + local pos_variation = 100 + droppos = { + x = droppos.x + math.random(-pos_variation, pos_variation) / 1000, + y = droppos.y + math.random(-pos_variation, pos_variation) / 1000, + z = droppos.z + math.random(-pos_variation, pos_variation) / 1000, + } + local item_entity = minetest.add_item(droppos, dropitem) + local drop_vel = vector.subtract(droppos, pos) + local speed = 3 + item_entity:set_velocity(drop_vel * speed) stack:take_item() inv:set_stack("main", stack_id, stack) end diff --git a/mods/ITEMS/REDSTONE/mcl_droppers/init.lua b/mods/ITEMS/REDSTONE/mcl_droppers/init.lua index abb351091..6dac4495f 100644 --- a/mods/ITEMS/REDSTONE/mcl_droppers/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_droppers/init.lua @@ -134,7 +134,16 @@ local dropperdef = { -- No container? if not dropped and not dropnodedef.groups.container then -- Drop item normally - minetest.add_item(droppos, dropitem) + local pos_variation = 100 + droppos = { + x = droppos.x + math.random(-pos_variation, pos_variation) / 1000, + y = droppos.y + math.random(-pos_variation, pos_variation) / 1000, + z = droppos.z + math.random(-pos_variation, pos_variation) / 1000, + } + local item_entity = minetest.add_item(droppos, dropitem) + local drop_vel = vector.subtract(droppos, pos) + local speed = 3 + item_entity:set_velocity(drop_vel * speed) stack:take_item() inv:set_stack("main", stack_id, stack) end From eeace260fe304dbb1ddef85d8fafaf3de3d91de2 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 22 Jul 2022 22:45:22 +1000 Subject: [PATCH 05/12] don't disable physics if you've already disabled it --- mods/ENTITIES/mcl_item_entity/init.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 0d27d91a0..aeb997d44 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -645,7 +645,8 @@ minetest.register_entity(":__builtin:item", { local is_floating = (is_stationary and is_in_water and (minetest.get_item_group(nn_above, "liquid") == 0)) - if is_floating then + + if is_floating and self.physical_state == true then self.object:set_velocity({x = 0, y = 0, z = 0}) self.object:set_acceleration({x = 0, y = 0, z = 0}) disable_physics(self.object, self) From 58d80e5e9caba9b329700bf888bed3417dbb3acf Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 22 Jul 2022 23:06:35 +1000 Subject: [PATCH 06/12] netherite items (except armour) will float in lava and not burn --- mods/ENTITIES/mcl_item_entity/init.lua | 4 ++-- mods/ITEMS/mcl_farming/hoes.lua | 2 +- mods/ITEMS/mcl_nether/init.lua | 6 +++--- mods/ITEMS/mcl_tools/init.lua | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index aeb997d44..2d8ec334d 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -635,7 +635,7 @@ minetest.register_entity(":__builtin:item", { end local nn = node.name - local is_in_water = (minetest.get_item_group(nn, "water") ~= 0) + local is_in_water = (minetest.get_item_group(nn, "liquid") ~= 0) local nn_above = minetest.get_node({x=p.x, y=p.y+0.1, z=p.z}).name -- make sure it's more or less stationary and is at water level local sleep_threshold = 0.3 @@ -671,7 +671,7 @@ minetest.register_entity(":__builtin:item", { local dg = minetest.get_item_group(nn, "destroys_items") if (def and (lg ~= 0 or fg ~= 0 or dg == 1)) then --Wait 2 seconds to allow mob drops to be cooked, & picked up instead of instantly destroyed. - if self.age > 2 then + if self.age > 2 and minetest.get_item_group(self.itemstring, "fire_immune") == 0 then if dg ~= 2 then minetest.sound_play("builtin_item_lava", {pos = self.object:get_pos(), gain = 0.5}) end diff --git a/mods/ITEMS/mcl_farming/hoes.lua b/mods/ITEMS/mcl_farming/hoes.lua index e023f123e..72d8f7b7a 100644 --- a/mods/ITEMS/mcl_farming/hoes.lua +++ b/mods/ITEMS/mcl_farming/hoes.lua @@ -285,7 +285,7 @@ minetest.register_tool("mcl_farming:hoe_netherite", { inventory_image = "farming_tool_netheritehoe.png", wield_scale = mcl_vars.tool_wield_scale, on_place = hoe_on_place_function(uses.netherite), - groups = { tool=1, hoe=1, enchantability=10 }, + groups = { tool=1, hoe=1, enchantability=10, fire_immune=1 }, tool_capabilities = { full_punch_interval = 0.25, damage_groups = { fleshy = 4, }, diff --git a/mods/ITEMS/mcl_nether/init.lua b/mods/ITEMS/mcl_nether/init.lua index f4a241cee..5536d3d29 100644 --- a/mods/ITEMS/mcl_nether/init.lua +++ b/mods/ITEMS/mcl_nether/init.lua @@ -71,7 +71,7 @@ minetest.register_node("mcl_nether:netheriteblock", { stack_max = 64, tiles = {"mcl_nether_netheriteblock.png"}, is_ground_content = true, - groups = {pickaxey=4, building_block=1, material_stone=1, xp = 0}, + groups = { pickaxey=4, building_block=1, material_stone=1, xp = 0, fire_immune=1 }, drop = "mcl_nether:netheriteblock", sounds = mcl_sounds.node_sound_stone_defaults(), _mcl_blast_resistance = 1200, @@ -285,7 +285,7 @@ minetest.register_craftitem("mcl_nether:netherite_scrap", { _doc_items_longdesc = S("Netherite scrap is a crafting ingredient for netherite ingots."), inventory_image = "mcl_nether_netherite_scrap.png", stack_max = 64, - groups = { craftitem = 1 }, + groups = { craftitem = 1, fire_immune=1 }, }) minetest.register_craftitem("mcl_nether:netherite_ingot", { @@ -293,7 +293,7 @@ minetest.register_craftitem("mcl_nether:netherite_ingot", { _doc_items_longdesc = S("Netherite ingots can be used with a smithing table to upgrade items to netherite."), inventory_image = "mcl_nether_netherite_ingot.png", stack_max = 64, - groups = { craftitem = 1 }, + groups = { craftitem = 1, fire_immune=1 }, }) minetest.register_craftitem("mcl_nether:netherbrick", { diff --git a/mods/ITEMS/mcl_tools/init.lua b/mods/ITEMS/mcl_tools/init.lua index c2192c968..6111d7b91 100644 --- a/mods/ITEMS/mcl_tools/init.lua +++ b/mods/ITEMS/mcl_tools/init.lua @@ -184,7 +184,7 @@ minetest.register_tool("mcl_tools:pick_netherite", { _doc_items_longdesc = pickaxe_longdesc, inventory_image = "default_tool_netheritepick.png", wield_scale = wield_scale, - groups = { tool=1, pickaxe=1, dig_speed_class=6, enchantability=10 }, + groups = { tool=1, pickaxe=1, dig_speed_class=6, enchantability=10, fire_immune=1 }, tool_capabilities = { -- 1/1.2 full_punch_interval = 0.83333333, @@ -384,7 +384,7 @@ minetest.register_tool("mcl_tools:shovel_netherite", { _doc_items_usagehelp = shovel_use, inventory_image = "default_tool_netheriteshovel.png", wield_scale = wield_scale, - groups = { tool=1, shovel=1, dig_speed_class=6, enchantability=10 }, + groups = { tool=1, shovel=1, dig_speed_class=6, enchantability=10, fire_immune=1 }, tool_capabilities = { full_punch_interval = 1, max_drop_level=5, @@ -539,7 +539,7 @@ minetest.register_tool("mcl_tools:axe_netherite", { _doc_items_longdesc = axe_longdesc, inventory_image = "default_tool_netheriteaxe.png", wield_scale = wield_scale, - groups = { tool=1, axe=1, dig_speed_class=6, enchantability=10 }, + groups = { tool=1, axe=1, dig_speed_class=6, enchantability=10, fire_immune=1 }, tool_capabilities = { full_punch_interval = 1.0, max_drop_level=5, @@ -664,7 +664,7 @@ minetest.register_tool("mcl_tools:sword_netherite", { _doc_items_longdesc = sword_longdesc, inventory_image = "default_tool_netheritesword.png", wield_scale = wield_scale, - groups = { weapon=1, sword=1, dig_speed_class=5, enchantability=10 }, + groups = { weapon=1, sword=1, dig_speed_class=5, enchantability=10, fire_immune=1 }, tool_capabilities = { full_punch_interval = 0.625, max_drop_level=5, From 65e42845f4a7eb3fa568a63d3e63b6b09ba8ddf2 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 22 Jul 2022 23:18:51 +1000 Subject: [PATCH 07/12] netherite armour no longer burns in lava --- mods/ITEMS/mcl_armor/register.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/mods/ITEMS/mcl_armor/register.lua b/mods/ITEMS/mcl_armor/register.lua index 0f8ef6315..89ff5ca9f 100644 --- a/mods/ITEMS/mcl_armor/register.lua +++ b/mods/ITEMS/mcl_armor/register.lua @@ -100,6 +100,7 @@ mcl_armor.register_set({ legs = 6, feet = 3, }, + groups = { fire_immune=1 }, toughness = 2, craft_material = "mcl_nether:netherite_ingot", sound_equip = "mcl_armor_equip_diamond", From fb28177ff1e1c7e23f437f0ccce3b32515b178c7 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sat, 23 Jul 2022 16:10:52 +1000 Subject: [PATCH 08/12] items will stay put when loaded, items dug by the game will get more initial random velocity, game will no longer apply random velocity twice (?) --- mods/ENTITIES/mcl_item_entity/init.lua | 43 +++++++++++++++++++------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 2d8ec334d..edc12b580 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -318,15 +318,17 @@ function minetest.handle_node_drops(pos, drops, digger) -- Spawn item and apply random speed local obj = minetest.add_item(dpos, drop_item) if obj then - local x = math.random(1, 5) - if math.random(1,2) == 1 then - x = -x - end - local z = math.random(1, 5) - if math.random(1,2) == 1 then - z = -z - end - obj:set_velocity({x=1/x, y=obj:get_velocity().y, z=1/z}) + -- set the velocity multiplier to the stored amount or if the game dug this node, apply a bigger velocity + local v = 1 + if digger and digger:is_player() then v = obj:get_luaentity().random_velocity + else v = 6 end + + local x = math.random(2, 10) / 10 * v + if math.random(0,10) < 5 then x = -x end + local z = math.random(2, 10) / 10 * v + if math.random(0,10) < 5 then z = -z end + local y = math.random(2,4) + obj:set_velocity({x=x, y=y, z=z}) obj:get_luaentity().age = item_drop_settings.dug_buffer @@ -408,6 +410,8 @@ minetest.register_entity(":__builtin:item", { -- Number of seconds this item entity has existed so far age = 0, + random_velocity = 1, + -- How old it has become in the collection animation collection_age = 0, @@ -463,7 +467,23 @@ minetest.register_entity(":__builtin:item", { glow = glow, } self.object:set_properties(prop) - if item_drop_settings.random_item_velocity == true then + if item_drop_settings.random_item_velocity == true and self.age < 2 then + minetest.after(0, function(self) + if not self or not self.object or not self.object:get_luaentity() then + return + end + local vel = self.object:get_velocity() + if vel and vel.x == 0 and vel.z == 0 and self.random_velocity > 0 then + local v = self.random_velocity + local x = math.random(2, 10) / 10 * v + if math.random(0,10) < 5 then x = -x end + local z = math.random(2, 10) / 10 * v + if math.random(0,10) < 5 then z = -z end + local y = math.random(2,4) + self.object:set_velocity({x=x, y=y, z=z}) + end + self.random_velocity = 0 + end, self) end end, @@ -554,7 +574,7 @@ minetest.register_entity(":__builtin:item", { self._forcetimer = 0 self.object:set_armor_groups({immortal = 1}) - self.object:set_velocity({x = 0, y = 2, z = 0}) + -- self.object:set_velocity({x = 0, y = 2, z = 0}) self.object:set_acceleration({x = 0, y = -get_gravity(), z = 0}) self:set_item(self.itemstring) end, @@ -590,6 +610,7 @@ minetest.register_entity(":__builtin:item", { self.age = 0 -- Handle as new entity own_stack:set_count(total_count) + self.random_velocity = 0 self:set_item(own_stack:to_string()) entity._removed = true From 6278fa21d3971719eabf5f97781fbff9fc3d9053 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sat, 23 Jul 2022 16:41:41 +1000 Subject: [PATCH 09/12] Removed an entire block of code that was duplicate and didn't do anything --- mods/ENTITIES/mcl_item_entity/init.lua | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index edc12b580..658fe89c4 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -467,24 +467,6 @@ minetest.register_entity(":__builtin:item", { glow = glow, } self.object:set_properties(prop) - if item_drop_settings.random_item_velocity == true and self.age < 2 then - minetest.after(0, function(self) - if not self or not self.object or not self.object:get_luaentity() then - return - end - local vel = self.object:get_velocity() - if vel and vel.x == 0 and vel.z == 0 and self.random_velocity > 0 then - local v = self.random_velocity - local x = math.random(2, 10) / 10 * v - if math.random(0,10) < 5 then x = -x end - local z = math.random(2, 10) / 10 * v - if math.random(0,10) < 5 then z = -z end - local y = math.random(2,4) - self.object:set_velocity({x=x, y=y, z=z}) - end - self.random_velocity = 0 - end, self) - end end, From 5fc662664f44ab907c438f280742a85e08a0518e Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Sun, 24 Jul 2022 15:59:00 +1000 Subject: [PATCH 10/12] cactus will act as if dug instead of its own hardcoded breaking function --- mods/ENTITIES/mcl_item_entity/init.lua | 38 +++++++++++++++++++------- mods/ITEMS/mcl_core/functions.lua | 4 +-- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 658fe89c4..30e4d828d 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -320,16 +320,12 @@ function minetest.handle_node_drops(pos, drops, digger) if obj then -- set the velocity multiplier to the stored amount or if the game dug this node, apply a bigger velocity local v = 1 - if digger and digger:is_player() then v = obj:get_luaentity().random_velocity - else v = 6 end - - local x = math.random(2, 10) / 10 * v - if math.random(0,10) < 5 then x = -x end - local z = math.random(2, 10) / 10 * v - if math.random(0,10) < 5 then z = -z end - local y = math.random(2,4) - obj:set_velocity({x=x, y=y, z=z}) + if digger and digger:is_player() then + obj:get_luaentity().random_velocity = 1 + else + obj:get_luaentity().random_velocity = 1.6 + end obj:get_luaentity().age = item_drop_settings.dug_buffer obj:get_luaentity()._insta_collect = false @@ -415,6 +411,26 @@ minetest.register_entity(":__builtin:item", { -- How old it has become in the collection animation collection_age = 0, + apply_random_vel = function(self, speed) + if not self or not self.object or not self.object:get_luaentity() then + return + end + + if speed ~= nil then self.random_velocity = speed end + + local vel = self.object:get_velocity() + if vel and vel.x == 0 and vel.z == 0 and self.random_velocity > 0 then + local v = self.random_velocity + local x = math.random(5, 10) / 10 * v + if math.random(0,10) < 5 then x = -x end + local z = math.random(5, 10) / 10 * v + if math.random(0,10) < 5 then z = -z end + local y = math.random(2,4) + self.object:set_velocity({x=x, y=y, z=z}) + end + self.random_velocity = 0 + end, + set_item = function(self, itemstring) self.itemstring = itemstring if self.itemstring == "" then @@ -467,7 +483,9 @@ minetest.register_entity(":__builtin:item", { glow = glow, } self.object:set_properties(prop) - + if item_drop_settings.random_item_velocity == true and self.age < 2 then + minetest.after(0, self.apply_random_vel, self) + end end, get_staticdata = function(self) diff --git a/mods/ITEMS/mcl_core/functions.lua b/mods/ITEMS/mcl_core/functions.lua index c9caf9423..c7dc7b12a 100644 --- a/mods/ITEMS/mcl_core/functions.lua +++ b/mods/ITEMS/mcl_core/functions.lua @@ -215,8 +215,8 @@ minetest.register_abm({ local posy = pos.y while minetest.get_node(vector.new(pos.x, posy, pos.z)).name == "mcl_core:cactus" do local pos = vector.new(pos.x, posy, pos.z) - minetest.remove_node(pos) - minetest.add_item(vector.offset(pos, math.random(-0.5, 0.5), 0, math.random(-0.5, 0.5)), "mcl_core:cactus") + minetest.dig_node(pos) + -- minetest.add_item(vector.offset(pos, math.random(-0.5, 0.5), 0, math.random(-0.5, 0.5)), "mcl_core:cactus") posy = posy + 1 end break From 70b7655e46d86c7e3c1539c81a064951aad38fc1 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Tue, 26 Jul 2022 20:20:13 +1000 Subject: [PATCH 11/12] various code style improvements --- mods/ENTITIES/mcl_item_entity/init.lua | 37 +++++++++++++------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 30e4d828d..6640b835f 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -320,14 +320,12 @@ function minetest.handle_node_drops(pos, drops, digger) if obj then -- set the velocity multiplier to the stored amount or if the game dug this node, apply a bigger velocity local v = 1 - if digger and digger:is_player() then obj:get_luaentity().random_velocity = 1 else obj:get_luaentity().random_velocity = 1.6 end obj:get_luaentity().age = item_drop_settings.dug_buffer - obj:get_luaentity()._insta_collect = false end end @@ -406,16 +404,18 @@ minetest.register_entity(":__builtin:item", { -- Number of seconds this item entity has existed so far age = 0, + -- Multiplier for initial random velocity when the item is spawned random_velocity = 1, -- How old it has become in the collection animation collection_age = 0, + -- Function to apply a random velocity apply_random_vel = function(self, speed) if not self or not self.object or not self.object:get_luaentity() then return end - + -- if you passed a value then use that for the velocity multiplier if speed ~= nil then self.random_velocity = speed end local vel = self.object:get_velocity() @@ -483,7 +483,7 @@ minetest.register_entity(":__builtin:item", { glow = glow, } self.object:set_properties(prop) - if item_drop_settings.random_item_velocity == true and self.age < 2 then + if item_drop_settings.random_item_velocity == true and self.age < 1 then minetest.after(0, self.apply_random_vel, self) end end, @@ -660,12 +660,14 @@ minetest.register_entity(":__builtin:item", { local nn_above = minetest.get_node({x=p.x, y=p.y+0.1, z=p.z}).name -- make sure it's more or less stationary and is at water level local sleep_threshold = 0.3 + local is_floating = false local is_stationary = math.abs(self.object:get_velocity().x) < sleep_threshold and math.abs(self.object:get_velocity().y) < sleep_threshold and math.abs(self.object:get_velocity().z) < sleep_threshold - local is_floating = (is_stationary - and is_in_water - and (minetest.get_item_group(nn_above, "liquid") == 0)) + if is_in_water and is_stationary then + is_floating = (is_in_water + and (minetest.get_item_group(nn_above, "liquid") == 0)) + end if is_floating and self.physical_state == true then self.object:set_velocity({x = 0, y = 0, z = 0}) @@ -857,24 +859,23 @@ minetest.register_entity(":__builtin:item", { if not minetest.registered_nodes[nn] or is_floating or is_on_floor then - if true then - local own_stack = ItemStack(self.object:get_luaentity().itemstring) - -- Merge with close entities of the same item - for _, object in pairs(minetest.get_objects_inside_radius(p, 0.8)) do - local obj = object:get_luaentity() - if obj and obj.name == "__builtin:item" - and obj.physical_state == false then - if self:try_merge_with(own_stack, object, obj) then - return - end + local own_stack = ItemStack(self.object:get_luaentity().itemstring) + -- Merge with close entities of the same item + for _, object in pairs(minetest.get_objects_inside_radius(p, 0.8)) do + local obj = object:get_luaentity() + if obj and obj.name == "__builtin:item" + and obj.physical_state == false then + if self:try_merge_with(own_stack, object, obj) then + return end end + -- don't disable if underwater if not is_in_water then disable_physics(self.object, self) end end else - if self._magnet_active == false and not is_floating and not is_in_water then + if self._magnet_active == false and not is_floating then enable_physics(self.object, self) end end From 86d6445f421219a0e72b65761d3af291d47de694 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Thu, 28 Jul 2022 11:10:56 +1000 Subject: [PATCH 12/12] fix crash when items in unloaded chunk --- mods/ENTITIES/mcl_item_entity/init.lua | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mods/ENTITIES/mcl_item_entity/init.lua b/mods/ENTITIES/mcl_item_entity/init.lua index 6640b835f..5a82ca1fd 100644 --- a/mods/ENTITIES/mcl_item_entity/init.lua +++ b/mods/ENTITIES/mcl_item_entity/init.lua @@ -649,6 +649,12 @@ minetest.register_entity(":__builtin:item", { local node = minetest.get_node_or_nil(p) local in_unloaded = (node == nil) + if in_unloaded then + -- Don't infinetly fall into unloaded map + disable_physics(self.object, self) + return + end + if self.is_clock then self.object:set_properties({ textures = {"mcl_clock:clock_" .. (mcl_worlds.clock_works(p) and mcl_clock.old_time or mcl_clock.random_frame)} @@ -680,11 +686,6 @@ minetest.register_entity(":__builtin:item", { enable_physics(self.object, self) return end - if in_unloaded then - -- Don't infinetly fall into unloaded map - disable_physics(self.object, self) - return - end -- Destroy item in lava, fire or special nodes