From 98ddf778cfdd77a1cba75d1d35ad4c610b9d1253 Mon Sep 17 00:00:00 2001 From: kay27 Date: Tue, 25 Jan 2022 19:18:49 +0400 Subject: [PATCH] Fix mob click in minetest 5.1.1 --- mods/CORE/mcl_init/compatibility.lua | 29 +++++++++++++------ .../api/mob_functions/death_logic.lua | 3 +- .../api/mob_functions/interaction.lua | 7 +++-- mods/MAPGEN/mcl_structures/init.lua | 2 ++ mods/MAPGEN/mcl_structures/mod.conf | 2 +- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/mods/CORE/mcl_init/compatibility.lua b/mods/CORE/mcl_init/compatibility.lua index 4aa2f92a2..41d937c02 100644 --- a/mods/CORE/mcl_init/compatibility.lua +++ b/mods/CORE/mcl_init/compatibility.lua @@ -1,16 +1,27 @@ -function minetest.is_creative_enabled() - return false -end +mcl_compatibility = {} function vector.offset(v,x,y,z) return vector.add(v,{x=x,y=y,z=z}) end ---[[ -minetest.register_on_joinplayer(function(ObjectRef, last_login) - if not ObjectRef.set_moon then - function ObjectRef.set_moon() +local minetest_get_node = minetest.get_node + +mcl_compatibility.sort_nodes = function(nodes) + if not nodes then return {} end + for _, pos in pairs(nodes) do + if not pos.x or not pos.y or not pos.z then + return nodes end end -end) -]] + local new_nodes = {} + for _, pos in pairs(nodes) do + local node = minetest_get_node(pos) + local name = node.name + if not new_nodes[name] then + new_nodes[name] = { pos } + else + table.insert(new_nodes[name], pos) + end + end + return new_nodes +end diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua index 4e6b7ca46..54ac58064 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua @@ -99,7 +99,8 @@ mobs.death_logic = function(self, dtime) self.death_animation_timer = self.death_animation_timer + dtime --get all attached entities and sort through them - local attached_entities = self.object:get_children() + -- TODO: support 5.1.1 + local attached_entities = self.object.get_children and self.object:get_children() or {} if #attached_entities > 0 then for _,entity in pairs(attached_entities) do --kick the player off diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua index fa5b31210..eeec26e6f 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua @@ -185,7 +185,8 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir) --if player is falling multiply damage by 1.5 --critical hit - if hitter:get_velocity().y < 0 then + local hitter_velocity = hitter:get_velocity() or hitter:get_player_velocity() or vector.new(0, 0, 0) + if hitter_velocity.y < 0 then damage = damage * 1.5 mobs.critical_effect(self) end @@ -207,7 +208,9 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir) self.pause_timer = 0.4 --don't do knockback from a rider - for _,obj in pairs(self.object:get_children()) do + local object_children = self.object.get_children and self.object:get_children() + -- TODO: support 5.1.1 + for _,obj in pairs(object_children or {}) do if obj == hitter then return end diff --git a/mods/MAPGEN/mcl_structures/init.lua b/mods/MAPGEN/mcl_structures/init.lua index 64f6db937..96759f604 100644 --- a/mods/MAPGEN/mcl_structures/init.lua +++ b/mods/MAPGEN/mcl_structures/init.lua @@ -107,6 +107,7 @@ end function process_mapgen_block_lvm(vm_context) local nodes = minetest.find_nodes_in_area(vm_context.minp, vm_context.maxp, {"group:struct"}, true) + nodes = mcl_compatibility.sort_nodes(nodes) for node_name, pos_list in pairs(nodes) do local lvm_callback = on_finished_block_callbacks[node_name] if lvm_callback then @@ -117,6 +118,7 @@ end function process_mapgen_chunk(minp, maxp, seed, vm_context) local nodes = minetest.find_nodes_in_area(minp, maxp, {"group:struct"}, true) + nodes = mcl_compatibility.sort_nodes(nodes) for node_name, pos_list in pairs(nodes) do local chunk_callback = on_finished_chunk_callbacks[node_name] if chunk_callback then diff --git a/mods/MAPGEN/mcl_structures/mod.conf b/mods/MAPGEN/mcl_structures/mod.conf index 1e34960a8..558e06638 100644 --- a/mods/MAPGEN/mcl_structures/mod.conf +++ b/mods/MAPGEN/mcl_structures/mod.conf @@ -1,4 +1,4 @@ name = mcl_structures author = Wuzzy, kay27, cora description = Structures for MineClone 2/5 -depends = mcl_loot, mcl_mapgen, mcl_worlds +depends = mcl_init, mcl_loot, mcl_mapgen, mcl_worlds