forked from VoxeLibre/VoxeLibre
Merge pull request 'Fix ocelots and add in skittish mob behavior' (#1625) from jordan4ibanez/MineClone2:mineclone5 into mineclone5
Reviewed-on: MineClone2/MineClone2#1625
This commit is contained in:
commit
9486d1bf23
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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",
|
||||
|
@ -39,7 +42,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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue