From 189c0ad157a8871d51045effcded0662aff7b1af Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 23 Apr 2021 15:53:01 -0400 Subject: [PATCH 1/2] Half finish horse (riding logic, etc) --- .../mcl_mobs/api/mob_functions/ai.lua | 8 +++ .../mcl_mobs/api/mob_functions/animation.lua | 2 +- .../mcl_mobs/api/mob_functions/collision.lua | 6 +- .../api/mob_functions/death_logic.lua | 14 +++++ mods/ENTITIES/mcl_mobs/api/mount.lua | 55 ++++++++++--------- mods/ENTITIES/mcl_mobs/api/spawning.lua | 2 + mods/ENTITIES/mobs_mc/horse.lua | 7 ++- 7 files changed, 62 insertions(+), 32 deletions(-) diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua index 5429ff8c5..6f5de1300 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/ai.lua @@ -672,6 +672,14 @@ mobs.mob_step = function(self, dtime) if self.do_custom then -- when false skip going any further if self.do_custom(self, dtime) == false then + --this needs to be here or the mob becomes immortal + if self.pause_timer > 0 then + self.pause_timer = self.pause_timer - dtime + --perfectly reset pause_timer + if self.pause_timer < 0 then + self.pause_timer = 0 + end + end --this overrides internal lua collision detection return end diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/animation.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/animation.lua index 71008c97c..fbf140034 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/animation.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/animation.lua @@ -22,7 +22,7 @@ mobs.set_mob_animation = function(self, anim, fixed_frame) end - if (not self.animation[anim .. "_start"] or not self.animation[anim .. "_end"]) then + if (not self.animation[anim .. "_start"] or not self.animation[anim .. "_end"]) then return end diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/collision.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/collision.lua index b56a0d392..60f0aeeb4 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/collision.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/collision.lua @@ -39,10 +39,10 @@ mobs.collision = function(self) end for _,object in ipairs(minetest_get_objects_inside_radius(pos, radius*1.25)) do - if object and object ~= self.object and (object:is_player() or (object:get_luaentity() and object:get_luaentity()._cmi_is_mob == true)) then--and + if object and object ~= self.object and (object:is_player() or (object:get_luaentity() and object:get_luaentity()._cmi_is_mob == true)) and --don't collide with rider, rider don't collide with thing - --(not object:get_attach() or (object:get_attach() and object:get_attach() ~= self.object)) and - --(not self.object:get_attach() or (self.object:get_attach() and self.object:get_attach() ~= object)) then + (not object:get_attach() or (object:get_attach() and object:get_attach() ~= self.object)) and + (not self.object:get_attach() or (self.object:get_attach() and self.object:get_attach() ~= object)) then --stop infinite loop collision_count = collision_count + 1 if collision_count > 100 then 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 166699358..f0524a76f 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/death_logic.lua @@ -89,6 +89,20 @@ end 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() + if #attached_entities > 0 then + for _,entity in pairs(attached_entities) do + --kick the player off + if entity:is_player() then + mobs.detach(entity) + --kick mobs off + --if there is scaling issues, this needs an additional check + else + entity:set_detach() + end + end + end --the final POOF of a mob despawning if self.death_animation_timer >= 1.25 then diff --git a/mods/ENTITIES/mcl_mobs/api/mount.lua b/mods/ENTITIES/mcl_mobs/api/mount.lua index 9383ee067..8ee45f299 100644 --- a/mods/ENTITIES/mcl_mobs/api/mount.lua +++ b/mods/ENTITIES/mcl_mobs/api/mount.lua @@ -206,21 +206,30 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime) -- move forwards if ctrl.up then - entity.v = entity.v + entity.accel / 10 + mobs.set_velocity(entity, entity.run_velocity) + + mobs.set_mob_animation(entity, moving_anim) -- move backwards elseif ctrl.down then - if entity.max_speed_reverse == 0 and entity.v == 0 then - return - end + mobs.set_velocity(entity, -entity.run_velocity) - entity.v = entity.v - entity.accel / 10 + mobs.set_mob_animation(entity, moving_anim) + + --halt + else + + mobs.set_velocity(entity, 0) + + mobs.set_mob_animation(entity, stand_anim) end - -- fix mob rotation + -- mob rotation entity.object:set_yaw(entity.driver:get_look_horizontal() - entity.rotate) + entity.yaw = entity.driver:get_look_horizontal() - entity.rotate + --[[ if can_fly then -- fly up @@ -244,32 +253,21 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime) end else + ]]-- - -- jump - if ctrl.jump then + -- jump + if ctrl.jump then - if velo.y == 0 then - velo.y = velo.y + entity.jump_height - acce_y = acce_y + (acce_y * 3) + 1 - end - end - - end - end - - -- if not moving then set animation and return - if entity.v == 0 and velo.x == 0 and velo.y == 0 and velo.z == 0 then - - if stand_anim then - mobs:set_animation(entity, stand_anim) + mobs.jump(entity) end - return + --end end + --[[ -- set moving animation if moving_anim then - mobs:set_animation(entity, moving_anim) + mobs:set_mob_animation(entity, moving_anim) end -- Stop! @@ -383,6 +381,7 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime) end entity.v2 = v + ]]-- end @@ -390,6 +389,10 @@ end function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim) + if true then + print("succ") + return + end local ctrl = entity.driver:get_player_control() local velo = entity.object:get_velocity() local dir = entity.driver:get_look_dir() @@ -440,9 +443,9 @@ function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim) -- change animation if stopped if velo.x == 0 and velo.y == 0 and velo.z == 0 then - mobs:set_animation(entity, stand_anim) + mobs:set_mob_animation(entity, stand_anim) else -- moving animation - mobs:set_animation(entity, moving_anim) + mobs:set_mob_animation(entity, moving_anim) end end diff --git a/mods/ENTITIES/mcl_mobs/api/spawning.lua b/mods/ENTITIES/mcl_mobs/api/spawning.lua index f885d55c7..100fc84b6 100644 --- a/mods/ENTITIES/mcl_mobs/api/spawning.lua +++ b/mods/ENTITIES/mcl_mobs/api/spawning.lua @@ -165,6 +165,8 @@ Overworld regular: local mobs_spawn = minetest.settings:get_bool("mobs_spawn", true) ~= false +mobs_spawn = false + -- count how many mobs are in an area local count_mobs = function(pos) local num = 0 diff --git a/mods/ENTITIES/mobs_mc/horse.lua b/mods/ENTITIES/mobs_mc/horse.lua index 0e0246d4e..66cd76538 100644 --- a/mods/ENTITIES/mobs_mc/horse.lua +++ b/mods/ENTITIES/mobs_mc/horse.lua @@ -87,6 +87,9 @@ local horse = { spawn_class = "passive", visual = "mesh", mesh = "mobs_mc_horse.b3d", + rotate = 270, + walk_velocity = 1, + run_velocity = 8, visual_size = {x=3.0, y=3.0}, collisionbox = {-0.69825, -0.01, -0.69825, 0.69825, 1.59, 0.69825}, animation = { @@ -96,7 +99,7 @@ local horse = { walk_speed = 25, walk_start = 0, walk_end = 40, - run_speed = 60, + run_speed = 120, run_start = 0, run_end = 40, }, @@ -181,7 +184,7 @@ local horse = { -- if driver present and horse has a saddle allow control of horse if self.driver and self._saddle then - mobs.drive(self, "walk", "stand", false, dtime) + mobs.drive(self, "run", "stand", false, dtime) return false -- skip rest of mob functions end From 8e7ce5a72ae3e7cedf985a414c64ca259bcd6136 Mon Sep 17 00:00:00 2001 From: jordan4ibanez Date: Fri, 23 Apr 2021 16:04:01 -0400 Subject: [PATCH 2/2] Add in a visual for horse taming (hearts) --- .../api/mob_functions/mob_effects.lua | 61 +++++++++++++++++++ mods/ENTITIES/mobs_mc/horse.lua | 9 +++ 2 files changed, 70 insertions(+) diff --git a/mods/ENTITIES/mcl_mobs/api/mob_functions/mob_effects.lua b/mods/ENTITIES/mcl_mobs/api/mob_functions/mob_effects.lua index 1bf79f8aa..b01920f18 100644 --- a/mods/ENTITIES/mcl_mobs/api/mob_functions/mob_effects.lua +++ b/mods/ENTITIES/mcl_mobs/api/mob_functions/mob_effects.lua @@ -58,4 +58,65 @@ mobs.critical_effect = function(self) vertical = false, texture = "heart.png^[colorize:black:255", }) +end + +--when feeding a mob +mobs.feed_effect = function(self) + + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() + local collisionbox = self.object:get_properties().collisionbox + + local min, max + + if collisionbox then + min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} + max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} + end + + minetest_add_particlespawner({ + amount = 10, + time = 0.0001, + minpos = vector.add(pos, min), + maxpos = vector.add(pos, max), + minvel = vector.new(-1,1,-1), + maxvel = vector.new(1,3,1), + minexptime = 0.7, + maxexptime = 1, + minsize = 1, + maxsize = 2, + collisiondetection = false, + vertical = false, + texture = "heart.png^[colorize:gray:255", + }) +end + +--hearts when tamed +mobs.tamed_effect = function(self) + local pos = self.object:get_pos() + local yaw = self.object:get_yaw() + local collisionbox = self.object:get_properties().collisionbox + + local min, max + + if collisionbox then + min = {x=collisionbox[1], y=collisionbox[2], z=collisionbox[3]} + max = {x=collisionbox[4], y=collisionbox[5], z=collisionbox[6]} + end + + minetest_add_particlespawner({ + amount = 30, + time = 0.0001, + minpos = vector.add(pos, min), + maxpos = vector.add(pos, max), + minvel = vector.new(-1,1,-1), + maxvel = vector.new(1,3,1), + minexptime = 0.7, + maxexptime = 1, + minsize = 1, + maxsize = 2, + collisiondetection = false, + vertical = false, + texture = "heart.png", + }) end \ No newline at end of file diff --git a/mods/ENTITIES/mobs_mc/horse.lua b/mods/ENTITIES/mobs_mc/horse.lua index 66cd76538..ac1a2ef4c 100644 --- a/mods/ENTITIES/mobs_mc/horse.lua +++ b/mods/ENTITIES/mobs_mc/horse.lua @@ -241,6 +241,7 @@ local horse = { self.buck_off_time = 40 -- TODO how long does it take in minecraft? if self.temper > 100 then self.tamed = true -- NOTE taming can only be finished by riding the horse + mobs.tamed_effect(self) if not self.owner or self.owner == "" then self.owner = clicker:get_player_name() end @@ -255,6 +256,14 @@ local horse = { -- If nothing happened temper_increase = 0 and addition does nothing self.temper = self.temper + temper_increase + --give the player some kind of idea + --of what's happening with the horse's temper + if self.temper <= 100 then + mobs.feed_effect(self) + else + mobs.tamed_effect(self) + end + return end