From 65fc5b6f28d340a610ea8bf576a6ae77650f8117 Mon Sep 17 00:00:00 2001 From: Sumyjkl Date: Fri, 22 Jul 2022 22:38:36 +1000 Subject: [PATCH] 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 60e0a73911..0d27d91a0b 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 aa20fc8135..94f0fcd8d4 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 abb3510913..6dac4495fb 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