mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-24 11:53:46 +01:00
[mcl_mobs] fix some warnings (131 remaining!)
This commit is contained in:
parent
66f132a645
commit
f76b66eec6
@ -47,6 +47,9 @@ read_globals = {
|
|||||||
--GENERAL
|
--GENERAL
|
||||||
"default",
|
"default",
|
||||||
|
|
||||||
|
--ENTITIES
|
||||||
|
"cmi",
|
||||||
|
|
||||||
--HUD
|
--HUD
|
||||||
"sfinv", "sfinv_buttons", "unified_inventory", "cmsg", "inventory_plus",
|
"sfinv", "sfinv_buttons", "unified_inventory", "cmsg", "inventory_plus",
|
||||||
}
|
}
|
@ -92,13 +92,13 @@ local node_snowblock = "mcl_core:snowblock"
|
|||||||
local node_snow = "mcl_core:snow"
|
local node_snow = "mcl_core:snow"
|
||||||
mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "mcl_core:dirt"
|
mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "mcl_core:dirt"
|
||||||
|
|
||||||
local mod_weather = minetest_get_modpath("mcl_weather") ~= nil
|
local mod_weather = minetest_get_modpath("mcl_weather")
|
||||||
local mod_explosions = minetest_get_modpath("mcl_explosions") ~= nil
|
local mod_explosions = minetest_get_modpath("mcl_explosions")
|
||||||
local mod_mobspawners = minetest_get_modpath("mcl_mobspawners") ~= nil
|
local mod_mobspawners = minetest_get_modpath("mcl_mobspawners")
|
||||||
local mod_hunger = minetest_get_modpath("mcl_hunger") ~= nil
|
local mod_hunger = minetest_get_modpath("mcl_hunger")
|
||||||
local mod_worlds = minetest_get_modpath("mcl_worlds") ~= nil
|
local mod_worlds = minetest_get_modpath("mcl_worlds")
|
||||||
local mod_armor = minetest_get_modpath("mcl_armor") ~= nil
|
local mod_armor = minetest_get_modpath("mcl_armor")
|
||||||
local mod_experience = minetest_get_modpath("mcl_experience") ~= nil
|
local mod_experience = minetest_get_modpath("mcl_experience")
|
||||||
|
|
||||||
|
|
||||||
-- random locals I found
|
-- random locals I found
|
||||||
@ -743,7 +743,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
|
|||||||
nametag = string.sub(nametag, 1, MAX_MOB_NAME_LENGTH)
|
nametag = string.sub(nametag, 1, MAX_MOB_NAME_LENGTH)
|
||||||
end
|
end
|
||||||
ent.nametag = nametag
|
ent.nametag = nametag
|
||||||
update_tag(ent)
|
--update_tag(ent)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- if not in creative then take item
|
-- if not in creative then take item
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
local math_random = math.random
|
local math = math
|
||||||
local math_pi = math.pi
|
local vector = vector
|
||||||
local math_floor = math.floor
|
local string = string
|
||||||
local math_round = math.round
|
|
||||||
|
|
||||||
local vector_multiply = vector.multiply
|
local tonumber = tonumber
|
||||||
local vector_add = vector.add
|
|
||||||
local vector_new = vector.new
|
|
||||||
local vector_distance = vector.distance
|
|
||||||
|
|
||||||
local minetest_yaw_to_dir = minetest.yaw_to_dir
|
local minetest_yaw_to_dir = minetest.yaw_to_dir
|
||||||
local minetest_get_item_group = minetest.get_item_group
|
local minetest_get_item_group = minetest.get_item_group
|
||||||
@ -28,16 +24,16 @@ end
|
|||||||
|
|
||||||
--a simple helper function for rounding
|
--a simple helper function for rounding
|
||||||
--http://lua-users.org/wiki/SimpleRound
|
--http://lua-users.org/wiki/SimpleRound
|
||||||
function round2(num, numDecimalPlaces)
|
local function round2(num, numDecimalPlaces)
|
||||||
return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
|
return tonumber(string.format("%." .. (numDecimalPlaces or 0) .. "f", num))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
_ _
|
_ _
|
||||||
| | | |
|
| | | |
|
||||||
| | __ _ _ __ __| |
|
| | __ _ _ __ __| |
|
||||||
| | / _` | '_ \ / _` |
|
| | / _` | '_ \ / _` |
|
||||||
| |___| (_| | | | | (_| |
|
| |___| (_| | | | | (_| |
|
||||||
\_____/\__,_|_| |_|\__,_|
|
\_____/\__,_|_| |_|\__,_|
|
||||||
]]--
|
]]--
|
||||||
@ -50,24 +46,23 @@ local cliff_check = function(self,dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local dir = minetest_yaw_to_dir(self.yaw)
|
local dir = minetest_yaw_to_dir(self.yaw)
|
||||||
local collisionbox = self.object:get_properties().collisionbox
|
local collisionbox = self.object:get_properties().collisionbox
|
||||||
local radius = collisionbox[4] + 0.5
|
local radius = collisionbox[4] + 0.5
|
||||||
|
|
||||||
dir = vector_multiply(dir,radius)
|
dir = vector.multiply(dir,radius)
|
||||||
|
|
||||||
local free_fall, blocker = minetest_line_of_sight(
|
local free_fall = minetest_line_of_sight(
|
||||||
{x = pos.x + dir.x, y = pos.y, z = pos.z + dir.z},
|
{x = pos.x + dir.x, y = pos.y, z = pos.z + dir.z},
|
||||||
{x = pos.x + dir.x, y = pos.y - self.fear_height, z = pos.z + dir.z})
|
{x = pos.x + dir.x, y = pos.y - self.fear_height, z = pos.z + dir.z})
|
||||||
|
|
||||||
return free_fall
|
return free_fall
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- state switching logic (stand, walk, run, attacks)
|
-- state switching logic (stand, walk, run, attacks)
|
||||||
local land_state_list_wandering = {"stand", "walk"}
|
local land_state_list_wandering = {"stand", "walk"}
|
||||||
|
|
||||||
local land_state_switch = function(self, dtime)
|
local function land_state_switch(self, dtime)
|
||||||
|
|
||||||
--do math before sure not attacking, following, or running away so continue
|
--do math before sure not attacking, following, or running away so continue
|
||||||
--doing random walking for mobs if all states are not met
|
--doing random walking for mobs if all states are not met
|
||||||
@ -93,8 +88,8 @@ local land_state_switch = function(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--ignore everything else if following
|
--ignore everything else if following
|
||||||
if mobs.check_following(self) and
|
if mobs.check_following(self) and
|
||||||
(not self.breed_lookout_timer or (self.breed_lookout_timer and self.breed_lookout_timer == 0)) and
|
(not self.breed_lookout_timer or (self.breed_lookout_timer and self.breed_lookout_timer == 0)) and
|
||||||
(not self.breed_timer or (self.breed_timer and self.breed_timer == 0)) then
|
(not self.breed_timer or (self.breed_timer and self.breed_timer == 0)) then
|
||||||
self.state = "follow"
|
self.state = "follow"
|
||||||
return
|
return
|
||||||
@ -136,7 +131,6 @@ local land_state_execution = function(self,dtime)
|
|||||||
if not self.object:get_properties() then
|
if not self.object:get_properties() then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--timer to time out looking for mate
|
--timer to time out looking for mate
|
||||||
if self.breed_lookout_timer and self.breed_lookout_timer > 0 then
|
if self.breed_lookout_timer and self.breed_lookout_timer > 0 then
|
||||||
@ -176,12 +170,12 @@ local land_state_execution = function(self,dtime)
|
|||||||
if velocity.y < 0 then
|
if velocity.y < 0 then
|
||||||
--lua is acting really weird so we have to help it
|
--lua is acting really weird so we have to help it
|
||||||
if round2(self.object:get_acceleration().y, 1) == -self.gravity then
|
if round2(self.object:get_acceleration().y, 1) == -self.gravity then
|
||||||
self.object:set_acceleration(vector_new(0,0,0))
|
self.object:set_acceleration(vector.new(0,0,0))
|
||||||
mobs.mob_fall_slow(self)
|
mobs.mob_fall_slow(self)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if round2(self.object:get_acceleration().y, 1) == 0 then
|
if round2(self.object:get_acceleration().y, 1) == 0 then
|
||||||
self.object:set_acceleration(vector_new(0,-self.gravity,0))
|
self.object:set_acceleration(vector.new(0,-self.gravity,0))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -206,15 +200,13 @@ local land_state_execution = function(self,dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
mobs.lock_yaw(self)
|
mobs.lock_yaw(self)
|
||||||
elseif self.state == "follow" then
|
elseif self.state == "follow" then
|
||||||
|
|
||||||
--always look at players
|
--always look at players
|
||||||
mobs.set_yaw_while_following(self)
|
mobs.set_yaw_while_following(self)
|
||||||
|
|
||||||
--check distance
|
--check distance
|
||||||
local distance_from_follow_person = vector_distance(self.object:get_pos(), self.following_person:get_pos())
|
local distance_from_follow_person = vector.distance(self.object:get_pos(), self.following_person:get_pos())
|
||||||
local distance_2d = mobs.get_2d_distance(self.object:get_pos(), self.following_person:get_pos())
|
local distance_2d = mobs.get_2d_distance(self.object:get_pos(), self.following_person:get_pos())
|
||||||
|
|
||||||
--don't push the player if too close
|
--don't push the player if too close
|
||||||
--don't spin around randomly
|
--don't spin around randomly
|
||||||
if self.follow_distance < distance_from_follow_person and self.minimum_follow_distance < distance_2d then
|
if self.follow_distance < distance_from_follow_person and self.minimum_follow_distance < distance_2d then
|
||||||
@ -240,7 +232,7 @@ local land_state_execution = function(self,dtime)
|
|||||||
self.walk_timer = math.random(1,6) + math.random()
|
self.walk_timer = math.random(1,6) + math.random()
|
||||||
|
|
||||||
--set the mob into a random direction
|
--set the mob into a random direction
|
||||||
self.yaw = (math_random() * (math.pi * 2))
|
self.yaw = (math.random() * (math.pi * 2))
|
||||||
end
|
end
|
||||||
|
|
||||||
--do animation
|
--do animation
|
||||||
@ -253,15 +245,13 @@ local land_state_execution = function(self,dtime)
|
|||||||
local node_in_front_of = mobs.jump_check(self)
|
local node_in_front_of = mobs.jump_check(self)
|
||||||
|
|
||||||
if node_in_front_of == 1 then
|
if node_in_front_of == 1 then
|
||||||
|
|
||||||
mobs.jump(self)
|
mobs.jump(self)
|
||||||
|
--turn if on the edge of cliff
|
||||||
--turn if on the edge of cliff
|
--(this is written like this because unlike
|
||||||
--(this is written like this because unlike
|
--jump_check which simply tells the mob to jump
|
||||||
--jump_check which simply tells the mob to jump
|
--this requires a mob to turn, removing the
|
||||||
--this requires a mob to turn, removing the
|
--ease of a full implementation for it in a single
|
||||||
--ease of a full implementation for it in a single
|
--function)
|
||||||
--function)
|
|
||||||
elseif node_in_front_of == 2 or (self.fear_height ~= 0 and cliff_check(self,dtime)) then
|
elseif node_in_front_of == 2 or (self.fear_height ~= 0 and cliff_check(self,dtime)) then
|
||||||
--turn 45 degrees if so
|
--turn 45 degrees if so
|
||||||
quick_rotate(self,dtime)
|
quick_rotate(self,dtime)
|
||||||
@ -292,9 +282,7 @@ local land_state_execution = function(self,dtime)
|
|||||||
local node_in_front_of = mobs.jump_check(self)
|
local node_in_front_of = mobs.jump_check(self)
|
||||||
|
|
||||||
if node_in_front_of == 1 then
|
if node_in_front_of == 1 then
|
||||||
|
|
||||||
mobs.jump(self)
|
mobs.jump(self)
|
||||||
|
|
||||||
--turn if on the edge of cliff
|
--turn if on the edge of cliff
|
||||||
--(this is written like this because unlike
|
--(this is written like this because unlike
|
||||||
--jump_check which simply tells the mob to jump
|
--jump_check which simply tells the mob to jump
|
||||||
@ -342,7 +330,7 @@ local land_state_execution = function(self,dtime)
|
|||||||
mobs.set_velocity(self, self.walk_velocity)
|
mobs.set_velocity(self, self.walk_velocity)
|
||||||
|
|
||||||
--smoosh together basically
|
--smoosh together basically
|
||||||
if vector_distance(self.object:get_pos(), mate:get_pos()) <= self.breed_distance then
|
if vector.distance(self.object:get_pos(), mate:get_pos()) <= self.breed_distance then
|
||||||
mobs.set_mob_animation(self, "stand")
|
mobs.set_mob_animation(self, "stand")
|
||||||
if self.special_breed_timer == 0 then
|
if self.special_breed_timer == 0 then
|
||||||
self.special_breed_timer = 2 --breeding takes 2 seconds
|
self.special_breed_timer = 2 --breeding takes 2 seconds
|
||||||
@ -353,7 +341,7 @@ local land_state_execution = function(self,dtime)
|
|||||||
|
|
||||||
--pop a baby out, it's a miracle!
|
--pop a baby out, it's a miracle!
|
||||||
local baby_pos = vector.divide(vector.add(self.object:get_pos(), mate:get_pos()), 2)
|
local baby_pos = vector.divide(vector.add(self.object:get_pos(), mate:get_pos()), 2)
|
||||||
local baby_mob = minetest.add_entity(pos, self.name, minetest.serialize({baby = true, grow_up_timer = self.grow_up_goal, bred = true}))
|
minetest.add_entity(baby_pos, self.name, minetest.serialize({baby = true, grow_up_timer = self.grow_up_goal, bred = true}))
|
||||||
|
|
||||||
mobs.play_sound_specific(self,"item_drop_pickup")
|
mobs.play_sound_specific(self,"item_drop_pickup")
|
||||||
|
|
||||||
@ -375,14 +363,13 @@ local land_state_execution = function(self,dtime)
|
|||||||
mobs.set_velocity(self,0)
|
mobs.set_velocity(self,0)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if float_now then
|
if float_now then
|
||||||
mobs.float(self)
|
mobs.float(self)
|
||||||
else
|
else
|
||||||
local acceleration = self.object:get_acceleration()
|
local acceleration = self.object:get_acceleration()
|
||||||
if acceleration and acceleration.y == 0 then
|
if acceleration and acceleration.y == 0 then
|
||||||
self.object:set_acceleration(vector_new(0,-self.gravity,0))
|
self.object:set_acceleration(vector.new(0,-self.gravity,0))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -391,10 +378,10 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
_____ _
|
_____ _
|
||||||
/ ___| (_)
|
/ ___| (_)
|
||||||
\ `--.__ ___ _ __ ___
|
\ `--.__ ___ _ __ ___
|
||||||
`--. \ \ /\ / / | '_ ` _ \
|
`--. \ \ /\ / / | '_ ` _ \
|
||||||
/\__/ /\ V V /| | | | | | |
|
/\__/ /\ V V /| | | | | | |
|
||||||
\____/ \_/\_/ |_|_| |_| |_|
|
\____/ \_/\_/ |_|_| |_| |_|
|
||||||
]]--
|
]]--
|
||||||
@ -416,16 +403,16 @@ end
|
|||||||
--check if a mob needs to turn while swimming
|
--check if a mob needs to turn while swimming
|
||||||
local swim_turn_check = function(self,dtime)
|
local swim_turn_check = function(self,dtime)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
pos.y = pos.y + 0.1
|
pos.y = pos.y + 0.1
|
||||||
local dir = minetest_yaw_to_dir(self.yaw)
|
local dir = minetest_yaw_to_dir(self.yaw)
|
||||||
|
|
||||||
local collisionbox = self.object:get_properties().collisionbox
|
local collisionbox = self.object:get_properties().collisionbox
|
||||||
local radius = collisionbox[4] + 0.5
|
local radius = collisionbox[4] + 0.5
|
||||||
|
|
||||||
vector_multiply(dir, radius)
|
vector.multiply(dir, radius)
|
||||||
|
|
||||||
local test_dir = vector.add(pos,dir)
|
local test_dir = vector.add(pos,dir)
|
||||||
|
|
||||||
local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0
|
local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0
|
||||||
|
|
||||||
@ -437,11 +424,11 @@ local swim_physics_swapper = function(self,inside_swim_node)
|
|||||||
|
|
||||||
--should be swimming, gravity is applied, switch to floating
|
--should be swimming, gravity is applied, switch to floating
|
||||||
if inside_swim_node and self.object:get_acceleration().y ~= 0 then
|
if inside_swim_node and self.object:get_acceleration().y ~= 0 then
|
||||||
self.object:set_acceleration(vector_new(0,0,0))
|
self.object:set_acceleration(vector.new(0,0,0))
|
||||||
--not be swim, gravity isn't applied, switch to falling
|
--not be swim, gravity isn't applied, switch to falling
|
||||||
elseif not inside_swim_node and self.object:get_acceleration().y == 0 then
|
elseif not inside_swim_node and self.object:get_acceleration().y == 0 then
|
||||||
self.pitch = 0
|
self.pitch = 0
|
||||||
self.object:set_acceleration(vector_new(0,-self.gravity,0))
|
self.object:set_acceleration(vector.new(0,-self.gravity,0))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -482,22 +469,17 @@ local swim_state_execution = function(self,dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
mobs.lock_yaw(self)
|
mobs.lock_yaw(self)
|
||||||
|
|
||||||
elseif self.state == "swim" then
|
elseif self.state == "swim" then
|
||||||
|
|
||||||
self.walk_timer = self.walk_timer - dtime
|
self.walk_timer = self.walk_timer - dtime
|
||||||
|
|
||||||
--reset the walk timer
|
--reset the walk timer
|
||||||
if self.walk_timer <= 0 then
|
if self.walk_timer <= 0 then
|
||||||
|
|
||||||
--re-randomize the walk timer
|
--re-randomize the walk timer
|
||||||
self.walk_timer = math.random(1,6) + math.random()
|
self.walk_timer = math.random(1,6) + math.random()
|
||||||
|
|
||||||
--set the mob into a random direction
|
--set the mob into a random direction
|
||||||
self.yaw = (math_random() * (math.pi * 2))
|
self.yaw = (math.random() * (math.pi * 2))
|
||||||
|
|
||||||
--create a truly random pitch, since there is no easy access to pitch math that I can find
|
--create a truly random pitch, since there is no easy access to pitch math that I can find
|
||||||
self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)]
|
self.pitch = math.random() * math.random(1,3) * random_pitch_multiplier[math.random(1,2)]
|
||||||
end
|
end
|
||||||
|
|
||||||
--do animation
|
--do animation
|
||||||
@ -535,14 +517,14 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
______ _
|
______ _
|
||||||
| ___| |
|
| ___| |
|
||||||
| |_ | |_ _
|
| |_ | |_ _
|
||||||
| _| | | | | |
|
| _| | | | | |
|
||||||
| | | | |_| |
|
| | | | |_| |
|
||||||
\_| |_|\__, |
|
\_| |_|\__, |
|
||||||
__/ |
|
__/ |
|
||||||
|___/
|
|___/
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
-- state switching logic (stand, walk, run, attacks)
|
-- state switching logic (stand, walk, run, attacks)
|
||||||
@ -566,16 +548,16 @@ end
|
|||||||
--check if a mob needs to turn while flying
|
--check if a mob needs to turn while flying
|
||||||
local fly_turn_check = function(self,dtime)
|
local fly_turn_check = function(self,dtime)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
pos.y = pos.y + 0.1
|
pos.y = pos.y + 0.1
|
||||||
local dir = minetest_yaw_to_dir(self.yaw)
|
local dir = minetest_yaw_to_dir(self.yaw)
|
||||||
|
|
||||||
local collisionbox = self.object:get_properties().collisionbox
|
local collisionbox = self.object:get_properties().collisionbox
|
||||||
local radius = collisionbox[4] + 0.5
|
local radius = collisionbox[4] + 0.5
|
||||||
|
|
||||||
vector_multiply(dir, radius)
|
vector.multiply(dir, radius)
|
||||||
|
|
||||||
local test_dir = vector.add(pos,dir)
|
local test_dir = vector.add(pos,dir)
|
||||||
|
|
||||||
local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0
|
local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0
|
||||||
|
|
||||||
@ -587,11 +569,11 @@ local fly_physics_swapper = function(self,inside_fly_node)
|
|||||||
|
|
||||||
--should be flyming, gravity is applied, switch to floating
|
--should be flyming, gravity is applied, switch to floating
|
||||||
if inside_fly_node and self.object:get_acceleration().y ~= 0 then
|
if inside_fly_node and self.object:get_acceleration().y ~= 0 then
|
||||||
self.object:set_acceleration(vector_new(0,0,0))
|
self.object:set_acceleration(vector.new(0,0,0))
|
||||||
--not be fly, gravity isn't applied, switch to falling
|
--not be fly, gravity isn't applied, switch to falling
|
||||||
elseif not inside_fly_node and self.object:get_acceleration().y == 0 then
|
elseif not inside_fly_node and self.object:get_acceleration().y == 0 then
|
||||||
self.pitch = 0
|
self.pitch = 0
|
||||||
self.object:set_acceleration(vector_new(0,-self.gravity,0))
|
self.object:set_acceleration(vector.new(0,-self.gravity,0))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -635,15 +617,13 @@ local fly_state_execution = function(self,dtime)
|
|||||||
|
|
||||||
--reset the walk timer
|
--reset the walk timer
|
||||||
if self.walk_timer <= 0 then
|
if self.walk_timer <= 0 then
|
||||||
|
|
||||||
--re-randomize the walk timer
|
--re-randomize the walk timer
|
||||||
self.walk_timer = math.random(1,6) + math.random()
|
self.walk_timer = math.random(1,6) + math.random()
|
||||||
|
|
||||||
--set the mob into a random direction
|
--set the mob into a random direction
|
||||||
self.yaw = (math_random() * (math.pi * 2))
|
self.yaw = (math.random() * (math.pi * 2))
|
||||||
|
|
||||||
--create a truly random pitch, since there is no easy access to pitch math that I can find
|
--create a truly random pitch, since there is no easy access to pitch math that I can find
|
||||||
self.pitch = math_random() * math.random(1,3) * random_pitch_multiplier[math_random(1,2)]
|
self.pitch = math.random() * math.random(1,3) * random_pitch_multiplier[math.random(1,2)]
|
||||||
end
|
end
|
||||||
|
|
||||||
--do animation
|
--do animation
|
||||||
@ -663,9 +643,7 @@ local fly_state_execution = function(self,dtime)
|
|||||||
|
|
||||||
--enable rotation locking
|
--enable rotation locking
|
||||||
mobs.movement_rotation_lock(self)
|
mobs.movement_rotation_lock(self)
|
||||||
|
|
||||||
elseif self.state == "attack" then
|
elseif self.state == "attack" then
|
||||||
|
|
||||||
--execute mob attack type
|
--execute mob attack type
|
||||||
--if self.attack_type == "explode" then
|
--if self.attack_type == "explode" then
|
||||||
|
|
||||||
@ -697,40 +675,39 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
___
|
___
|
||||||
|_ |
|
|_ |
|
||||||
| |_ _ _ __ ___ _ __
|
| |_ _ _ __ ___ _ __
|
||||||
| | | | | '_ ` _ \| '_ \
|
| | | | | '_ ` _ \| '_ \
|
||||||
/\__/ / |_| | | | | | | |_) |
|
/\__/ / |_| | | | | | | |_) |
|
||||||
\____/ \__,_|_| |_| |_| .__/
|
\____/ \__,_|_| |_| |_| .__/
|
||||||
| |
|
| |
|
||||||
|_|
|
|_|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
|
|
||||||
--check if a mob needs to turn while jumping
|
--check if a mob needs to turn while jumping
|
||||||
local jump_turn_check = function(self,dtime)
|
--[[local function jump_turn_check(self, dtime)
|
||||||
|
local pos = self.object:get_pos()
|
||||||
|
pos.y = pos.y + 0.1
|
||||||
|
local dir = minetest_yaw_to_dir(self.yaw)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local collisionbox = self.object:get_properties().collisionbox
|
||||||
pos.y = pos.y + 0.1
|
|
||||||
local dir = minetest_yaw_to_dir(self.yaw)
|
|
||||||
|
|
||||||
local collisionbox = self.object:get_properties().collisionbox
|
|
||||||
local radius = collisionbox[4] + 0.5
|
local radius = collisionbox[4] + 0.5
|
||||||
|
|
||||||
vector_multiply(dir, radius)
|
vector.multiply(dir, radius)
|
||||||
|
|
||||||
local test_dir = vector.add(pos,dir)
|
local test_dir = vector.add(pos,dir)
|
||||||
|
|
||||||
local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0
|
local green_flag_1 = minetest_get_item_group(minetest_get_node(test_dir).name, "solid") ~= 0
|
||||||
|
|
||||||
return(green_flag_1)
|
return green_flag_1
|
||||||
end
|
end]]
|
||||||
|
|
||||||
-- state switching logic (stand, jump, run, attacks)
|
-- state switching logic (stand, jump, run, attacks)
|
||||||
local jump_state_list_wandering = {"stand", "jump"}
|
local jump_state_list_wandering = {"stand", "jump"}
|
||||||
|
|
||||||
local jump_state_switch = function(self, dtime)
|
local function jump_state_switch(self, dtime)
|
||||||
self.state_timer = self.state_timer - dtime
|
self.state_timer = self.state_timer - dtime
|
||||||
if self.state_timer <= 0 then
|
if self.state_timer <= 0 then
|
||||||
self.state_timer = math.random(4,10) + math.random()
|
self.state_timer = math.random(4,10) + math.random()
|
||||||
@ -739,8 +716,8 @@ local jump_state_switch = function(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- states are executed here
|
-- states are executed here
|
||||||
local jump_state_execution = function(self,dtime)
|
local function jump_state_execution(self, dtime)
|
||||||
|
local node_in_front_of = mobs.jump_check(self)
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local collisionbox = self.object:get_properties().collisionbox
|
local collisionbox = self.object:get_properties().collisionbox
|
||||||
--get the center of the mob
|
--get the center of the mob
|
||||||
@ -775,7 +752,7 @@ local jump_state_execution = function(self,dtime)
|
|||||||
self.walk_timer = math.random(1,6) + math.random()
|
self.walk_timer = math.random(1,6) + math.random()
|
||||||
|
|
||||||
--set the mob into a random direction
|
--set the mob into a random direction
|
||||||
self.yaw = (math_random() * (math.pi * 2))
|
self.yaw = (math.random() * (math.pi * 2))
|
||||||
end
|
end
|
||||||
|
|
||||||
--do animation
|
--do animation
|
||||||
@ -793,15 +770,10 @@ local jump_state_execution = function(self,dtime)
|
|||||||
mobs.jump_move(self,self.walk_velocity)
|
mobs.jump_move(self,self.walk_velocity)
|
||||||
|
|
||||||
elseif self.state == "run" then
|
elseif self.state == "run" then
|
||||||
|
|
||||||
print("run")
|
print("run")
|
||||||
|
|
||||||
elseif self.state == "attack" then
|
elseif self.state == "attack" then
|
||||||
|
|
||||||
print("attack")
|
print("attack")
|
||||||
|
end
|
||||||
end
|
|
||||||
|
|
||||||
if float_now then
|
if float_now then
|
||||||
mobs.float(self)
|
mobs.float(self)
|
||||||
end
|
end
|
||||||
@ -811,14 +783,14 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
___ ___ _ _ _
|
___ ___ _ _ _
|
||||||
| \/ | (_) | | (_)
|
| \/ | (_) | | (_)
|
||||||
| . . | __ _ _ _ __ | | ___ __ _ _ ___
|
| . . | __ _ _ _ __ | | ___ __ _ _ ___
|
||||||
| |\/| |/ _` | | '_ \ | | / _ \ / _` | |/ __|
|
| |\/| |/ _` | | '_ \ | | / _ \ / _` | |/ __|
|
||||||
| | | | (_| | | | | | | |___| (_) | (_| | | (__
|
| | | | (_| | | | | | | |___| (_) | (_| | | (__
|
||||||
\_| |_/\__,_|_|_| |_| \_____/\___/ \__, |_|\___|
|
\_| |_/\__,_|_|_| |_| \_____/\___/ \__, |_|\___|
|
||||||
__/ |
|
__/ |
|
||||||
|___/
|
|___/
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
--the main loop
|
--the main loop
|
||||||
@ -859,13 +831,13 @@ mobs.mob_step = function(self, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--color modifier which coincides with the pause_timer
|
--color modifier which coincides with the pause_timer
|
||||||
if self.old_health and self.health < self.old_health then
|
if self.old_health and self.health < self.old_health then
|
||||||
self.object:set_texture_mod("^[colorize:red:120")
|
self.object:set_texture_mod("^[colorize:red:120")
|
||||||
--fix double death sound
|
--fix double death sound
|
||||||
if self.health > 0 then
|
if self.health > 0 then
|
||||||
mobs.play_sound(self,"damage")
|
mobs.play_sound(self,"damage")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.old_health = self.health
|
self.old_health = self.health
|
||||||
|
|
||||||
--do death logic (animation, poof, explosion, etc)
|
--do death logic (animation, poof, explosion, etc)
|
||||||
@ -916,7 +888,6 @@ mobs.mob_step = function(self, dtime)
|
|||||||
|
|
||||||
elseif self.breath < self.breath_max then
|
elseif self.breath < self.breath_max then
|
||||||
self.breath = self.breath + dtime
|
self.breath = self.breath + dtime
|
||||||
|
|
||||||
--clean timer reset
|
--clean timer reset
|
||||||
if self.breath > self.breath_max then
|
if self.breath > self.breath_max then
|
||||||
self.breath = self.breath_max
|
self.breath = self.breath_max
|
||||||
@ -948,10 +919,6 @@ mobs.mob_step = function(self, dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--baby grows up
|
--baby grows up
|
||||||
if self.baby then
|
if self.baby then
|
||||||
--print(self.grow_up_timer)
|
--print(self.grow_up_timer)
|
||||||
@ -968,8 +935,6 @@ mobs.mob_step = function(self, dtime)
|
|||||||
mobs.baby_grow_up(self)
|
mobs.baby_grow_up(self)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--do custom mob instructions
|
--do custom mob instructions
|
||||||
if self.do_custom then
|
if self.do_custom then
|
||||||
@ -1015,7 +980,7 @@ mobs.mob_step = function(self, dtime)
|
|||||||
self.memory = self.memory - dtime
|
self.memory = self.memory - dtime
|
||||||
--get if memory player is within viewing range
|
--get if memory player is within viewing range
|
||||||
if self.attacking and self.attacking:is_player() then
|
if self.attacking and self.attacking:is_player() then
|
||||||
local distance = vector_distance(self.object:get_pos(), self.attacking:get_pos())
|
local distance = vector.distance(self.object:get_pos(), self.attacking:get_pos())
|
||||||
if distance > self.view_range then
|
if distance > self.view_range then
|
||||||
self.memory = 0
|
self.memory = 0
|
||||||
end
|
end
|
||||||
@ -1090,7 +1055,7 @@ mobs.mob_step = function(self, dtime)
|
|||||||
--jump only (like slimes)
|
--jump only (like slimes)
|
||||||
if self.jump_only then
|
if self.jump_only then
|
||||||
jump_state_switch(self, dtime)
|
jump_state_switch(self, dtime)
|
||||||
jump_state_execution(self, dtime)
|
jump_state_execution(self, dtime)
|
||||||
--swimming
|
--swimming
|
||||||
elseif self.swim then
|
elseif self.swim then
|
||||||
swim_state_switch(self, dtime)
|
swim_state_switch(self, dtime)
|
||||||
@ -1124,28 +1089,22 @@ mobs.mob_step = function(self, dtime)
|
|||||||
--overrides absolutely everything
|
--overrides absolutely everything
|
||||||
--mobs get stuck in cobwebs like players
|
--mobs get stuck in cobwebs like players
|
||||||
if not self.ignores_cobwebs then
|
if not self.ignores_cobwebs then
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local node = pos and minetest_get_node(pos).name
|
local node = pos and minetest_get_node(pos).name
|
||||||
|
|
||||||
if node == "mcl_core:cobweb" then
|
if node == "mcl_core:cobweb" then
|
||||||
|
|
||||||
--fight the rest of the api
|
--fight the rest of the api
|
||||||
if self.object:get_acceleration().y ~= 0 then
|
if self.object:get_acceleration().y ~= 0 then
|
||||||
self.object:set_acceleration(vector_new(0,0,0))
|
self.object:set_acceleration(vector.new(0,0,0))
|
||||||
end
|
end
|
||||||
|
|
||||||
mobs.stick_in_cobweb(self)
|
mobs.stick_in_cobweb(self)
|
||||||
|
|
||||||
self.was_stuck_in_cobweb = true
|
self.was_stuck_in_cobweb = true
|
||||||
|
|
||||||
else
|
else
|
||||||
--do not override other functions
|
--do not override other functions
|
||||||
if self.was_stuck_in_cobweb == true then
|
if self.was_stuck_in_cobweb == true then
|
||||||
--return the mob back to normal
|
--return the mob back to normal
|
||||||
self.was_stuck_in_cobweb = nil
|
self.was_stuck_in_cobweb = nil
|
||||||
if self.object:get_acceleration().y == 0 and not self.swim and not self.fly then
|
if self.object:get_acceleration().y == 0 and not self.swim and not self.fly then
|
||||||
self.object:set_acceleration(vector_new(0,-self.gravity,0))
|
self.object:set_acceleration(vector.new(0,-self.gravity,0))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
local math_pi = math.pi
|
local math = math
|
||||||
local math_floor = math.floor
|
local vector = vector
|
||||||
local math_random = math.random
|
|
||||||
local HALF_PI = math_pi/2
|
local HALF_PI = math.pi/2
|
||||||
|
|
||||||
|
|
||||||
local vector_direction = vector.direction
|
local vector_direction = vector.direction
|
||||||
@ -48,8 +48,7 @@ mobs.set_mob_animation = function(self, anim, fixed_frame)
|
|||||||
self.animation[anim .. "_speed"] or self.animation.speed_normal or 15,
|
self.animation[anim .. "_speed"] or self.animation.speed_normal or 15,
|
||||||
0, self.animation[anim .. "_loop"] ~= false)
|
0, self.animation[anim .. "_loop"] ~= false)
|
||||||
|
|
||||||
|
self.current_animation = anim
|
||||||
self.current_animation = anim
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -65,14 +64,14 @@ mobs.death_effect = function(pos, yaw, collisionbox, rotate)
|
|||||||
max = { x = 0.5, y = 0.5, z = 0.5 }
|
max = { x = 0.5, y = 0.5, z = 0.5 }
|
||||||
end
|
end
|
||||||
if rotate then
|
if rotate then
|
||||||
min = vector.rotate(min, {x=0, y=yaw, z=math_pi/2})
|
min = vector.rotate(min, {x=0, y=yaw, z=math.pi/2})
|
||||||
max = vector.rotate(max, {x=0, y=yaw, z=math_pi/2})
|
max = vector.rotate(max, {x=0, y=yaw, z=math.pi/2})
|
||||||
min, max = vector.sort(min, max)
|
min, max = vector.sort(min, max)
|
||||||
min = vector.multiply(min, 0.5)
|
min = vector.multiply(min, 0.5)
|
||||||
max = vector.multiply(max, 0.5)
|
max = vector.multiply(max, 0.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest_add_particlespawner({
|
minetest.add_particlespawner({
|
||||||
amount = 50,
|
amount = 50,
|
||||||
time = 0.001,
|
time = 0.001,
|
||||||
minpos = vector.add(pos, min),
|
minpos = vector.add(pos, min),
|
||||||
@ -88,7 +87,7 @@ mobs.death_effect = function(pos, yaw, collisionbox, rotate)
|
|||||||
texture = "mcl_particles_mob_death.png^[colorize:#000000:255",
|
texture = "mcl_particles_mob_death.png^[colorize:#000000:255",
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest_sound_play("mcl_mobs_mob_poof", {
|
minetest.sound_play("mcl_mobs_mob_poof", {
|
||||||
pos = pos,
|
pos = pos,
|
||||||
gain = 1.0,
|
gain = 1.0,
|
||||||
max_hear_distance = 8,
|
max_hear_distance = 8,
|
||||||
@ -99,7 +98,6 @@ end
|
|||||||
--this allows auto facedir rotation while making it so mobs
|
--this allows auto facedir rotation while making it so mobs
|
||||||
--don't look like wet noodles flopping around
|
--don't look like wet noodles flopping around
|
||||||
mobs.movement_rotation_lock = function(self)
|
mobs.movement_rotation_lock = function(self)
|
||||||
|
|
||||||
local current_engine_yaw = self.object:get_yaw()
|
local current_engine_yaw = self.object:get_yaw()
|
||||||
local current_lua_yaw = self.yaw
|
local current_lua_yaw = self.yaw
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
local vector_direction = vector.direction
|
local vector_direction = vector.direction
|
||||||
local minetest_dir_to_yaw = minetest.dir_to_yaw
|
--local minetest_dir_to_yaw = minetest.dir_to_yaw
|
||||||
local vector_distance = vector.distance
|
local vector_distance = vector.distance
|
||||||
local vector_multiply = vector.multiply
|
local vector_multiply = vector.multiply
|
||||||
local math_random = math.random
|
local math_random = math.random
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
_ _ _ _
|
_ _ _ _
|
||||||
| | | | | | | |
|
| | | | | | | |
|
||||||
| | | | __ _ _ __ __| | | |
|
| | | | __ _ _ __ __| | | |
|
||||||
| | | | / _` | '_ \ / _` | | |
|
| | | | / _` | '_ \ / _` | | |
|
||||||
@ -16,14 +16,14 @@ local math_random = math.random
|
|||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
_____ _ _
|
_____ _ _
|
||||||
| ___| | | | |
|
| ___| | | | |
|
||||||
| |____ ___ __ | | ___ __| | ___
|
| |____ ___ __ | | ___ __| | ___
|
||||||
| __\ \/ / '_ \| |/ _ \ / _` |/ _ \
|
| __\ \/ / '_ \| |/ _ \ / _` |/ _ \
|
||||||
| |___> <| |_) | | (_) | (_| | __/
|
| |___> <| |_) | | (_) | (_| | __/
|
||||||
\____/_/\_\ .__/|_|\___/ \__,_|\___|
|
\____/_/\_\ .__/|_|\___/ \__,_|\___|
|
||||||
| |
|
| |
|
||||||
|_|
|
|_|
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
mobs.explode_attack_walk = function(self,dtime)
|
mobs.explode_attack_walk = function(self,dtime)
|
||||||
@ -74,7 +74,6 @@ mobs.explode_attack_walk = function(self,dtime)
|
|||||||
if node_in_front_of == 1 then
|
if node_in_front_of == 1 then
|
||||||
mobs.jump(self)
|
mobs.jump(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--do biggening explosion thing
|
--do biggening explosion thing
|
||||||
if self.explosion_animation and self.explosion_animation > self.explosion_timer then
|
if self.explosion_animation and self.explosion_animation > self.explosion_timer then
|
||||||
@ -102,10 +101,10 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
______ _
|
______ _
|
||||||
| ___ \ | |
|
| ___ \ | |
|
||||||
| |_/ / _ _ __ ___| |__
|
| |_/ / _ _ __ ___| |__
|
||||||
| __/ | | | '_ \ / __| '_ \
|
| __/ | | | '_ \ / __| '_ \
|
||||||
| | | |_| | | | | (__| | | |
|
| | | |_| | | | | (__| | | |
|
||||||
\_| \__,_|_| |_|\___|_| |_|
|
\_| \__,_|_| |_|\___|_| |_|
|
||||||
]]--
|
]]--
|
||||||
@ -113,7 +112,6 @@ ______ _
|
|||||||
|
|
||||||
|
|
||||||
mobs.punch_attack_walk = function(self,dtime)
|
mobs.punch_attack_walk = function(self,dtime)
|
||||||
|
|
||||||
--this needs an exception
|
--this needs an exception
|
||||||
if self.attacking == nil or not self.attacking:is_player() then
|
if self.attacking == nil or not self.attacking:is_player() then
|
||||||
self.attacking = nil
|
self.attacking = nil
|
||||||
@ -187,14 +185,14 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
______ _ _ _ _
|
______ _ _ _ _
|
||||||
| ___ \ (_) | | (_) |
|
| ___ \ (_) | | (_) |
|
||||||
| |_/ / __ ___ _ ___ ___| |_ _| | ___
|
| |_/ / __ ___ _ ___ ___| |_ _| | ___
|
||||||
| __/ '__/ _ \| |/ _ \/ __| __| | |/ _ \
|
| __/ '__/ _ \| |/ _ \/ __| __| | |/ _ \
|
||||||
| | | | | (_) | | __/ (__| |_| | | __/
|
| | | | | (_) | | __/ (__| |_| | | __/
|
||||||
\_| |_| \___/| |\___|\___|\__|_|_|\___|
|
\_| |_| \___/| |\___|\___|\__|_|_|\___|
|
||||||
_/ |
|
_/ |
|
||||||
|__/
|
|__/
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
|
|
||||||
@ -255,40 +253,39 @@ end
|
|||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
_ ______ _ _
|
_ ______ _ _
|
||||||
| | | ___| | | |
|
| | | ___| | | |
|
||||||
| | | |_ | |_ _ | |
|
| | | |_ | |_ _ | |
|
||||||
| | | _| | | | | | | |
|
| | | _| | | | | | | |
|
||||||
|_| | | | | |_| | |_|
|
|_| | | | | |_| | |_|
|
||||||
(_) \_| |_|\__, | (_)
|
(_) \_| |_|\__, | (_)
|
||||||
__/ |
|
__/ |
|
||||||
|___/
|
|___/
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
______ _ _ _ _
|
______ _ _ _ _
|
||||||
| ___ \ (_) | | (_) |
|
| ___ \ (_) | | (_) |
|
||||||
| |_/ / __ ___ _ ___ ___| |_ _| | ___
|
| |_/ / __ ___ _ ___ ___| |_ _| | ___
|
||||||
| __/ '__/ _ \| |/ _ \/ __| __| | |/ _ \
|
| __/ '__/ _ \| |/ _ \/ __| __| | |/ _ \
|
||||||
| | | | | (_) | | __/ (__| |_| | | __/
|
| | | | | (_) | | __/ (__| |_| | | __/
|
||||||
\_| |_| \___/| |\___|\___|\__|_|_|\___|
|
\_| |_| \___/| |\___|\___|\__|_|_|\___|
|
||||||
_/ |
|
_/ |
|
||||||
|__/
|
|__/
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
local random_pitch_multiplier = {-1,1}
|
local random_pitch_multiplier = {-1,1}
|
||||||
|
|
||||||
mobs.projectile_attack_fly = function(self, dtime)
|
mobs.projectile_attack_fly = function(self, dtime)
|
||||||
|
|
||||||
--this needs an exception
|
--this needs an exception
|
||||||
if self.attacking == nil or not self.attacking:is_player() then
|
if self.attacking == nil or not self.attacking:is_player() then
|
||||||
self.attacking = nil
|
self.attacking = nil
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
--this is specifically for random ghast movement
|
--this is specifically for random ghast movement
|
||||||
if self.fly_random_while_attack then
|
if self.fly_random_while_attack then
|
||||||
|
|
||||||
@ -315,7 +312,7 @@ mobs.projectile_attack_fly = function(self, dtime)
|
|||||||
|
|
||||||
local distance_from_attacking = vector_distance(self.object:get_pos(), self.attacking:get_pos())
|
local distance_from_attacking = vector_distance(self.object:get_pos(), self.attacking:get_pos())
|
||||||
|
|
||||||
if distance_from_attacking >= self.reach then
|
if distance_from_attacking >= self.reach then
|
||||||
mobs.set_pitch_while_attacking(self)
|
mobs.set_pitch_while_attacking(self)
|
||||||
mobs.set_fly_velocity(self, self.run_velocity)
|
mobs.set_fly_velocity(self, self.run_velocity)
|
||||||
mobs.set_mob_animation(self,"run")
|
mobs.set_mob_animation(self,"run")
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
local disable_physics = function(object, luaentity, ignore_check, reset_movement)
|
local math = math
|
||||||
|
local vector = vector
|
||||||
|
|
||||||
|
local function disable_physics(object, luaentity, ignore_check, reset_movement)
|
||||||
if luaentity.physical_state == true or ignore_check == true then
|
if luaentity.physical_state == true or ignore_check == true then
|
||||||
luaentity.physical_state = false
|
luaentity.physical_state = false
|
||||||
object:set_properties({
|
object:set_properties({
|
||||||
@ -12,7 +15,7 @@ local disable_physics = function(object, luaentity, ignore_check, reset_movement
|
|||||||
end
|
end
|
||||||
|
|
||||||
----For Water Flowing:
|
----For Water Flowing:
|
||||||
local enable_physics = function(object, luaentity, ignore_check)
|
local function enable_physics(object, luaentity, ignore_check)
|
||||||
if luaentity.physical_state == false or ignore_check == true then
|
if luaentity.physical_state == false or ignore_check == true then
|
||||||
luaentity.physical_state = true
|
luaentity.physical_state = true
|
||||||
object:set_properties({
|
object:set_properties({
|
||||||
@ -272,7 +275,7 @@ local falling = function(self, pos)
|
|||||||
|
|
||||||
self.object:set_acceleration({
|
self.object:set_acceleration({
|
||||||
x = 0,
|
x = 0,
|
||||||
y = -self.fall_speed / (math_max(1, v.y) ^ 2),
|
y = -self.fall_speed / (math.max(1, v.y) ^ 2),
|
||||||
z = 0
|
z = 0
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
@ -503,9 +506,9 @@ local follow_flop = function(self)
|
|||||||
if sdef and sdef.walkable then
|
if sdef and sdef.walkable then
|
||||||
mob_sound(self, "flop")
|
mob_sound(self, "flop")
|
||||||
self.object:set_velocity({
|
self.object:set_velocity({
|
||||||
x = math_random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
|
x = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
|
||||||
y = FLOP_HEIGHT,
|
y = FLOP_HEIGHT,
|
||||||
z = math_random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
|
z = math.random(-FLOP_HOR_SPEED, FLOP_HOR_SPEED),
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -987,7 +990,7 @@ local check_for_death = function(self, cause, cmi_cause)
|
|||||||
item_drop(self, cooked, looting)
|
item_drop(self, cooked, looting)
|
||||||
|
|
||||||
if mod_experience and ((not self.child) or self.type ~= "animal") and (minetest_get_us_time() - self.xp_timestamp <= 5000000) then
|
if mod_experience and ((not self.child) or self.type ~= "animal") and (minetest_get_us_time() - self.xp_timestamp <= 5000000) then
|
||||||
mcl_experience.throw_experience(self.object:get_pos(), math_random(self.xp_min, self.xp_max))
|
mcl_experience.throw_experience(self.object:get_pos(), math.random(self.xp_min, self.xp_max))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1361,7 +1364,7 @@ local do_attack = function(self, player)
|
|||||||
self.state = "attack"
|
self.state = "attack"
|
||||||
|
|
||||||
-- TODO: Implement war_cry sound without being annoying
|
-- TODO: Implement war_cry sound without being annoying
|
||||||
--if math_random(0, 100) < 90 then
|
--if math.random(0, 100) < 90 then
|
||||||
--mob_sound(self, "war_cry", true)
|
--mob_sound(self, "war_cry", true)
|
||||||
--end
|
--end
|
||||||
end
|
end
|
||||||
@ -1396,7 +1399,7 @@ local mob_sound = function(self, soundname, is_opinion, fixed_pitch)
|
|||||||
pitch = base_pitch
|
pitch = base_pitch
|
||||||
end
|
end
|
||||||
-- randomize the pitch a bit
|
-- randomize the pitch a bit
|
||||||
pitch = pitch + math_random(-10, 10) * 0.005
|
pitch = pitch + math.random(-10, 10) * 0.005
|
||||||
end
|
end
|
||||||
minetest_sound_play(sound, {
|
minetest_sound_play(sound, {
|
||||||
object = self.object,
|
object = self.object,
|
||||||
@ -1699,7 +1702,7 @@ local do_env_damage = function(self)
|
|||||||
end
|
end
|
||||||
if drowning then
|
if drowning then
|
||||||
|
|
||||||
self.breath = math_max(0, self.breath - 1)
|
self.breath = math.max(0, self.breath - 1)
|
||||||
|
|
||||||
effect(pos, 2, "bubble.png", nil, nil, 1, nil)
|
effect(pos, 2, "bubble.png", nil, nil, 1, nil)
|
||||||
if self.breath <= 0 then
|
if self.breath <= 0 then
|
||||||
@ -2044,7 +2047,7 @@ local breed = function(self)
|
|||||||
|
|
||||||
-- Give XP
|
-- Give XP
|
||||||
if mod_experience then
|
if mod_experience then
|
||||||
mcl_experience.throw_experience(pos, math_random(1, 7))
|
mcl_experience.throw_experience(pos, math.random(1, 7))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- custom breed function
|
-- custom breed function
|
||||||
@ -2061,7 +2064,7 @@ local breed = function(self)
|
|||||||
|
|
||||||
|
|
||||||
-- Use texture of one of the parents
|
-- Use texture of one of the parents
|
||||||
local p = math_random(1, 2)
|
local p = math.random(1, 2)
|
||||||
if p == 1 then
|
if p == 1 then
|
||||||
ent_c.base_texture = parent1.base_texture
|
ent_c.base_texture = parent1.base_texture
|
||||||
else
|
else
|
||||||
@ -2091,7 +2094,7 @@ local replace = function(self, pos)
|
|||||||
or not self.replace_what
|
or not self.replace_what
|
||||||
or self.child == true
|
or self.child == true
|
||||||
or self.object:get_velocity().y ~= 0
|
or self.object:get_velocity().y ~= 0
|
||||||
or math_random(1, self.replace_rate) > 1 then
|
or math.random(1, self.replace_rate) > 1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2099,7 +2102,7 @@ local replace = function(self, pos)
|
|||||||
|
|
||||||
if type(self.replace_what[1]) == "table" then
|
if type(self.replace_what[1]) == "table" then
|
||||||
|
|
||||||
local num = math_random(#self.replace_what)
|
local num = math.random(#self.replace_what)
|
||||||
|
|
||||||
what = self.replace_what[num][1] or ""
|
what = self.replace_what[num][1] or ""
|
||||||
with = self.replace_what[num][2] or ""
|
with = self.replace_what[num][2] or ""
|
||||||
@ -2163,7 +2166,7 @@ function do_states(self)
|
|||||||
|
|
||||||
if self.state == "stand" then
|
if self.state == "stand" then
|
||||||
|
|
||||||
if math_random(1, 4) == 1 then
|
if math.random(1, 4) == 1 then
|
||||||
|
|
||||||
local lp = nil
|
local lp = nil
|
||||||
local s = self.object:get_pos()
|
local s = self.object:get_pos()
|
||||||
@ -2189,7 +2192,7 @@ function do_states(self)
|
|||||||
|
|
||||||
if lp.x > s.x then yaw = yaw + math_pi end
|
if lp.x > s.x then yaw = yaw + math_pi end
|
||||||
else
|
else
|
||||||
yaw = yaw + math_random(-0.5, 0.5)
|
yaw = yaw + math.random(-0.5, 0.5)
|
||||||
end
|
end
|
||||||
|
|
||||||
yaw = set_yaw(self, yaw, 8)
|
yaw = set_yaw(self, yaw, 8)
|
||||||
@ -2204,7 +2207,7 @@ function do_states(self)
|
|||||||
|
|
||||||
if self.walk_chance ~= 0
|
if self.walk_chance ~= 0
|
||||||
and self.facing_fence ~= true
|
and self.facing_fence ~= true
|
||||||
and math_random(1, 100) <= self.walk_chance
|
and math.random(1, 100) <= self.walk_chance
|
||||||
and is_at_cliff_or_danger(self) == false then
|
and is_at_cliff_or_danger(self) == false then
|
||||||
|
|
||||||
set_velocity(self, self.walk_velocity)
|
set_velocity(self, self.walk_velocity)
|
||||||
@ -2254,7 +2257,7 @@ function do_states(self)
|
|||||||
{x = s.x + 5, y = s.y + 1, z = s.z + 5},
|
{x = s.x + 5, y = s.y + 1, z = s.z + 5},
|
||||||
{"group:solid"})
|
{"group:solid"})
|
||||||
|
|
||||||
lp = #lp > 0 and lp[math_random(#lp)]
|
lp = #lp > 0 and lp[math.random(#lp)]
|
||||||
|
|
||||||
-- did we find land?
|
-- did we find land?
|
||||||
if lp then
|
if lp then
|
||||||
@ -2280,8 +2283,8 @@ function do_states(self)
|
|||||||
else
|
else
|
||||||
|
|
||||||
-- Randomly turn
|
-- Randomly turn
|
||||||
if math_random(1, 100) <= 30 then
|
if math.random(1, 100) <= 30 then
|
||||||
yaw = yaw + math_random(-0.5, 0.5)
|
yaw = yaw + math.random(-0.5, 0.5)
|
||||||
yaw = set_yaw(self, yaw, 8)
|
yaw = set_yaw(self, yaw, 8)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -2289,9 +2292,9 @@ function do_states(self)
|
|||||||
yaw = set_yaw(self, yaw, 8)
|
yaw = set_yaw(self, yaw, 8)
|
||||||
|
|
||||||
-- otherwise randomly turn
|
-- otherwise randomly turn
|
||||||
elseif math_random(1, 100) <= 30 then
|
elseif math.random(1, 100) <= 30 then
|
||||||
|
|
||||||
yaw = yaw + math_random(-0.5, 0.5)
|
yaw = yaw + math.random(-0.5, 0.5)
|
||||||
yaw = set_yaw(self, yaw, 8)
|
yaw = set_yaw(self, yaw, 8)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2302,7 +2305,7 @@ function do_states(self)
|
|||||||
end
|
end
|
||||||
if self.facing_fence == true
|
if self.facing_fence == true
|
||||||
or cliff_or_danger
|
or cliff_or_danger
|
||||||
or math_random(1, 100) <= 30 then
|
or math.random(1, 100) <= 30 then
|
||||||
|
|
||||||
set_velocity(self, 0)
|
set_velocity(self, 0)
|
||||||
self.state = "stand"
|
self.state = "stand"
|
||||||
@ -2602,7 +2605,7 @@ function do_states(self)
|
|||||||
self.timer = 0
|
self.timer = 0
|
||||||
|
|
||||||
if self.double_melee_attack
|
if self.double_melee_attack
|
||||||
and math_random(1, 2) == 1 then
|
and math.random(1, 2) == 1 then
|
||||||
set_animation(self, "punch2")
|
set_animation(self, "punch2")
|
||||||
else
|
else
|
||||||
set_animation(self, "punch")
|
set_animation(self, "punch")
|
||||||
@ -2669,7 +2672,7 @@ function do_states(self)
|
|||||||
if self.shoot_interval
|
if self.shoot_interval
|
||||||
and self.timer > self.shoot_interval
|
and self.timer > self.shoot_interval
|
||||||
and not minetest_raycast(p, self.attack:get_pos(), false, false):next()
|
and not minetest_raycast(p, self.attack:get_pos(), false, false):next()
|
||||||
and math_random(1, 100) <= 60 then
|
and math.random(1, 100) <= 60 then
|
||||||
|
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
set_animation(self, "shoot")
|
set_animation(self, "shoot")
|
||||||
@ -2759,7 +2762,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
-- Code to execute before custom on_rightclick handling
|
-- Code to execute before custom on_rightclick handling
|
||||||
local on_rightclick_prefix = function(self, clicker)
|
local function on_rightclick_prefix(self, clicker)
|
||||||
local item = clicker:get_wielded_item()
|
local item = clicker:get_wielded_item()
|
||||||
|
|
||||||
-- Name mob with nametag
|
-- Name mob with nametag
|
||||||
@ -2785,17 +2788,17 @@ local on_rightclick_prefix = function(self, clicker)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local create_mob_on_rightclick = function(on_rightclick)
|
--[[local function create_mob_on_rightclick(on_rightclick)
|
||||||
return function(self, clicker)
|
return function(self, clicker)
|
||||||
local stop = on_rightclick_prefix(self, clicker)
|
local stop = on_rightclick_prefix(self, clicker)
|
||||||
if (not stop) and (on_rightclick) then
|
if (not stop) and (on_rightclick) then
|
||||||
on_rightclick(self, clicker)
|
on_rightclick(self, clicker)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end]]
|
||||||
|
|
||||||
-- set and return valid yaw
|
-- set and return valid yaw
|
||||||
local set_yaw = function(self, yaw, delay, dtime)
|
local function set_yaw(self, yaw, delay, dtime)
|
||||||
|
|
||||||
if not yaw or yaw ~= yaw then
|
if not yaw or yaw ~= yaw then
|
||||||
yaw = 0
|
yaw = 0
|
||||||
@ -2805,7 +2808,7 @@ local set_yaw = function(self, yaw, delay, dtime)
|
|||||||
|
|
||||||
if delay == 0 then
|
if delay == 0 then
|
||||||
if self.shaking and dtime then
|
if self.shaking and dtime then
|
||||||
yaw = yaw + (math_random() * 2 - 1) * 5 * dtime
|
yaw = yaw + (math.random() * 2 - 1) * 5 * dtime
|
||||||
end
|
end
|
||||||
self.yaw(yaw)
|
self.yaw(yaw)
|
||||||
update_roll(self)
|
update_roll(self)
|
||||||
@ -2825,8 +2828,7 @@ function mobs:yaw(self, yaw, delay, dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
mob_step = function()
|
--mob_step = function()
|
||||||
|
|
||||||
--if self.state == "die" then
|
--if self.state == "die" then
|
||||||
-- print("need custom die stop moving thing")
|
-- print("need custom die stop moving thing")
|
||||||
-- return
|
-- return
|
||||||
@ -2901,7 +2903,7 @@ mob_step = function()
|
|||||||
--end
|
--end
|
||||||
|
|
||||||
-- mob plays random sound at times
|
-- mob plays random sound at times
|
||||||
--if math_random(1, 70) == 1 then
|
--if math.random(1, 70) == 1 then
|
||||||
-- mob_sound(self, "random", true)
|
-- mob_sound(self, "random", true)
|
||||||
--end
|
--end
|
||||||
|
|
||||||
@ -2934,11 +2936,11 @@ mob_step = function()
|
|||||||
|
|
||||||
|
|
||||||
--if is_at_water_danger(self) and self.state ~= "attack" then
|
--if is_at_water_danger(self) and self.state ~= "attack" then
|
||||||
-- if math_random(1, 10) <= 6 then
|
-- if math.random(1, 10) <= 6 then
|
||||||
-- set_velocity(self, 0)
|
-- set_velocity(self, 0)
|
||||||
-- self.state = "stand"
|
-- self.state = "stand"
|
||||||
-- set_animation(self, "stand")
|
-- set_animation(self, "stand")
|
||||||
-- yaw = yaw + math_random(-0.5, 0.5)
|
-- yaw = yaw + math.random(-0.5, 0.5)
|
||||||
-- yaw = set_yaw(self, yaw, 8)
|
-- yaw = set_yaw(self, yaw, 8)
|
||||||
-- end
|
-- end
|
||||||
--end
|
--end
|
||||||
@ -2982,7 +2984,7 @@ mob_step = function()
|
|||||||
mcl_burning.extinguish(self.object)
|
mcl_burning.extinguish(self.object)
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
elseif self.lifetimer <= 10 then
|
elseif self.lifetimer <= 10 then
|
||||||
if math_random(10) < 4 then
|
if math.random(10) < 4 then
|
||||||
self.despawn_immediately = true
|
self.despawn_immediately = true
|
||||||
else
|
else
|
||||||
self.lifetimer = 20
|
self.lifetimer = 20
|
||||||
@ -2991,4 +2993,4 @@ mob_step = function()
|
|||||||
end
|
end
|
||||||
]]--
|
]]--
|
||||||
|
|
||||||
end
|
--end
|
@ -1,14 +1,13 @@
|
|||||||
local minetest_get_objects_inside_radius = minetest.get_objects_inside_radius
|
local minetest_get_objects_inside_radius = minetest.get_objects_inside_radius
|
||||||
|
|
||||||
local vector_distance = vector.distance
|
local vector = vector
|
||||||
|
|
||||||
--check to see if someone nearby has some tasty food
|
--check to see if someone nearby has some tasty food
|
||||||
mobs.check_following = function(self) -- returns true or false
|
mobs.check_following = function(self) -- returns true or false
|
||||||
|
|
||||||
--ignore
|
--ignore
|
||||||
if not self.follow then
|
if not self.follow then
|
||||||
self.following_person = nil
|
self.following_person = nil
|
||||||
return(false)
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--hey look, this thing works for passive mobs too!
|
--hey look, this thing works for passive mobs too!
|
||||||
@ -20,20 +19,20 @@ mobs.check_following = function(self) -- returns true or false
|
|||||||
--safety check
|
--safety check
|
||||||
if not stack then
|
if not stack then
|
||||||
self.following_person = nil
|
self.following_person = nil
|
||||||
return(false)
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local item_name = stack:get_name()
|
local item_name = stack:get_name()
|
||||||
--all checks have passed, that guy has some good looking food
|
--all checks have passed, that guy has some good looking food
|
||||||
if item_name == self.follow then
|
if item_name == self.follow then
|
||||||
self.following_person = follower
|
self.following_person = follower
|
||||||
return(true)
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--everything failed
|
--everything failed
|
||||||
self.following_person = nil
|
self.following_person = nil
|
||||||
return(false)
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--a function which attempts to make mobs enter
|
--a function which attempts to make mobs enter
|
||||||
@ -42,30 +41,30 @@ mobs.enter_breed_state = function(self,clicker)
|
|||||||
|
|
||||||
--do not breed if baby
|
--do not breed if baby
|
||||||
if self.baby then
|
if self.baby then
|
||||||
return(false)
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--do not do anything if looking for mate or
|
--do not do anything if looking for mate or
|
||||||
--if cooling off from breeding
|
--if cooling off from breeding
|
||||||
if self.breed_lookout_timer > 0 or self.breed_timer > 0 then
|
if self.breed_lookout_timer > 0 or self.breed_timer > 0 then
|
||||||
return(false)
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--if this is caught, that means something has gone
|
--if this is caught, that means something has gone
|
||||||
--seriously wrong
|
--seriously wrong
|
||||||
if not clicker or not clicker:is_player() then
|
if not clicker or not clicker:is_player() then
|
||||||
return(false)
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local stack = clicker:get_wielded_item()
|
local stack = clicker:get_wielded_item()
|
||||||
--safety check
|
--safety check
|
||||||
if not stack then
|
if not stack then
|
||||||
return(false)
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local item_name = stack:get_name()
|
local item_name = stack:get_name()
|
||||||
--all checks have passed, that guy has some good looking food
|
--all checks have passed, that guy has some good looking food
|
||||||
if item_name == self.follow then
|
if item_name == self.follow then
|
||||||
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
||||||
stack:take_item()
|
stack:take_item()
|
||||||
clicker:set_wielded_item(stack)
|
clicker:set_wielded_item(stack)
|
||||||
@ -73,11 +72,11 @@ mobs.enter_breed_state = function(self,clicker)
|
|||||||
self.breed_lookout_timer = self.breed_lookout_timer_goal
|
self.breed_lookout_timer = self.breed_lookout_timer_goal
|
||||||
self.bred = true
|
self.bred = true
|
||||||
mobs.play_sound_specific(self,"mobs_mc_animal_eat_generic")
|
mobs.play_sound_specific(self,"mobs_mc_animal_eat_generic")
|
||||||
return(true)
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
--everything failed
|
--everything failed
|
||||||
return(false)
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -96,23 +95,23 @@ mobs.look_for_mate = function(self)
|
|||||||
for _,mate in pairs(minetest_get_objects_inside_radius(pos1, radius)) do
|
for _,mate in pairs(minetest_get_objects_inside_radius(pos1, radius)) do
|
||||||
|
|
||||||
--look for a breeding mate
|
--look for a breeding mate
|
||||||
if mate and mate:get_luaentity()
|
if mate and mate:get_luaentity()
|
||||||
and mate:get_luaentity()._cmi_is_mob
|
and mate:get_luaentity()._cmi_is_mob
|
||||||
and mate:get_luaentity().name == self.name
|
and mate:get_luaentity().name == self.name
|
||||||
and mate:get_luaentity().breed_lookout_timer > 0
|
and mate:get_luaentity().breed_lookout_timer > 0
|
||||||
and mate:get_luaentity() ~= self then
|
and mate:get_luaentity() ~= self then
|
||||||
|
|
||||||
local pos2 = mate:get_pos()
|
local pos2 = mate:get_pos()
|
||||||
|
|
||||||
local distance = vector_distance(pos1,pos2)
|
local distance = vector.distance(pos1,pos2)
|
||||||
|
|
||||||
if distance <= radius then
|
if distance <= radius then
|
||||||
if line_of_sight then
|
if minetest.line_of_sight then
|
||||||
--must add eye height or stuff breaks randomly because of
|
--must add eye height or stuff breaks randomly because of
|
||||||
--seethrough nodes being a blocker (like grass)
|
--seethrough nodes being a blocker (like grass)
|
||||||
if minetest_line_of_sight(
|
if minetest.line_of_sight(
|
||||||
vector_new(pos1.x, pos1.y, pos1.z),
|
vector.new(pos1.x, pos1.y, pos1.z),
|
||||||
vector_new(pos2.x, pos2.y + mate:get_properties().eye_height, pos2.z)
|
vector.new(pos2.x, pos2.y + mate:get_properties().eye_height, pos2.z)
|
||||||
) then
|
) then
|
||||||
mates_detected = mates_detected + 1
|
mates_detected = mates_detected + 1
|
||||||
mates_in_area[mate] = distance
|
mates_in_area[mate] = distance
|
||||||
@ -160,14 +159,14 @@ mobs.make_baby_grow_faster = function(self,clicker)
|
|||||||
if clicker and clicker:is_player() then
|
if clicker and clicker:is_player() then
|
||||||
local stack = clicker:get_wielded_item()
|
local stack = clicker:get_wielded_item()
|
||||||
--safety check
|
--safety check
|
||||||
if not stack then
|
if not stack then
|
||||||
return(false)
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local item_name = stack:get_name()
|
local item_name = stack:get_name()
|
||||||
--all checks have passed, that guy has some good looking food
|
--all checks have passed, that guy has some good looking food
|
||||||
if item_name == self.follow then
|
if item_name == self.follow then
|
||||||
self.grow_up_timer = self.grow_up_timer - (self.grow_up_timer * 0.10) --take 10 percent off - diminishing returns
|
self.grow_up_timer = self.grow_up_timer - (self.grow_up_timer * 0.10) --take 10 percent off - diminishing returns
|
||||||
|
|
||||||
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
||||||
stack:take_item()
|
stack:take_item()
|
||||||
@ -175,10 +174,8 @@ mobs.make_baby_grow_faster = function(self,clicker)
|
|||||||
end
|
end
|
||||||
|
|
||||||
mobs.play_sound_specific(self,"mobs_mc_animal_eat_generic")
|
mobs.play_sound_specific(self,"mobs_mc_animal_eat_generic")
|
||||||
|
return true
|
||||||
return(true)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return false
|
||||||
return(false)
|
|
||||||
end
|
end
|
@ -8,10 +8,8 @@ local vector_direction = vector.direction
|
|||||||
local integer_test = {-1,1}
|
local integer_test = {-1,1}
|
||||||
|
|
||||||
mobs.collision = function(self)
|
mobs.collision = function(self)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
|
|
||||||
if not self or not self.object or not self.object:get_luaentity() then
|
if not self or not self.object or not self.object:get_luaentity() then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -20,7 +18,7 @@ mobs.collision = function(self)
|
|||||||
local collisionbox = self.object:get_properties().collisionbox
|
local collisionbox = self.object:get_properties().collisionbox
|
||||||
|
|
||||||
pos.y = pos.y + collisionbox[2]
|
pos.y = pos.y + collisionbox[2]
|
||||||
|
|
||||||
local collision_boundary = collisionbox[4]
|
local collision_boundary = collisionbox[4]
|
||||||
|
|
||||||
local radius = collision_boundary
|
local radius = collision_boundary
|
||||||
@ -41,7 +39,7 @@ mobs.collision = function(self)
|
|||||||
for _,object in ipairs(minetest_get_objects_inside_radius(pos, radius*1.25)) do
|
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 and object:get_luaentity().health > 0)) and
|
if object and object ~= self.object and (object:is_player() or (object:get_luaentity() and object:get_luaentity()._cmi_is_mob == true and object:get_luaentity().health > 0)) and
|
||||||
--don't collide with rider, rider don't collide with thing
|
--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 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 self.object:get_attach() or (self.object:get_attach() and self.object:get_attach() ~= object)) then
|
||||||
--stop infinite loop
|
--stop infinite loop
|
||||||
collision_count = collision_count + 1
|
collision_count = collision_count + 1
|
||||||
@ -52,7 +50,7 @@ mobs.collision = function(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local pos2 = object:get_pos()
|
local pos2 = object:get_pos()
|
||||||
|
|
||||||
local object_collisionbox = object:get_properties().collisionbox
|
local object_collisionbox = object:get_properties().collisionbox
|
||||||
|
|
||||||
pos2.y = pos2.y + object_collisionbox[2]
|
pos2.y = pos2.y + object_collisionbox[2]
|
||||||
@ -74,7 +72,7 @@ mobs.collision = function(self)
|
|||||||
local dir = vector.direction(pos,pos2)
|
local dir = vector.direction(pos,pos2)
|
||||||
|
|
||||||
dir.y = 0
|
dir.y = 0
|
||||||
|
|
||||||
--eliminate mob being stuck in corners
|
--eliminate mob being stuck in corners
|
||||||
if dir.x == 0 and dir.z == 0 then
|
if dir.x == 0 and dir.z == 0 then
|
||||||
--slightly adjust mob position to prevent equal length
|
--slightly adjust mob position to prevent equal length
|
||||||
@ -84,7 +82,7 @@ mobs.collision = function(self)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local velocity = dir
|
local velocity = dir
|
||||||
|
|
||||||
--0.5 is the max force multiplier
|
--0.5 is the max force multiplier
|
||||||
local force = 0.5 - (0.5 * distance / (collision_boundary + object_collision_boundary))
|
local force = 0.5 - (0.5 * distance / (collision_boundary + object_collision_boundary))
|
||||||
|
|
||||||
@ -104,11 +102,9 @@ mobs.collision = function(self)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.object:add_velocity(vel1)
|
self.object:add_velocity(vel1)
|
||||||
object:add_velocity(vel2)
|
object:add_velocity(vel2)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -116,7 +112,6 @@ end
|
|||||||
|
|
||||||
--this is used for arrow collisions
|
--this is used for arrow collisions
|
||||||
mobs.arrow_hit = function(self, player)
|
mobs.arrow_hit = function(self, player)
|
||||||
|
|
||||||
player:punch(self.object, 1.0, {
|
player:punch(self.object, 1.0, {
|
||||||
full_punch_interval = 1.0,
|
full_punch_interval = 1.0,
|
||||||
damage_groups = {fleshy = self._damage}
|
damage_groups = {fleshy = self._damage}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
local minetest_add_item = minetest.add_item
|
local minetest_add_item = minetest.add_item
|
||||||
local minetest_sound_play = minetest.sound_play
|
--local minetest_sound_play = minetest.sound_play
|
||||||
|
|
||||||
local math_pi = math.pi
|
local math_pi = math.pi
|
||||||
local math_random = math.random
|
local math_random = math.random
|
||||||
@ -19,7 +19,7 @@ local item_drop = function(self, cooked, looting_level)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local obj, item, num
|
local obj, item
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
self.drops = self.drops or {} -- nil check
|
self.drops = self.drops or {} -- nil check
|
||||||
@ -56,8 +56,11 @@ local item_drop = function(self, cooked, looting_level)
|
|||||||
-- cook items when true
|
-- cook items when true
|
||||||
if cooked then
|
if cooked then
|
||||||
|
|
||||||
local output = minetest_get_craft_result({
|
local output = minetest.get_craft_result({
|
||||||
method = "cooking", width = 1, items = {item}})
|
method = "cooking",
|
||||||
|
width = 1,
|
||||||
|
items = {item},
|
||||||
|
})
|
||||||
|
|
||||||
if output and output.item and not output.item:is_empty() then
|
if output and output.item and not output.item:is_empty() then
|
||||||
item = output.item:get_name()
|
item = output.item:get_name()
|
||||||
@ -117,15 +120,10 @@ mobs.death_logic = function(self, dtime)
|
|||||||
|
|
||||||
--the final POOF of a mob despawning
|
--the final POOF of a mob despawning
|
||||||
if self.death_animation_timer >= 1.25 then
|
if self.death_animation_timer >= 1.25 then
|
||||||
|
|
||||||
item_drop(self,false,1)
|
item_drop(self,false,1)
|
||||||
|
|
||||||
mobs.death_effect(self)
|
mobs.death_effect(self)
|
||||||
|
|
||||||
mcl_experience.throw_experience(self.object:get_pos(), math_random(self.xp_min, self.xp_max))
|
mcl_experience.throw_experience(self.object:get_pos(), math_random(self.xp_min, self.xp_max))
|
||||||
|
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
local minetest_line_of_sight = minetest.line_of_sight
|
local minetest_line_of_sight = minetest.line_of_sight
|
||||||
local minetest_dir_to_yaw = minetest.dir_to_yaw
|
--local minetest_dir_to_yaw = minetest.dir_to_yaw
|
||||||
local minetest_yaw_to_dir = minetest.yaw_to_dir
|
local minetest_yaw_to_dir = minetest.yaw_to_dir
|
||||||
local minetest_get_node = minetest.get_node
|
local minetest_get_node = minetest.get_node
|
||||||
local minetest_get_item_group = minetest.get_item_group
|
local minetest_get_item_group = minetest.get_item_group
|
||||||
@ -18,19 +18,16 @@ local table_copy = table.copy
|
|||||||
local math_abs = math.abs
|
local math_abs = math.abs
|
||||||
|
|
||||||
-- default function when mobs are blown up with TNT
|
-- default function when mobs are blown up with TNT
|
||||||
local do_tnt = function(obj, damage)
|
--[[local function do_tnt(obj, damage)
|
||||||
|
|
||||||
obj.object:punch(obj.object, 1.0, {
|
obj.object:punch(obj.object, 1.0, {
|
||||||
full_punch_interval = 1.0,
|
full_punch_interval = 1.0,
|
||||||
damage_groups = {fleshy = damage},
|
damage_groups = {fleshy = damage},
|
||||||
}, nil)
|
}, nil)
|
||||||
|
|
||||||
return false, true, {}
|
return false, true, {}
|
||||||
end
|
end]]
|
||||||
|
|
||||||
--a fast function to be able to detect only players without using objects_in_radius
|
--a fast function to be able to detect only players without using objects_in_radius
|
||||||
mobs.detect_closest_player_within_radius = function(self, line_of_sight, radius, object_height_adder)
|
mobs.detect_closest_player_within_radius = function(self, line_of_sight, radius, object_height_adder)
|
||||||
|
|
||||||
local pos1 = self.object:get_pos()
|
local pos1 = self.object:get_pos()
|
||||||
local players_in_area = {}
|
local players_in_area = {}
|
||||||
local winner_player = nil
|
local winner_player = nil
|
||||||
@ -49,7 +46,7 @@ mobs.detect_closest_player_within_radius = function(self, line_of_sight, radius,
|
|||||||
--must add eye height or stuff breaks randomly because of
|
--must add eye height or stuff breaks randomly because of
|
||||||
--seethrough nodes being a blocker (like grass)
|
--seethrough nodes being a blocker (like grass)
|
||||||
if minetest_line_of_sight(
|
if minetest_line_of_sight(
|
||||||
vector_new(pos1.x, pos1.y + object_height_adder, pos1.z),
|
vector_new(pos1.x, pos1.y + object_height_adder, pos1.z),
|
||||||
vector_new(pos2.x, pos2.y + player:get_properties().eye_height, pos2.z)
|
vector_new(pos2.x, pos2.y + player:get_properties().eye_height, pos2.z)
|
||||||
) then
|
) then
|
||||||
players_detected = players_detected + 1
|
players_detected = players_detected + 1
|
||||||
@ -108,7 +105,7 @@ mobs.jump_check = function(self,dtime)
|
|||||||
if green_flag_1 and green_flag_2 then
|
if green_flag_1 and green_flag_2 then
|
||||||
--can jump over node
|
--can jump over node
|
||||||
return(1)
|
return(1)
|
||||||
elseif green_flag_1 and not green_flag_2 then
|
elseif green_flag_1 and not green_flag_2 then
|
||||||
--wall in front of mob
|
--wall in front of mob
|
||||||
return(2)
|
return(2)
|
||||||
end
|
end
|
||||||
@ -180,15 +177,10 @@ end
|
|||||||
-- check if within physical map limits (-30911 to 30927)
|
-- check if within physical map limits (-30911 to 30927)
|
||||||
-- within_limits, wmin, wmax = nil, -30913, 30928
|
-- within_limits, wmin, wmax = nil, -30913, 30928
|
||||||
mobs.within_limits = function(pos, radius)
|
mobs.within_limits = function(pos, radius)
|
||||||
|
local wmin, wmax
|
||||||
if mcl_vars then
|
if mcl_vars then
|
||||||
if mcl_vars.mapgen_edge_min and mcl_vars.mapgen_edge_max then
|
if mcl_vars.mapgen_edge_min and mcl_vars.mapgen_edge_max then
|
||||||
wmin, wmax = mcl_vars.mapgen_edge_min, mcl_vars.mapgen_edge_max
|
wmin, wmax = mcl_vars.mapgen_edge_min, mcl_vars.mapgen_edge_max
|
||||||
within_limits = function(pos, radius)
|
|
||||||
return pos
|
|
||||||
and (pos.x - radius) > wmin and (pos.x + radius) < wmax
|
|
||||||
and (pos.y - radius) > wmin and (pos.y + radius) < wmax
|
|
||||||
and (pos.z - radius) > wmin and (pos.z + radius) < wmax
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return pos
|
return pos
|
||||||
|
@ -1,112 +1,98 @@
|
|||||||
local vector_new = vector.new
|
local math = math
|
||||||
|
local vector = vector
|
||||||
|
|
||||||
--converts yaw to degrees
|
--converts yaw to degrees
|
||||||
local degrees = function(yaw)
|
local degrees = function(yaw)
|
||||||
return(yaw*180.0/math.pi)
|
return(yaw*180.0/math.pi)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
mobs.do_head_logic = function(self,dtime)
|
mobs.do_head_logic = function(self,dtime)
|
||||||
|
|
||||||
local player = minetest.get_player_by_name("singleplayer")
|
local player = minetest.get_player_by_name("singleplayer")
|
||||||
|
|
||||||
local look_at = player:get_pos()
|
local look_at = player:get_pos()
|
||||||
look_at.y = look_at.y + player:get_properties().eye_height
|
look_at.y = look_at.y + player:get_properties().eye_height
|
||||||
|
|
||||||
|
local pos = self.object:get_pos()
|
||||||
|
|
||||||
|
local body_yaw = self.object:get_yaw()
|
||||||
|
|
||||||
|
local body_dir = minetest.yaw_to_dir(body_yaw)
|
||||||
|
|
||||||
|
pos.y = pos.y + self.head_height_offset
|
||||||
|
|
||||||
|
local head_offset = vector.multiply(body_dir, self.head_direction_offset)
|
||||||
|
|
||||||
|
pos = vector.add(pos, head_offset)
|
||||||
|
|
||||||
|
minetest.add_particle({
|
||||||
|
pos = pos,
|
||||||
|
velocity = {x=0, y=0, z=0},
|
||||||
|
acceleration = {x=0, y=0, z=0},
|
||||||
|
expirationtime = 0.2,
|
||||||
|
size = 1,
|
||||||
|
texture = "default_dirt.png",
|
||||||
|
})
|
||||||
|
|
||||||
|
local bone_pos = vector.new(0,0,0)
|
||||||
|
|
||||||
|
--(horizontal)
|
||||||
|
bone_pos.y = self.head_bone_pos_y
|
||||||
|
|
||||||
|
--(vertical)
|
||||||
|
bone_pos.z = self.head_bone_pos_z
|
||||||
|
|
||||||
|
--print(yaw)
|
||||||
|
|
||||||
|
--local _, bone_rot = self.object:get_bone_position("head")
|
||||||
|
|
||||||
|
--bone_rot.x = bone_rot.x + (dtime * 10)
|
||||||
|
--bone_rot.z = bone_rot.z + (dtime * 10)
|
||||||
|
|
||||||
|
local head_yaw = minetest.dir_to_yaw(vector.direction(pos,look_at)) - body_yaw
|
||||||
|
|
||||||
|
if self.reverse_head_yaw then
|
||||||
|
head_yaw = head_yaw * -1
|
||||||
|
end
|
||||||
|
|
||||||
|
--over rotation protection
|
||||||
|
--stops radians from going out of spec
|
||||||
|
if head_yaw > math.pi then
|
||||||
|
head_yaw = head_yaw - (math.pi * 2)
|
||||||
|
elseif head_yaw < -math.pi then
|
||||||
|
head_yaw = head_yaw + (math.pi * 2)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local check_failed = false
|
||||||
|
--upper check + 90 degrees or upper math.radians (3.14/2)
|
||||||
|
if head_yaw > math.pi - (math.pi/2) then
|
||||||
|
head_yaw = 0
|
||||||
|
check_failed = true
|
||||||
|
--lower check - 90 degrees or lower negative math.radians (-3.14/2)
|
||||||
|
elseif head_yaw < -math.pi + (math.pi/2) then
|
||||||
|
head_yaw = 0
|
||||||
|
check_failed = true
|
||||||
|
end
|
||||||
|
|
||||||
|
local head_pitch = 0
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
--DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG
|
||||||
|
--head_yaw = 0
|
||||||
|
--DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG
|
||||||
|
|
||||||
local body_yaw = self.object:get_yaw()
|
if not check_failed then
|
||||||
|
head_pitch = minetest.dir_to_yaw(vector.new(vector.distance(vector.new(pos.x,0,pos.z),vector.new(look_at.x,0,look_at.z)),0,pos.y-look_at.y))+(math.pi/2)
|
||||||
|
end
|
||||||
|
|
||||||
local body_dir = minetest.yaw_to_dir(body_yaw)
|
if self.head_pitch_modifier then
|
||||||
|
head_pitch = head_pitch + self.head_pitch_modifier
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.swap_y_with_x then
|
||||||
pos.y = pos.y + self.head_height_offset
|
self.object:set_bone_position(self.head_bone, bone_pos, vector.new(degrees(head_pitch),degrees(head_yaw),0))
|
||||||
|
else
|
||||||
local head_offset = vector.multiply(body_dir, self.head_direction_offset)
|
self.object:set_bone_position(self.head_bone, bone_pos, vector.new(degrees(head_pitch),0,degrees(head_yaw)))
|
||||||
|
end
|
||||||
pos = vector.add(pos, head_offset)
|
--set_bone_position([bone, position, rotation])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
minetest.add_particle({
|
|
||||||
pos = pos,
|
|
||||||
velocity = {x=0, y=0, z=0},
|
|
||||||
acceleration = {x=0, y=0, z=0},
|
|
||||||
expirationtime = 0.2,
|
|
||||||
size = 1,
|
|
||||||
texture = "default_dirt.png",
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
||||||
local bone_pos = vector_new(0,0,0)
|
|
||||||
|
|
||||||
|
|
||||||
--(horizontal)
|
|
||||||
bone_pos.y = self.head_bone_pos_y
|
|
||||||
|
|
||||||
--(vertical)
|
|
||||||
bone_pos.z = self.head_bone_pos_z
|
|
||||||
|
|
||||||
--print(yaw)
|
|
||||||
|
|
||||||
--local _, bone_rot = self.object:get_bone_position("head")
|
|
||||||
|
|
||||||
--bone_rot.x = bone_rot.x + (dtime * 10)
|
|
||||||
--bone_rot.z = bone_rot.z + (dtime * 10)
|
|
||||||
|
|
||||||
|
|
||||||
local head_yaw
|
|
||||||
head_yaw = minetest.dir_to_yaw(vector.direction(pos,look_at)) - body_yaw
|
|
||||||
|
|
||||||
if self.reverse_head_yaw then
|
|
||||||
head_yaw = head_yaw * -1
|
|
||||||
end
|
|
||||||
|
|
||||||
--over rotation protection
|
|
||||||
--stops radians from going out of spec
|
|
||||||
if head_yaw > math.pi then
|
|
||||||
head_yaw = head_yaw - (math.pi * 2)
|
|
||||||
elseif head_yaw < -math.pi then
|
|
||||||
head_yaw = head_yaw + (math.pi * 2)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local check_failed = false
|
|
||||||
--upper check + 90 degrees or upper math.radians (3.14/2)
|
|
||||||
if head_yaw > math.pi - (math.pi/2) then
|
|
||||||
head_yaw = 0
|
|
||||||
check_failed = true
|
|
||||||
--lower check - 90 degrees or lower negative math.radians (-3.14/2)
|
|
||||||
elseif head_yaw < -math.pi + (math.pi/2) then
|
|
||||||
head_yaw = 0
|
|
||||||
check_failed = true
|
|
||||||
end
|
|
||||||
|
|
||||||
local head_pitch = 0
|
|
||||||
|
|
||||||
--DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG
|
|
||||||
--head_yaw = 0
|
|
||||||
--DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG DEBUG
|
|
||||||
|
|
||||||
if not check_failed then
|
|
||||||
head_pitch = minetest.dir_to_yaw(vector.new(vector.distance(vector.new(pos.x,0,pos.z),vector.new(look_at.x,0,look_at.z)),0,pos.y-look_at.y))+(math.pi/2)
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.head_pitch_modifier then
|
|
||||||
head_pitch = head_pitch + self.head_pitch_modifier
|
|
||||||
end
|
|
||||||
|
|
||||||
if self.swap_y_with_x then
|
|
||||||
self.object:set_bone_position(self.head_bone, bone_pos, vector_new(degrees(head_pitch),degrees(head_yaw),0))
|
|
||||||
else
|
|
||||||
self.object:set_bone_position(self.head_bone, bone_pos, vector_new(degrees(head_pitch),0,degrees(head_yaw)))
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--set_bone_position([bone, position, rotation])
|
|
||||||
end
|
end
|
@ -2,22 +2,19 @@ local minetest_after = minetest.after
|
|||||||
local minetest_sound_play = minetest.sound_play
|
local minetest_sound_play = minetest.sound_play
|
||||||
local minetest_dir_to_yaw = minetest.dir_to_yaw
|
local minetest_dir_to_yaw = minetest.dir_to_yaw
|
||||||
|
|
||||||
local math_floor = math.floor
|
local math = math
|
||||||
local math_min = math.min
|
local vector = vector
|
||||||
local math_random = math.random
|
|
||||||
|
|
||||||
local vector_direction = vector.direction
|
|
||||||
local vector_multiply = vector.multiply
|
|
||||||
|
|
||||||
local MAX_MOB_NAME_LENGTH = 30
|
local MAX_MOB_NAME_LENGTH = 30
|
||||||
|
|
||||||
|
local mod_hunger = minetest.get_modpath("mcl_hunger")
|
||||||
|
|
||||||
mobs.feed_tame = function(self)
|
mobs.feed_tame = function(self)
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Code to execute before custom on_rightclick handling
|
-- Code to execute before custom on_rightclick handling
|
||||||
local on_rightclick_prefix = function(self, clicker)
|
local function on_rightclick_prefix(self, clicker)
|
||||||
|
|
||||||
local item = clicker:get_wielded_item()
|
local item = clicker:get_wielded_item()
|
||||||
|
|
||||||
-- Name mob with nametag
|
-- Name mob with nametag
|
||||||
@ -60,7 +57,6 @@ end
|
|||||||
|
|
||||||
-- deal damage and effects when mob punched
|
-- deal damage and effects when mob punched
|
||||||
mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
||||||
|
|
||||||
--don't do anything if the mob is already dead
|
--don't do anything if the mob is already dead
|
||||||
if self.health <= 0 then
|
if self.health <= 0 then
|
||||||
return
|
return
|
||||||
@ -94,14 +90,13 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
pos2.y = 0
|
pos2.y = 0
|
||||||
|
|
||||||
|
|
||||||
local dir = vector_direction(pos2,pos1)
|
local dir = vector.direction(pos2,pos1)
|
||||||
|
|
||||||
local yaw = minetest_dir_to_yaw(dir)
|
local yaw = minetest_dir_to_yaw(dir)
|
||||||
|
|
||||||
self.yaw = yaw
|
self.yaw = yaw
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- custom punch function
|
-- custom punch function
|
||||||
if self.do_punch then
|
if self.do_punch then
|
||||||
-- when false skip going any further
|
-- when false skip going any further
|
||||||
@ -113,23 +108,20 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
--don't do damage until pause timer resets
|
--don't do damage until pause timer resets
|
||||||
if self.pause_timer > 0 then
|
if self.pause_timer > 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- error checking when mod profiling is enabled
|
-- error checking when mod profiling is enabled
|
||||||
if not tool_capabilities then
|
if not tool_capabilities then
|
||||||
minetest.log("warning", "[mobs_mc] Mod profiling enabled, damage not enabled")
|
minetest.log("warning", "[mobs_mc] Mod profiling enabled, damage not enabled")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local is_player = hitter:is_player()
|
local is_player = hitter:is_player()
|
||||||
|
|
||||||
|
|
||||||
-- punch interval
|
-- punch interval
|
||||||
local weapon = hitter:get_wielded_item()
|
local weapon = hitter:get_wielded_item()
|
||||||
|
|
||||||
local punch_interval = 1.4
|
--local punch_interval = 1.4
|
||||||
|
|
||||||
-- exhaust attacker
|
-- exhaust attacker
|
||||||
if mod_hunger and is_player then
|
if mod_hunger and is_player then
|
||||||
@ -139,7 +131,6 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
-- calculate mob damage
|
-- calculate mob damage
|
||||||
local damage = 0
|
local damage = 0
|
||||||
local armor = self.object:get_armor_groups() or {}
|
local armor = self.object:get_armor_groups() or {}
|
||||||
local tmp
|
|
||||||
|
|
||||||
--calculate damage groups
|
--calculate damage groups
|
||||||
for group,_ in pairs( (tool_capabilities.damage_groups or {}) ) do
|
for group,_ in pairs( (tool_capabilities.damage_groups or {}) ) do
|
||||||
@ -163,13 +154,13 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
|
|
||||||
-- healing
|
-- healing
|
||||||
if damage <= -1 then
|
if damage <= -1 then
|
||||||
self.health = self.health - math_floor(damage)
|
self.health = self.health - math.floor(damage)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if tool_capabilities then
|
--if tool_capabilities then
|
||||||
punch_interval = tool_capabilities.full_punch_interval or 1.4
|
-- punch_interval = tool_capabilities.full_punch_interval or 1.4
|
||||||
end
|
--end
|
||||||
|
|
||||||
-- add weapon wear manually
|
-- add weapon wear manually
|
||||||
-- Required because we have custom health handling ("health" property)
|
-- Required because we have custom health handling ("health" property)
|
||||||
@ -183,7 +174,7 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
local weapon = hitter:get_wielded_item(player)
|
local weapon = hitter:get_wielded_item(player)
|
||||||
local def = weapon:get_definition()
|
local def = weapon:get_definition()
|
||||||
if def.tool_capabilities and def.tool_capabilities.punch_attack_uses then
|
if def.tool_capabilities and def.tool_capabilities.punch_attack_uses then
|
||||||
local wear = math_floor(65535/tool_capabilities.punch_attack_uses)
|
local wear = math.floor(65535/tool_capabilities.punch_attack_uses)
|
||||||
weapon:add_wear(wear)
|
weapon:add_wear(wear)
|
||||||
hitter:set_wielded_item(weapon)
|
hitter:set_wielded_item(weapon)
|
||||||
end
|
end
|
||||||
@ -224,7 +215,7 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
|
|
||||||
-- knock back effect
|
-- knock back effect
|
||||||
local velocity = self.object:get_velocity()
|
local velocity = self.object:get_velocity()
|
||||||
|
|
||||||
--2d direction
|
--2d direction
|
||||||
local pos1 = self.object:get_pos()
|
local pos1 = self.object:get_pos()
|
||||||
pos1.y = 0
|
pos1.y = 0
|
||||||
@ -240,9 +231,8 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
up = 0
|
up = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
--0.75 for perfect distance to not be too easy, and not be too hard
|
--0.75 for perfect distance to not be too easy, and not be too hard
|
||||||
local multiplier = 0.75
|
local multiplier = 0.75
|
||||||
|
|
||||||
-- check if tool already has specific knockback value
|
-- check if tool already has specific knockback value
|
||||||
local knockback_enchant = mcl_enchanting.get_enchantment(hitter:get_wielded_item(), "knockback")
|
local knockback_enchant = mcl_enchanting.get_enchantment(hitter:get_wielded_item(), "knockback")
|
||||||
@ -254,21 +244,16 @@ mobs.mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
|
|||||||
--it's coming for you
|
--it's coming for you
|
||||||
if self.hostile then
|
if self.hostile then
|
||||||
multiplier = multiplier + 2
|
multiplier = multiplier + 2
|
||||||
end
|
end
|
||||||
|
dir = vector.multiply(dir,multiplier)
|
||||||
dir = vector_multiply(dir,multiplier)
|
|
||||||
|
|
||||||
dir.y = up
|
dir.y = up
|
||||||
|
|
||||||
--add the velocity
|
--add the velocity
|
||||||
self.object:add_velocity(dir)
|
self.object:add_velocity(dir)
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--do internal per mob projectile calculations
|
--do internal per mob projectile calculations
|
||||||
mobs.shoot_projectile = function(self)
|
mobs.shoot_projectile = function(self)
|
||||||
|
|
||||||
local pos1 = self.object:get_pos()
|
local pos1 = self.object:get_pos()
|
||||||
--add mob eye height
|
--add mob eye height
|
||||||
pos1.y = pos1.y + self.eye_height
|
pos1.y = pos1.y + self.eye_height
|
||||||
@ -278,7 +263,7 @@ mobs.shoot_projectile = function(self)
|
|||||||
pos2.y = pos2.y + self.attacking:get_properties().eye_height
|
pos2.y = pos2.y + self.attacking:get_properties().eye_height
|
||||||
|
|
||||||
--get direction
|
--get direction
|
||||||
local dir = vector_direction(pos1,pos2)
|
local dir = vector.direction(pos1,pos2)
|
||||||
|
|
||||||
--call internal shoot_arrow function
|
--call internal shoot_arrow function
|
||||||
self.shoot_arrow(self,pos1,dir)
|
self.shoot_arrow(self,pos1,dir)
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
local minetest_add_particlespawner = minetest.add_particlespawner
|
local minetest_add_particlespawner = minetest.add_particlespawner
|
||||||
|
|
||||||
mobs.death_effect = function(self)
|
mobs.death_effect = function(self)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local yaw = self.object:get_yaw()
|
--local yaw = self.object:get_yaw()
|
||||||
local collisionbox = self.object:get_properties().collisionbox
|
local collisionbox = self.object:get_properties().collisionbox
|
||||||
|
|
||||||
local min, max
|
local min, max
|
||||||
@ -33,7 +32,7 @@ end
|
|||||||
mobs.critical_effect = function(self)
|
mobs.critical_effect = function(self)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local yaw = self.object:get_yaw()
|
--local yaw = self.object:get_yaw()
|
||||||
local collisionbox = self.object:get_properties().collisionbox
|
local collisionbox = self.object:get_properties().collisionbox
|
||||||
|
|
||||||
local min, max
|
local min, max
|
||||||
@ -62,9 +61,8 @@ end
|
|||||||
|
|
||||||
--when feeding a mob
|
--when feeding a mob
|
||||||
mobs.feed_effect = function(self)
|
mobs.feed_effect = function(self)
|
||||||
|
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local yaw = self.object:get_yaw()
|
--local yaw = self.object:get_yaw()
|
||||||
local collisionbox = self.object:get_properties().collisionbox
|
local collisionbox = self.object:get_properties().collisionbox
|
||||||
|
|
||||||
local min, max
|
local min, max
|
||||||
@ -94,7 +92,7 @@ end
|
|||||||
--hearts when tamed
|
--hearts when tamed
|
||||||
mobs.tamed_effect = function(self)
|
mobs.tamed_effect = function(self)
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local yaw = self.object:get_yaw()
|
--local yaw = self.object:get_yaw()
|
||||||
local collisionbox = self.object:get_properties().collisionbox
|
local collisionbox = self.object:get_properties().collisionbox
|
||||||
|
|
||||||
local min, max
|
local min, max
|
||||||
@ -124,7 +122,7 @@ end
|
|||||||
--hearts when breeding
|
--hearts when breeding
|
||||||
mobs.breeding_effect = function(self)
|
mobs.breeding_effect = function(self)
|
||||||
local pos = self.object:get_pos()
|
local pos = self.object:get_pos()
|
||||||
local yaw = self.object:get_yaw()
|
--local yaw = self.object:get_yaw()
|
||||||
local collisionbox = self.object:get_properties().collisionbox
|
local collisionbox = self.object:get_properties().collisionbox
|
||||||
|
|
||||||
local min, max
|
local min, max
|
||||||
|
@ -1,16 +1,10 @@
|
|||||||
local math_pi = math.pi
|
-- localize math functions
|
||||||
local math_sin = math.sin
|
local math = math
|
||||||
local math_cos = math.cos
|
local HALF_PI = math.pi / 2
|
||||||
local math_random = math.random
|
local DOUBLE_PI = math.pi * 2
|
||||||
local HALF_PI = math_pi / 2
|
|
||||||
local DOUBLE_PI = math_pi * 2
|
|
||||||
|
|
||||||
-- localize vector functions
|
-- localize vector functions
|
||||||
local vector_new = vector.new
|
local vector = vector
|
||||||
local vector_length = vector.length
|
|
||||||
local vector_multiply = vector.multiply
|
|
||||||
local vector_distance = vector.distance
|
|
||||||
local vector_normalize = vector.normalize
|
|
||||||
|
|
||||||
local minetest_yaw_to_dir = minetest.yaw_to_dir
|
local minetest_yaw_to_dir = minetest.yaw_to_dir
|
||||||
local minetest_dir_to_yaw = minetest.dir_to_yaw
|
local minetest_dir_to_yaw = minetest.dir_to_yaw
|
||||||
@ -19,18 +13,17 @@ local DEFAULT_JUMP_HEIGHT = 5
|
|||||||
local DEFAULT_FLOAT_SPEED = 4
|
local DEFAULT_FLOAT_SPEED = 4
|
||||||
local DEFAULT_CLIMB_SPEED = 3
|
local DEFAULT_CLIMB_SPEED = 3
|
||||||
|
|
||||||
|
|
||||||
mobs.stick_in_cobweb = function(self)
|
mobs.stick_in_cobweb = function(self)
|
||||||
local current_velocity = self.object:get_velocity()
|
local current_velocity = self.object:get_velocity()
|
||||||
|
|
||||||
local goal_velocity = vector_multiply(vector_normalize(current_velocity), 0.4)
|
local goal_velocity = vector.multiply(vector.normalize(current_velocity), 0.4)
|
||||||
|
|
||||||
goal_velocity.y = -0.5
|
goal_velocity.y = -0.5
|
||||||
|
|
||||||
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
||||||
|
|
||||||
--smooths out mobs a bit
|
--smooths out mobs a bit
|
||||||
if vector_length(new_velocity_addition) >= 0.0001 then
|
if vector.length(new_velocity_addition) >= 0.0001 then
|
||||||
self.object:add_velocity(new_velocity_addition)
|
self.object:add_velocity(new_velocity_addition)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -40,7 +33,7 @@ mobs.float = function(self)
|
|||||||
|
|
||||||
local acceleration = self.object:get_acceleration()
|
local acceleration = self.object:get_acceleration()
|
||||||
if acceleration and acceleration.y ~= 0 then
|
if acceleration and acceleration.y ~= 0 then
|
||||||
self.object:set_acceleration(vector_new(0,0,0))
|
self.object:set_acceleration(vector.new(0,0,0))
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -59,7 +52,7 @@ mobs.float = function(self)
|
|||||||
new_velocity_addition.z = 0
|
new_velocity_addition.z = 0
|
||||||
|
|
||||||
--smooths out mobs a bit
|
--smooths out mobs a bit
|
||||||
if vector_length(new_velocity_addition) >= 0.0001 then
|
if vector.length(new_velocity_addition) >= 0.0001 then
|
||||||
self.object:add_velocity(new_velocity_addition)
|
self.object:add_velocity(new_velocity_addition)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -81,7 +74,7 @@ mobs.climb = function(self)
|
|||||||
new_velocity_addition.z = 0
|
new_velocity_addition.z = 0
|
||||||
|
|
||||||
--smooths out mobs a bit
|
--smooths out mobs a bit
|
||||||
if vector_length(new_velocity_addition) >= 0.0001 then
|
if vector.length(new_velocity_addition) >= 0.0001 then
|
||||||
self.object:add_velocity(new_velocity_addition)
|
self.object:add_velocity(new_velocity_addition)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -109,22 +102,22 @@ mobs.set_velocity = function(self, v)
|
|||||||
local current_velocity = self.object:get_velocity()
|
local current_velocity = self.object:get_velocity()
|
||||||
|
|
||||||
local goal_velocity = {
|
local goal_velocity = {
|
||||||
x = (math_sin(yaw) * -v),
|
x = (math.sin(yaw) * -v),
|
||||||
y = 0,
|
y = 0,
|
||||||
z = (math_cos(yaw) * v),
|
z = (math.cos(yaw) * v),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
||||||
|
|
||||||
if vector_length(new_velocity_addition) > vector_length(goal_velocity) then
|
if vector.length(new_velocity_addition) > vector.length(goal_velocity) then
|
||||||
vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition)))
|
vector.multiply(new_velocity_addition, (vector.length(goal_velocity) / vector.length(new_velocity_addition)))
|
||||||
end
|
end
|
||||||
|
|
||||||
new_velocity_addition.y = 0
|
new_velocity_addition.y = 0
|
||||||
|
|
||||||
--smooths out mobs a bit
|
--smooths out mobs a bit
|
||||||
if vector_length(new_velocity_addition) >= 0.0001 then
|
if vector.length(new_velocity_addition) >= 0.0001 then
|
||||||
self.object:add_velocity(new_velocity_addition)
|
self.object:add_velocity(new_velocity_addition)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -139,7 +132,7 @@ mobs.get_velocity = function(self)
|
|||||||
v.y = 0
|
v.y = 0
|
||||||
|
|
||||||
if v then
|
if v then
|
||||||
return vector_length(v)
|
return vector.length(v)
|
||||||
end
|
end
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
@ -155,7 +148,7 @@ mobs.jump = function(self, velocity)
|
|||||||
--fallback velocity to allow modularity
|
--fallback velocity to allow modularity
|
||||||
velocity = velocity or DEFAULT_JUMP_HEIGHT
|
velocity = velocity or DEFAULT_JUMP_HEIGHT
|
||||||
|
|
||||||
self.object:add_velocity(vector_new(0,velocity,0))
|
self.object:add_velocity(vector.new(0,velocity,0))
|
||||||
end
|
end
|
||||||
|
|
||||||
--make mobs fall slowly
|
--make mobs fall slowly
|
||||||
@ -175,15 +168,15 @@ mobs.mob_fall_slow = function(self)
|
|||||||
new_velocity_addition.x = 0
|
new_velocity_addition.x = 0
|
||||||
new_velocity_addition.z = 0
|
new_velocity_addition.z = 0
|
||||||
|
|
||||||
if vector_length(new_velocity_addition) > vector_length(goal_velocity) then
|
if vector.length(new_velocity_addition) > vector.length(goal_velocity) then
|
||||||
vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition)))
|
vector.multiply(new_velocity_addition, (vector.length(goal_velocity) / vector.length(new_velocity_addition)))
|
||||||
end
|
end
|
||||||
|
|
||||||
new_velocity_addition.x = 0
|
new_velocity_addition.x = 0
|
||||||
new_velocity_addition.z = 0
|
new_velocity_addition.z = 0
|
||||||
|
|
||||||
--smooths out mobs a bit
|
--smooths out mobs a bit
|
||||||
if vector_length(new_velocity_addition) >= 0.0001 then
|
if vector.length(new_velocity_addition) >= 0.0001 then
|
||||||
self.object:add_velocity(new_velocity_addition)
|
self.object:add_velocity(new_velocity_addition)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -215,13 +208,13 @@ mobs.flop = function(self, velocity)
|
|||||||
velocity = velocity or DEFAULT_JUMP_HEIGHT
|
velocity = velocity or DEFAULT_JUMP_HEIGHT
|
||||||
|
|
||||||
--create a random direction (2d yaw)
|
--create a random direction (2d yaw)
|
||||||
local dir = DOUBLE_PI * math_random()
|
local dir = DOUBLE_PI * math.random()
|
||||||
|
|
||||||
--create a random force value
|
--create a random force value
|
||||||
local force = math_random(0,3) + math_random()
|
local force = math.random(0,3) + math.random()
|
||||||
|
|
||||||
--convert the yaw to a direction vector then multiply it times the force
|
--convert the yaw to a direction vector then multiply it times the force
|
||||||
local final_additional_force = vector_multiply(minetest_yaw_to_dir(dir), force)
|
local final_additional_force = vector.multiply(minetest_yaw_to_dir(dir), force)
|
||||||
|
|
||||||
--place in the "flop" velocity to make the mob flop
|
--place in the "flop" velocity to make the mob flop
|
||||||
final_additional_force.y = velocity
|
final_additional_force.y = velocity
|
||||||
@ -249,20 +242,20 @@ mobs.set_swim_velocity = function(self, v)
|
|||||||
local current_velocity = self.object:get_velocity()
|
local current_velocity = self.object:get_velocity()
|
||||||
|
|
||||||
local goal_velocity = {
|
local goal_velocity = {
|
||||||
x = (math_sin(yaw) * -v),
|
x = (math.sin(yaw) * -v),
|
||||||
y = pitch,
|
y = pitch,
|
||||||
z = (math_cos(yaw) * v),
|
z = (math.cos(yaw) * v),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
||||||
|
|
||||||
if vector_length(new_velocity_addition) > vector_length(goal_velocity) then
|
if vector.length(new_velocity_addition) > vector.length(goal_velocity) then
|
||||||
vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition)))
|
vector.multiply(new_velocity_addition, (vector.length(goal_velocity) / vector.length(new_velocity_addition)))
|
||||||
end
|
end
|
||||||
|
|
||||||
--smooths out mobs a bit
|
--smooths out mobs a bit
|
||||||
if vector_length(new_velocity_addition) >= 0.0001 then
|
if vector.length(new_velocity_addition) >= 0.0001 then
|
||||||
self.object:add_velocity(new_velocity_addition)
|
self.object:add_velocity(new_velocity_addition)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -294,20 +287,20 @@ mobs.set_fly_velocity = function(self, v)
|
|||||||
local current_velocity = self.object:get_velocity()
|
local current_velocity = self.object:get_velocity()
|
||||||
|
|
||||||
local goal_velocity = {
|
local goal_velocity = {
|
||||||
x = (math_sin(yaw) * -v),
|
x = (math.sin(yaw) * -v),
|
||||||
y = pitch,
|
y = pitch,
|
||||||
z = (math_cos(yaw) * v),
|
z = (math.cos(yaw) * v),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
||||||
|
|
||||||
if vector_length(new_velocity_addition) > vector_length(goal_velocity) then
|
if vector.length(new_velocity_addition) > vector.length(goal_velocity) then
|
||||||
vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition)))
|
vector.multiply(new_velocity_addition, (vector.length(goal_velocity) / vector.length(new_velocity_addition)))
|
||||||
end
|
end
|
||||||
|
|
||||||
--smooths out mobs a bit
|
--smooths out mobs a bit
|
||||||
if vector_length(new_velocity_addition) >= 0.0001 then
|
if vector.length(new_velocity_addition) >= 0.0001 then
|
||||||
self.object:add_velocity(new_velocity_addition)
|
self.object:add_velocity(new_velocity_addition)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -319,7 +312,7 @@ mobs.calculate_pitch = function(pos1, pos2)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
return(minetest_dir_to_yaw(vector_new(vector_distance(vector_new(pos1.x,0,pos1.z),vector_new(pos2.x,0,pos2.z)),0,pos1.y - pos2.y)) + HALF_PI)
|
return(minetest_dir_to_yaw(vector.new(vector.distance(vector.new(pos1.x,0,pos1.z),vector.new(pos2.x,0,pos2.z)),0,pos1.y - pos2.y)) + HALF_PI)
|
||||||
end
|
end
|
||||||
|
|
||||||
--make mobs fly up or down based on their y difference
|
--make mobs fly up or down based on their y difference
|
||||||
@ -356,27 +349,27 @@ mobs.jump_move = function(self, velocity)
|
|||||||
mobs.set_velocity(self,0)
|
mobs.set_velocity(self,0)
|
||||||
|
|
||||||
--fallback velocity to allow modularity
|
--fallback velocity to allow modularity
|
||||||
jump_height = DEFAULT_JUMP_HEIGHT
|
local jump_height = DEFAULT_JUMP_HEIGHT
|
||||||
|
|
||||||
local yaw = (self.yaw or 0)
|
local yaw = (self.yaw or 0)
|
||||||
|
|
||||||
local current_velocity = self.object:get_velocity()
|
local current_velocity = self.object:get_velocity()
|
||||||
|
|
||||||
local goal_velocity = {
|
local goal_velocity = {
|
||||||
x = (math_sin(yaw) * -velocity),
|
x = (math.sin(yaw) * -velocity),
|
||||||
y = jump_height,
|
y = jump_height,
|
||||||
z = (math_cos(yaw) * velocity),
|
z = (math.cos(yaw) * velocity),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
local new_velocity_addition = vector.subtract(goal_velocity,current_velocity)
|
||||||
|
|
||||||
if vector_length(new_velocity_addition) > vector_length(goal_velocity) then
|
if vector.length(new_velocity_addition) > vector.length(goal_velocity) then
|
||||||
vector.multiply(new_velocity_addition, (vector_length(goal_velocity) / vector_length(new_velocity_addition)))
|
vector.multiply(new_velocity_addition, (vector.length(goal_velocity) / vector.length(new_velocity_addition)))
|
||||||
end
|
end
|
||||||
|
|
||||||
--smooths out mobs a bit
|
--smooths out mobs a bit
|
||||||
if vector_length(new_velocity_addition) >= 0.0001 then
|
if vector.length(new_velocity_addition) >= 0.0001 then
|
||||||
self.object:add_velocity(new_velocity_addition)
|
self.object:add_velocity(new_velocity_addition)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
local math_random = math.random
|
local math_random = math.random
|
||||||
|
|
||||||
local minetest_settings = minetest.settings
|
local minetest_settings = minetest.settings
|
||||||
|
|
||||||
|
-- CMI support check
|
||||||
|
local use_cmi = minetest.global_exists("cmi")
|
||||||
|
|
||||||
-- get entity staticdata
|
-- get entity staticdata
|
||||||
mobs.mob_staticdata = function(self)
|
mobs.mob_staticdata = function(self)
|
||||||
|
|
||||||
--despawn mechanism
|
--despawn mechanism
|
||||||
--don't despawned tamed or bred mobs
|
--don't despawned tamed or bred mobs
|
||||||
if not self.tamed and not self.bred then
|
if not self.tamed and not self.bred then
|
||||||
@ -142,8 +144,6 @@ mobs.mob_activate = function(self, staticdata, def, dtime)
|
|||||||
self.health = math_random (self.hp_min, self.hp_max)
|
self.health = math_random (self.hp_min, self.hp_max)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if not self.random_sound_timer then
|
if not self.random_sound_timer then
|
||||||
self.random_sound_timer = math_random(self.random_sound_timer_min,self.random_sound_timer_max)
|
self.random_sound_timer = math_random(self.random_sound_timer_min,self.random_sound_timer_max)
|
||||||
end
|
end
|
||||||
@ -185,7 +185,6 @@ mobs.mob_activate = function(self, staticdata, def, dtime)
|
|||||||
self.opinion_sound_cooloff = 0 -- used to prevent sound spam of particular sound types
|
self.opinion_sound_cooloff = 0 -- used to prevent sound spam of particular sound types
|
||||||
|
|
||||||
self.texture_mods = {}
|
self.texture_mods = {}
|
||||||
|
|
||||||
|
|
||||||
self.v_start = false
|
self.v_start = false
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
@ -199,7 +198,6 @@ mobs.mob_activate = function(self, staticdata, def, dtime)
|
|||||||
else
|
else
|
||||||
self.object:set_texture_mod("")
|
self.object:set_texture_mod("")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- set anything changed above
|
-- set anything changed above
|
||||||
self.object:set_properties(self)
|
self.object:set_properties(self)
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
|
|
||||||
-- lib_mount by Blert2112 (edited by TenPlus1)
|
-- lib_mount by Blert2112 (edited by TenPlus1)
|
||||||
|
|
||||||
local enable_crash = false
|
--local enable_crash = false
|
||||||
local crash_threshold = 6.5 -- ignored if enable_crash=false
|
--local crash_threshold = 6.5 -- ignored if enable_crash=false
|
||||||
|
|
||||||
|
local math = math
|
||||||
|
local vector = vector
|
||||||
|
|
||||||
------------------------------------------------------------------------------
|
------------------------------------------------------------------------------
|
||||||
|
|
||||||
@ -10,7 +13,7 @@ local crash_threshold = 6.5 -- ignored if enable_crash=false
|
|||||||
-- Helper functions
|
-- Helper functions
|
||||||
--
|
--
|
||||||
|
|
||||||
local node_ok = function(pos, fallback)
|
--[[local function node_ok(pos, fallback)
|
||||||
|
|
||||||
fallback = fallback or mobs.fallback_node
|
fallback = fallback or mobs.fallback_node
|
||||||
|
|
||||||
@ -21,10 +24,10 @@ local node_ok = function(pos, fallback)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {name = fallback}
|
return {name = fallback}
|
||||||
end
|
end]]
|
||||||
|
|
||||||
|
|
||||||
local function node_is(pos)
|
--[[local function node_is(pos)
|
||||||
|
|
||||||
local node = node_ok(pos)
|
local node = node_ok(pos)
|
||||||
|
|
||||||
@ -45,7 +48,7 @@ local function node_is(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return "other"
|
return "other"
|
||||||
end
|
end]]
|
||||||
|
|
||||||
|
|
||||||
local function get_sign(i)
|
local function get_sign(i)
|
||||||
@ -60,13 +63,11 @@ local function get_sign(i)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
local function get_velocity(v, yaw, y)
|
--[[local function get_velocity(v, yaw, y)
|
||||||
|
|
||||||
local x = -math.sin(yaw) * v
|
local x = -math.sin(yaw) * v
|
||||||
local z = math.cos(yaw) * v
|
local z = math.cos(yaw) * v
|
||||||
|
|
||||||
return {x = x, y = y, z = z}
|
return {x = x, y = y, z = z}
|
||||||
end
|
end]]
|
||||||
|
|
||||||
|
|
||||||
local function get_v(v)
|
local function get_v(v)
|
||||||
@ -172,7 +173,7 @@ function mobs.detach(player, offset)
|
|||||||
|
|
||||||
--pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z}
|
--pos = {x = pos.x + offset.x, y = pos.y + 0.2 + offset.y, z = pos.z + offset.z}
|
||||||
|
|
||||||
player:add_velocity(vector.new(math.random(-6,6),math.random(5,8),math.random(-6,6))) --throw the rider off
|
player:add_velocity(vector.new(math.random(-6,6), math.random(5,8), math.random(-6,6))) --throw the rider off
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
minetest.after(0.1, function(name, pos)
|
minetest.after(0.1, function(name, pos)
|
||||||
@ -187,13 +188,13 @@ end
|
|||||||
|
|
||||||
function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
|
function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
|
||||||
|
|
||||||
local rot_view = 0
|
--local rot_view = 0
|
||||||
|
|
||||||
if entity.player_rotation.y == 90 then
|
--if entity.player_rotation.y == 90 then
|
||||||
rot_view = math.pi/2
|
-- rot_view = math.pi/2
|
||||||
end
|
--end
|
||||||
|
|
||||||
local acce_y = 0
|
--local acce_y = 0
|
||||||
local velo = entity.object:get_velocity()
|
local velo = entity.object:get_velocity()
|
||||||
|
|
||||||
entity.v = get_v(velo) * get_sign(entity.v)
|
entity.v = get_v(velo) * get_sign(entity.v)
|
||||||
@ -388,7 +389,6 @@ end
|
|||||||
-- directional flying routine by D00Med (edited by TenPlus1)
|
-- directional flying routine by D00Med (edited by TenPlus1)
|
||||||
|
|
||||||
function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim)
|
function mobs.fly(entity, dtime, speed, shoots, arrow, moving_anim, stand_anim)
|
||||||
|
|
||||||
if true then
|
if true then
|
||||||
print("succ")
|
print("succ")
|
||||||
return
|
return
|
||||||
|
@ -9,9 +9,9 @@ local get_objects_inside_radius = minetest.get_objects_inside_radius
|
|||||||
|
|
||||||
local math_random = math.random
|
local math_random = math.random
|
||||||
local math_floor = math.floor
|
local math_floor = math.floor
|
||||||
local max = math.max
|
--local max = math.max
|
||||||
|
|
||||||
local vector_distance = vector.distance
|
--local vector_distance = vector.distance
|
||||||
local vector_new = vector.new
|
local vector_new = vector.new
|
||||||
local vector_floor = vector.floor
|
local vector_floor = vector.floor
|
||||||
|
|
||||||
@ -573,10 +573,10 @@ if mobs_spawn then
|
|||||||
local spawning_position = spawning_position_list[math_random(1,#spawning_position_list)]
|
local spawning_position = spawning_position_list[math_random(1,#spawning_position_list)]
|
||||||
|
|
||||||
--Prevent strange behavior --- this is commented out: /too close to player --fixed with inner circle
|
--Prevent strange behavior --- this is commented out: /too close to player --fixed with inner circle
|
||||||
if not spawning_position then -- or vector_distance(player_pos, spawning_position) < 15
|
if not spawning_position then -- or vector_distance(player_pos, spawning_position) < 15
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
|
|
||||||
--hard code mob limit in area to 5 for now
|
--hard code mob limit in area to 5 for now
|
||||||
if count_mobs(spawning_position) >= 5 then
|
if count_mobs(spawning_position) >= 5 then
|
||||||
break
|
break
|
||||||
@ -606,7 +606,7 @@ if mobs_spawn then
|
|||||||
local is_lava = get_item_group(gotten_node, "lava") ~= 0
|
local is_lava = get_item_group(gotten_node, "lava") ~= 0
|
||||||
|
|
||||||
local mob_def = nil
|
local mob_def = nil
|
||||||
|
|
||||||
--create a disconnected clone of the spawn dictionary
|
--create a disconnected clone of the spawn dictionary
|
||||||
--prevents memory leak
|
--prevents memory leak
|
||||||
local mob_library_worker_table = table_copy(spawn_dictionary)
|
local mob_library_worker_table = table_copy(spawn_dictionary)
|
||||||
|
Loading…
Reference in New Issue
Block a user