From ae5564e6581eedcb02e949cb6305b8b57e0247df Mon Sep 17 00:00:00 2001 From: codiac Date: Sun, 10 Sep 2023 21:33:37 +1000 Subject: [PATCH 1/4] Make golem go home. Fixes #3288 --- mods/ENTITIES/mobs_mc/iron_golem.lua | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 6b428c6f8..9cdb6aa10 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -9,7 +9,8 @@ local S = minetest.get_translator("mobs_mc") --################### IRON GOLEM --################### -local etime = 0 +local walk_dist = 40 +local tele_dist = 80 mcl_mobs.register_mob("mobs_mc:iron_golem", { description = S("Iron Golem"), @@ -85,11 +86,23 @@ mcl_mobs.register_mob("mobs_mc:iron_golem", { punch_start = 40, punch_end = 50, }, jump = true, - on_step = function(self,dtime) - etime = etime + dtime - if etime > 10 then - if self._home and vector.distance(self._home,self.object:get_pos()) > 50 then - self:gopath(self._home) + do_custom = function(self, dtime) + self.home_timer = (self.home_timer or 0) + dtime + + if self.home_timer > 10 then + self.home_timer = 0 + if self._home then + local dist = vector.distance(self._home,self.object:get_pos()) + if dist >= tele_dist then + self.object:set_pos(self._home) + self.state = "stand" + self.order = "follow" + elseif dist >= walk_dist then + self:gopath(self._home, function(self) + self.state = "stand" + self.order = "follow" + end) + end end end end, From 06f9486e4dac1cb9143d333fa8d45c61eba3a088 Mon Sep 17 00:00:00 2001 From: codiac Date: Mon, 11 Sep 2023 15:18:39 +1000 Subject: [PATCH 2/4] Do not go home if attacking --- mods/ENTITIES/mobs_mc/iron_golem.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 9cdb6aa10..2d081e4fe 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -91,7 +91,7 @@ mcl_mobs.register_mob("mobs_mc:iron_golem", { if self.home_timer > 10 then self.home_timer = 0 - if self._home then + if self._home and self.state ~= "attack" then local dist = vector.distance(self._home,self.object:get_pos()) if dist >= tele_dist then self.object:set_pos(self._home) From 89c97690c8960731b37eabb794c32df204316924 Mon Sep 17 00:00:00 2001 From: codiac Date: Wed, 13 Sep 2023 15:21:19 +1000 Subject: [PATCH 3/4] Add a setting to enable mod nav hacks --- mods/ENTITIES/mobs_mc/iron_golem.lua | 3 ++- settingtypes.txt | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 2d081e4fe..b79971b9b 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -4,6 +4,7 @@ --License for code WTFPL and otherwise stated in readmes local S = minetest.get_translator("mobs_mc") +local allow_nav_hacks = minetest.settings:get_bool("mcl_mob_allow_nav_hacks ",false) --################### --################### IRON GOLEM @@ -93,7 +94,7 @@ mcl_mobs.register_mob("mobs_mc:iron_golem", { self.home_timer = 0 if self._home and self.state ~= "attack" then local dist = vector.distance(self._home,self.object:get_pos()) - if dist >= tele_dist then + if allow_nav_hacks and dist >= tele_dist then self.object:set_pos(self._home) self.state = "stand" self.order = "follow" diff --git a/settingtypes.txt b/settingtypes.txt index 82086de14..0b466f76f 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -207,6 +207,10 @@ mcl_mobs_overworld_threshold (Artificial light threshold to stop monster spawns mcl_mobs_overworld_sky_threshold (Skylight threshold to stop monster spawns in the Overworld) int 7 0 14 mcl_mobs_overworld_passive_threshold (Combined light threshold to stop animal and npc spawns in the Overworld) int 7 0 14 +# Enable workarounds for faulty mob navigation. +# Hack 1: teleport golems home if they are very far from home +mcl_mob_allow_nav_hacks (Mob navigation hacks) bool false + [Audio] # Enable flame sound. flame_sound (Flame sound) bool true From 71282e196eda35f748506de8918bf3433b5c5dde Mon Sep 17 00:00:00 2001 From: codiac Date: Sun, 24 Sep 2023 22:19:06 +1000 Subject: [PATCH 4/4] Move mob nav hacks to Experimental --- settingtypes.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/settingtypes.txt b/settingtypes.txt index 0b466f76f..6d4bfb9e8 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -207,10 +207,6 @@ mcl_mobs_overworld_threshold (Artificial light threshold to stop monster spawns mcl_mobs_overworld_sky_threshold (Skylight threshold to stop monster spawns in the Overworld) int 7 0 14 mcl_mobs_overworld_passive_threshold (Combined light threshold to stop animal and npc spawns in the Overworld) int 7 0 14 -# Enable workarounds for faulty mob navigation. -# Hack 1: teleport golems home if they are very far from home -mcl_mob_allow_nav_hacks (Mob navigation hacks) bool false - [Audio] # Enable flame sound. flame_sound (Flame sound) bool true @@ -294,6 +290,10 @@ fix_doubleplants (Mcimport double plant fixes) bool true # Allow players to create Minecraft-like maps. enable_real_maps (Enable Real Maps) bool true +# Enable workarounds for faulty mob navigation. +# Hack 1: teleport golems home if they are very far from home +mcl_mob_allow_nav_hacks (Mob navigation hacks) bool false + [Additional Features] # Enable Bookshelf inventories mcl_bookshelf_inventories (Enable bookshelf inventories) bool true