From c138050e0b877f5dc987959efe4acbe17ffd86f2 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 23 Apr 2021 16:45:12 -0400 Subject: [PATCH 1/4] Make iron golem neutral and protective, fix rotation --- mods/ENTITIES/mobs_mc/iron_golem.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 2ccee2d0a..e12e7ab4a 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -15,8 +15,11 @@ mobs:register_mob("mobs_mc:iron_golem", { type = "npc", spawn_class = "passive", passive = true, + rotate = 270, hp_min = 100, hp_max = 100, + protect = true, + neutral = true, breath_max = -1, collisionbox = {-0.7, -0.01, -0.7, 0.7, 2.69, 0.7}, visual = "mesh", From 8daf197fb899a0bee8f61aad4ccedec1108f5f92 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 23 Apr 2021 16:52:07 -0400 Subject: [PATCH 2/4] Fix iron golem rotation --- mods/ENTITIES/mobs_mc/iron_golem.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index e12e7ab4a..08f7cfe58 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -18,6 +18,7 @@ mobs:register_mob("mobs_mc:iron_golem", { rotate = 270, hp_min = 100, hp_max = 100, + rotate = 270, protect = true, neutral = true, breath_max = -1, @@ -42,7 +43,7 @@ mobs:register_mob("mobs_mc:iron_golem", { reach = 3, group_attack = true, attacks_monsters = true, - attack_type = "dogfight", + attack_type = "punch", drops = { {name = mobs_mc.items.iron_ingot, chance = 1, From af4c42fea7112ada76fd9b273f771611532bdcf9 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 23 Apr 2021 17:10:44 -0400 Subject: [PATCH 3/4] Add skittish behavior (runaway from punch) and fix ocelot --- mods/ENTITIES/mcl_mobs/api/api.lua | 1 + .../mcl_mobs/api/mob_functions/ai.lua | 51 +++++++++++++++++-- .../api/mob_functions/interaction.lua | 28 +++++----- mods/ENTITIES/mobs_mc/iron_golem.lua | 3 +- mods/ENTITIES/mobs_mc/ocelot.lua | 2 + 5 files changed, 67 insertions(+), 18 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/api.lua b/mods/ENTITIES/mcl_mobs/api/api.lua index 373ac18b7..852bfd8af 100644 --- a/mods/ENTITIES/mcl_mobs/api/api.lua +++ b/mods/ENTITIES/mcl_mobs/api/api.lua @@ -337,6 +337,7 @@ function mobs:register_mob(name, def) fall_slow = def.fall_slow, projectile_cooldown_min = def.projectile_cooldown_min or 2, projectile_cooldown_max = def.projectile_cooldown_max or 6, + skittish = def.skittish, --end j4i stuff -- MCL2 extensions diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index f914ab9d5..09877ac2a 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -67,13 +67,26 @@ local land_state_list_wandering = {"stand", "walk"} local land_state_switch = function(self, dtime) + --do math after sure not attacking or running away + self.state_timer = self.state_timer - dtime + + --only run away + if self.skittish and self.state == "run" then + self.run_timer = self.run_timer - dtime + if self.run_timer > 0 then + return + end + + --continue + end + + --only attack if self.hostile and self.attacking then self.state = "attack" return end - --do math after sure not attacking - self.state_timer = self.state_timer - dtime + if self.state_timer <= 0 then self.state_timer = math.random(4,10) + math.random() @@ -185,7 +198,37 @@ local land_state_execution = function(self,dtime) elseif self.state == "run" then - print("run") + --do animation + mobs.set_mob_animation(self, "run") + + --enable rotation locking + mobs.movement_rotation_lock(self) + + --check for nodes to jump over + local node_in_front_of = mobs.jump_check(self) + + if node_in_front_of == 1 then + + mobs.jump(self) + + --turn if on the edge of cliff + --(this is written like this because unlike + --jump_check which simply tells the mob to jump + --this requires a mob to turn, removing the + --ease of a full implementation for it in a single + --function) + elseif node_in_front_of == 2 or (self.fear_height ~= 0 and cliff_check(self,dtime)) then + --turn 45 degrees if so + quick_rotate(self,dtime) + --stop the mob so it doesn't fall off + mobs.set_velocity(self,0) + end + + --only move forward if path is clear + if node_in_front_of == 0 or node_in_front_of == 1 then + --set the velocity of the mob + mobs.set_velocity(self,self.run_velocity) + end elseif self.state == "attack" then @@ -652,7 +695,7 @@ mobs.mob_step = function(self, dtime) self.object:remove() return false end - + --do death logic (animation, poof, explosion, etc) if self.health <= 0 then diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua index 264eff9de..6cbc48b0b 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/interaction.lua @@ -1,5 +1,6 @@ local minetest_after = minetest.after local minetest_sound_play = minetest.sound_play +local minetest_dir_to_yaw = minetest.dir_to_yaw local math_floor = math.floor local math_min = math.min @@ -63,21 +64,24 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir) return end - --neutral passive mobs switch to neutral hostile - if self.neutral then + --turn skittish mobs away and RUN + if self.skittish then - --drop in variables for attacking (stops crash) - self.attacking = hitter - self.punch_timer = 0 + self.state = "run" - self.hostile = true - --hostile_cooldown timer is initialized here - self.hostile_cooldown_timer = self.hostile_cooldown + self.run_timer = 5 --arbitrary 5 seconds - --initialize the group attack (check for other mobs in area, make them neutral hostile) - if self.group_attack then - mobs.group_attack_initialization(self) - end + local pos1 = self.object:get_pos() + pos1.y = 0 + local pos2 = hitter:get_pos() + pos2.y = 0 + + + local dir = vector_direction(pos2,pos1) + + local yaw = minetest_dir_to_yaw(dir) + + self.yaw = yaw end diff --git a/mods/ENTITIES/mobs_mc/iron_golem.lua b/mods/ENTITIES/mobs_mc/iron_golem.lua index 08f7cfe58..d4cd311a8 100644 --- a/mods/ENTITIES/mobs_mc/iron_golem.lua +++ b/mods/ENTITIES/mobs_mc/iron_golem.lua @@ -17,8 +17,7 @@ mobs:register_mob("mobs_mc:iron_golem", { passive = true, rotate = 270, hp_min = 100, - hp_max = 100, - rotate = 270, + hp_max = 100, protect = true, neutral = true, breath_max = -1, diff --git a/mods/ENTITIES/mobs_mc/ocelot.lua b/mods/ENTITIES/mobs_mc/ocelot.lua index bb62a54fa..8442d0614 100644 --- a/mods/ENTITIES/mobs_mc/ocelot.lua +++ b/mods/ENTITIES/mobs_mc/ocelot.lua @@ -30,6 +30,8 @@ local ocelot = { type = "animal", spawn_class = "passive", can_despawn = true, + rotate = 270, + skittish = true, hp_min = 10, hp_max = 10, xp_min = 1, From 304cbed447adbcccff246f242d18d51fc010df35 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 23 Apr 2021 17:12:02 -0400 Subject: [PATCH 4/4] Make mobs that should be skittish, skittish --- mods/ENTITIES/mobs_mc/chicken.lua | 2 +- mods/ENTITIES/mobs_mc/cow+mooshroom.lua | 2 +- mods/ENTITIES/mobs_mc/horse.lua | 1 + mods/ENTITIES/mobs_mc/pig.lua | 2 +- mods/ENTITIES/mobs_mc/sheep.lua | 1 + 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/mods/ENTITIES/mobs_mc/chicken.lua b/mods/ENTITIES/mobs_mc/chicken.lua index 2e1a2e524..780a06912 100644 --- a/mods/ENTITIES/mobs_mc/chicken.lua +++ b/mods/ENTITIES/mobs_mc/chicken.lua @@ -17,7 +17,7 @@ mobs:register_mob("mobs_mc:chicken", { xp_min = 1, xp_max = 3, collisionbox = {-0.2, -0.01, -0.2, 0.2, 0.69, 0.2}, - runaway = true, + skittish = true, fall_slow = true, floats = 1, visual = "mesh", diff --git a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua index 59b80ecb9..1c170077c 100644 --- a/mods/ENTITIES/mobs_mc/cow+mooshroom.lua +++ b/mods/ENTITIES/mobs_mc/cow+mooshroom.lua @@ -32,7 +32,7 @@ local cow_def = { max = 2, looting = "common",}, }, - runaway = true, + skittish = true, sounds = { random = "mobs_mc_cow", damage = "mobs_mc_cow_hurt", diff --git a/mods/ENTITIES/mobs_mc/horse.lua b/mods/ENTITIES/mobs_mc/horse.lua index ac1a2ef4c..404efc292 100644 --- a/mods/ENTITIES/mobs_mc/horse.lua +++ b/mods/ENTITIES/mobs_mc/horse.lua @@ -90,6 +90,7 @@ local horse = { rotate = 270, walk_velocity = 1, run_velocity = 8, + skittish = true, visual_size = {x=3.0, y=3.0}, collisionbox = {-0.69825, -0.01, -0.69825, 0.69825, 1.59, 0.69825}, animation = { diff --git a/mods/ENTITIES/mobs_mc/pig.lua b/mods/ENTITIES/mobs_mc/pig.lua index 16cf7d0f0..8ce0f1829 100644 --- a/mods/ENTITIES/mobs_mc/pig.lua +++ b/mods/ENTITIES/mobs_mc/pig.lua @@ -5,7 +5,7 @@ local S = minetest.get_translator("mobs_mc") mobs:register_mob("mobs_mc:pig", { type = "animal", spawn_class = "passive", - runaway = true, + skittish = true, rotate = 270, hp_min = 10, hp_max = 10, diff --git a/mods/ENTITIES/mobs_mc/sheep.lua b/mods/ENTITIES/mobs_mc/sheep.lua index 30571d0a2..60d3c4d3b 100644 --- a/mods/ENTITIES/mobs_mc/sheep.lua +++ b/mods/ENTITIES/mobs_mc/sheep.lua @@ -62,6 +62,7 @@ mobs:register_mob("mobs_mc:sheep", { hp_max = 8, xp_min = 1, xp_max = 3, + skittish = true, collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.29, 0.45}, rotate = 270, visual = "mesh",