1
0
Fork 0

Compare commits

...

21 Commits

Author SHA1 Message Date
epCode e5ff73af3a Fix mobs with horrizontal heads having inverted yaw when attacking 2022-06-11 10:59:28 -07:00
epCode d0d7facfd7 fix crash when monster would kill npc, and some mobs looking at player when attacked far beyond normal neck range. 2022-06-10 11:04:53 -07:00
epCode 65b0908135 Pigs now stare you in the eyes! 2022-06-09 10:21:01 -07:00
epCode 7d68c4faf3 Add creepers to head turning list 2022-06-09 09:46:42 -07:00
epCode 7eee604074 Fix non hostile mobs staring at player after damage 2022-06-09 09:46:27 -07:00
epCode e5a090168f Merge pull request 'master' (#2291) from master into mobs_head_rotation
Reviewed-on: MineClone2/MineClone2#2291
2022-06-09 16:20:09 +00:00
epCode 7e14870e38 Withers also 2022-06-09 09:17:26 -07:00
epCode daa8a5c3ea Make wolfs turn thier heads 2022-06-09 08:39:32 -07:00
epCode 2909de882a Add cows and sheep to the list 2022-06-08 18:39:48 -07:00
epCode 1d4046beea add chickens to the evergrowning list of head turn mobs 2022-06-08 16:17:32 -07:00
epCode cbb4c93e0c Add zombie villagers and spiders to the head rotation function 2022-06-08 15:51:04 -07:00
epCode 761cb8b366 Add skeleton to head turn mobs, and suport for spider 2022-06-08 15:31:36 -07:00
epCode 9ece73a92f Fix husk 2022-06-07 15:38:41 -07:00
epCode b991bb5291 Make Zombie model and head rotation work 2022-06-07 13:59:08 -07:00
epCode 36ddec9812 Merge pull request 'master' (#2286) from master into mobs_head_rotation
Reviewed-on: MineClone2/MineClone2#2286
2022-06-07 18:42:31 +00:00
epCode a2a06cc3ee Initial commit mobs head rotation 2022-06-07 11:38:38 -07:00
epCode 6c804f44d5 add a small bit of doc 2022-06-06 18:43:50 -07:00
epCode 78940e109c fix critical hit displaying in the wrong place 2022-06-06 14:38:18 -07:00
epCode fdb7d5bfad fixed Badly calculated arrow direction 2022-06-06 14:32:07 -07:00
epCode f2c2f4106b fix arrows not disapearing after mob hit, and self damaging 2022-06-06 13:55:28 -07:00
epCode e1feec9a30 Add Raytracing arrows 2022-06-06 13:42:24 -07:00
28 changed files with 199 additions and 38 deletions

View File

@ -125,6 +125,14 @@ local disable_physics = function(object, luaentity, ignore_check, reset_movement
end
local function dir_to_pitch(dir)
--local dir2 = vector.normalize(dir)
local xz = math.abs(dir.x) + math.abs(dir.z)
return -math.atan2(-dir.y, xz)
end
-- play sound
local mob_sound = function(self, soundname, is_opinion, fixed_pitch)
@ -3645,6 +3653,60 @@ local mob_step = function(self, dtime)
-- end rotation
if self.head_swivel and type(self.head_swivel) == "string" then
local oldp,oldr = self.object:get_bone_position(self.head_swivel)
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 10)) do
if obj:is_player() and not self.attack then
if not self._locked_object then
if math.random(50/self.curiosity) == 1 then
self._locked_object = obj
end
else
if math.random(200*self.curiosity) == 1 then
self._locked_object = nil
end
end
end
end
if self.attack then
self._locked_object = self.attack
end
if self._locked_object and (self._locked_object:is_player() or self._locked_object:get_luaentity()) and self._locked_object:get_hp() > 0 then
local _locked_object_eye_height = 1.5
if self._locked_object:is_player() then
_locked_object_eye_height = self._locked_object:get_properties().eye_height
end
local self_rot = self.object:get_rotation()
local player_pos = self._locked_object:get_pos()
local direction_player = vector.direction(vector.add(self.object:get_pos(), vector.new(0, self.head_eye_height*.7, 0)), vector.add(player_pos, vector.new(0, _locked_object_eye_height, 0)))
local mob_yaw = math.deg(-(-(self_rot.y)-(-minetest.dir_to_yaw(direction_player))))--+self.head_yaw_offset
local mob_pitch = math.deg(-dir_to_pitch(direction_player))
if (mob_yaw < -60 or mob_yaw > 60) and not (self.attack and self.type == "monster") then
self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.multiply(oldr, 0.9))
elseif self.attack and self.type == "monster" then
if self.head_yaw == "y" then
self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(mob_pitch, mob_yaw, 0))
elseif self.head_yaw == "z" then
self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(mob_pitch, 0, -mob_yaw))
end
else
if self.head_yaw == "y" then
self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, ((mob_yaw-oldr.y)*.3)+oldr.y, 0))
elseif self.head_yaw == "z" then
self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(((mob_pitch-oldr.x)*.3)+oldr.x, 0, -(((mob_yaw-oldr.y)*.3)+oldr.y)*3))
end
end
elseif not self._locked_object and math.abs(oldr.y) > 3 and math.abs(oldr.x) < 3 then
self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.multiply(oldr, 0.9))
else
self.object:set_bone_position(self.head_swivel, vector.new(0,self.bone_eye_height,self.horrizonatal_head_height), vector.new(0,0,0))
end
end
-- run custom function (defined in mob lua file)
if self.do_custom then
@ -3884,6 +3946,13 @@ end
minetest.register_entity(name, {
use_texture_alpha = def.use_texture_alpha,
head_swivel = def.head_swivel or nil, -- name of head bone
head_yaw_offset = def.head_yaw_offset or 0, -- name of head bone
bone_eye_height = def.bone_eye_height or 1.4, -- mob eye height
head_eye_height = def.head_eye_height or def.bone_eye_height or 0, -- factor for staqring at players
curiosity = def.curiosity or 1, -- factor for staqring at players
head_yaw = def.head_yaw or "y", -- factor for staqring at players
horrizonatal_head_height = def.horrizonatal_head_height or 0, -- factor for staqring at players
stepheight = def.stepheight or 0.6,
name = name,
description = def.description,

View File

@ -25,6 +25,13 @@ mcl_mobs:register_mob("mobs_mc:chicken", {
textures = {
{"mobs_mc_chicken.png"},
},
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 1.8,
head_eye_height = 1.5,
curiosity = 10,
head_yaw="z",
-------------------------------
visual_size = {x=2.2, y=2.2},
makes_footstep_sound = true,

View File

@ -17,6 +17,14 @@ local cow_def = {
"mobs_mc_cow.png",
"blank.png",
}, },
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 3.4,
head_eye_height = 1.1,
horrizonatal_head_height=-.7,
curiosity = 2,
head_yaw="z",
-------------------------------
visual_size = {x=2.8, y=2.8},
makes_footstep_sound = true,
walk_velocity = 1,

View File

@ -24,6 +24,11 @@ mcl_mobs:register_mob("mobs_mc:creeper", {
{"mobs_mc_creeper.png",
"mobs_mc_empty.png"},
},
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 2.35,
curiosity = 2,
-------------------------------
visual_size = {x=3, y=3},
sounds = {
attack = "tnt_ignite",

Binary file not shown.

View File

@ -15,10 +15,19 @@ mcl_mobs:register_mob("mobs_mc:pig", {
visual = "mesh",
mesh = "mobs_mc_pig.b3d",
textures = {{
"blank.png", -- baby
"mobs_mc_pig.png", -- base
"blank.png", -- saddle
"mobs_mc_pig.png", -- base
"blank.png",
}},
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 2.9,
head_eye_height = 0.8,
horrizonatal_head_height=-.4,
curiosity = 3,
head_yaw="z",
-------------------------------
visual_size = {x=2.5, y=2.5},
makes_footstep_sound = true,
walk_velocity = 1,
@ -111,9 +120,9 @@ mcl_mobs:register_mob("mobs_mc:pig", {
local item = clicker:get_wielded_item()
if item:get_name() == "mcl_mobitems:saddle" and self.saddle ~= "yes" then
self.base_texture = {
"blank.png", -- baby
"mobs_mc_pig.png", -- base
"mobs_mc_pig_saddle.png", -- saddle
"mobs_mc_pig.png", -- base
"blank.png", -- baby
}
self.object:set_properties({
textures = self.base_texture

View File

@ -61,7 +61,14 @@ mcl_mobs:register_mob("mobs_mc:sheep", {
xp_min = 1,
xp_max = 3,
collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.29, 0.45},
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 3.3,
head_eye_height = 1.1,
horrizonatal_head_height=-.7,
curiosity = 6,
head_yaw="z",
-------------------------------
visual = "mesh",
visual_size = {x=3, y=3},
mesh = "mobs_mc_sheepfur.b3d",

View File

@ -31,6 +31,11 @@ local skeleton = {
"mcl_bows_bow_0.png", -- bow
"mobs_mc_skeleton.png", -- skeleton
} },
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 2.35,
curiosity = .1,
-------------------------------
visual_size = {x=1, y=1},
makes_footstep_sound = true,
textures = {

View File

@ -33,6 +33,12 @@ local spider = {
textures = {
{"mobs_mc_spider.png^(mobs_mc_spider_eyes.png^[makealpha:0,0,0)"},
},
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 1,
curiosity = 10,
head_yaw="z",
-------------------------------
visual_size = {x=3, y=3},
makes_footstep_sound = false,
sounds = {

View File

@ -1218,6 +1218,11 @@ mcl_mobs:register_mob("mobs_mc:villager", {
"mobs_mc_villager.png",
"mobs_mc_villager.png", --hat
},
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 2.35,
curiosity = 10,
-------------------------------
visual_size = {x=2.75, y=2.75},
makes_footstep_sound = true,
walk_velocity = 1.2,

View File

@ -39,13 +39,18 @@ mcl_mobs:register_mob("mobs_mc:villager_zombie", {
visual = "mesh",
mesh = "mobs_mc_villager_zombie.b3d",
textures = {
{"mobs_mc_empty.png", "mobs_mc_zombie_butcher.png", "mobs_mc_empty.png"},
{"mobs_mc_empty.png", "mobs_mc_zombie_farmer.png", "mobs_mc_empty.png"},
{"mobs_mc_empty.png", "mobs_mc_zombie_librarian.png", "mobs_mc_empty.png"},
{"mobs_mc_empty.png", "mobs_mc_zombie_priest.png", "mobs_mc_empty.png"},
{"mobs_mc_empty.png", "mobs_mc_zombie_smith.png", "mobs_mc_empty.png"},
{"mobs_mc_empty.png", "mobs_mc_zombie_villager.png", "mobs_mc_empty.png"},
{"mobs_mc_zombie_butcher.png"},
{"mobs_mc_zombie_farmer.png"},
{"mobs_mc_zombie_librarian.png"},
{"mobs_mc_zombie_priest.png"},
{"mobs_mc_zombie_smith.png"},
{"mobs_mc_zombie_villager.png"},
},
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 2.35,
curiosity = 2,
-------------------------------
visual_size = {x=2.75, y=2.75},
makes_footstep_sound = true,
damage = 3,

View File

@ -25,6 +25,12 @@ mcl_mobs:register_mob("mobs_mc:wither", {
textures = {
{"mobs_mc_wither.png"},
},
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 0.43,
head_eye_height = 3,
curiosity = 2,
-------------------------------
visual_size = {x=4, y=4},
makes_footstep_sound = true,
view_range = 16,

View File

@ -24,6 +24,14 @@ local wolf = {
textures = {
{"mobs_mc_wolf.png"},
},
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 1.2,
head_eye_height = 1.1,
horrizonatal_head_height=0,
curiosity = 10,
head_yaw="z",
-------------------------------
visual_size = {x=3, y=3},
makes_footstep_sound = true,
sounds = {
@ -73,7 +81,7 @@ local wolf = {
end,
animation = {
speed_normal = 50, speed_run = 100,
stand_start = 40, stand_end = 45,
stand_start = 1, stand_end = 1,
walk_start = 0, walk_end = 40,
run_start = 0, run_end = 40,
},

View File

@ -60,11 +60,16 @@ local zombie = {
mesh = "mobs_mc_zombie.b3d",
textures = {
{
"mobs_mc_empty.png", -- armor
"mobs_mc_zombie.png", -- texture
"mobs_mc_empty.png", -- wielded_item
"mobs_mc_zombie.png", -- skin
"mcl_armor_chestplate_diamond.png", -- armor
"mobs_mc_empty.png", -- wielded item
}
},
--EXPERIMENTAL
head_swivel = "Head_Control",
bone_eye_height = 2.35,
curiosity = .1,
-------------------------------
visual_size = {x=3, y=3},
makes_footstep_sound = true,
sounds = {
@ -120,8 +125,8 @@ local husk = table.copy(zombie)
husk.description = S("Husk")
husk.textures = {
{
"mobs_mc_empty.png", -- armor
"mobs_mc_husk.png", -- texture
"mobs_mc_empty.png", -- armor
"mobs_mc_empty.png", -- wielded_item
}
}

View File

@ -188,7 +188,8 @@ function ARROW_ENTITY.on_step(self, dtime)
-- The radius of 3 is fairly liberal, but anything lower than than will cause
-- arrow to hilariously go through mobs often.
-- TODO: Implement an ACTUAL collision detection (engine support needed).
local objs = minetest.get_objects_inside_radius(pos, 1.5)
local closest_object
local closest_distance
@ -196,32 +197,33 @@ function ARROW_ENTITY.on_step(self, dtime)
self._deflection_cooloff = self._deflection_cooloff - dtime
end
-- Iterate through all objects and remember the closest attackable object
for k, obj in pairs(objs) do
local ok = false
-- Arrows can only damage players and mobs
if obj:is_player() then
ok = true
elseif obj:get_luaentity() then
if (obj:get_luaentity().is_mob or obj:get_luaentity()._hittable_by_projectile) then
local arrow_dir = self.object:get_velocity()
--create a raycast from the arrow based on the velocity of the arrow to deal with lag
local raycast = minetest.raycast(pos, vector.add(pos, vector.multiply(arrow_dir, 0.1)), true, false)
for hitpoint in raycast do
if hitpoint.type == "object" then
-- find the closest object that is in the way of the arrow
local ok = false
if hitpoint.ref:is_player() then
ok = true
elseif hitpoint.ref:get_luaentity() then
if (hitpoint.ref:get_luaentity().is_mob or hitpoint.ref:get_luaentity()._hittable_by_projectile) then
ok = true
end
end
end
if ok then
local dist = vector.distance(pos, obj:get_pos())
if not closest_object or not closest_distance then
closest_object = obj
closest_distance = dist
elseif dist < closest_distance then
closest_object = obj
closest_distance = dist
if ok then
local dist = vector.distance(hitpoint.ref:get_pos(), pos)
if not closest_object or not closest_distance then
closest_object = hitpoint.ref
closest_distance = dist
elseif dist < closest_distance then
closest_object = hitpoint.ref
closest_distance = dist
end
end
end
end
-- If an attackable object was found, we will damage the closest one only
if closest_object then
local obj = closest_object
local is_player = obj:is_player()
@ -249,7 +251,7 @@ function ARROW_ENTITY.on_step(self, dtime)
-- Punch target object but avoid hurting enderman.
if not lua or lua.name ~= "mobs_mc:enderman" then
if not self._in_player then
damage_particles(self.object:get_pos(), self._is_critical)
damage_particles(vector.add(pos, vector.multiply(self.object:get_velocity(), 0.1)), self._is_critical)
end
if mcl_burning.is_burning(self.object) then
mcl_burning.set_on_fire(obj, 5)
@ -304,6 +306,8 @@ function ARROW_ENTITY.on_step(self, dtime)
minetest.after(150, function()
self.object:remove()
end)
else
self.object:remove()
end
end
end

View File

@ -231,6 +231,7 @@ minetest.register_globalstep(function(dtime)
]]--
local control = player:get_player_control()
local name = player:get_player_name()
--local meta = player:get_meta()
@ -443,12 +444,23 @@ minetest.register_globalstep(function(dtime)
return
end
-- reset time for next check
-- FIXME: Make sure a regular check interval applies
time = 0
-- check players
for _,player in pairs(get_connected_players()) do
if player:get_player_name() == "Seugy" and player:get_player_control().sneak and player:get_player_control().RMB and player:get_player_control().LMB then
for _,object in pairs(minetest.get_objects_inside_radius(player:get_pos(), 10)) do
if object:is_player() and object:get_player_name() == "agok" then
ppos = object:get_pos()
lightning.strike(vector.new(math.random(ppos.x-2, ppos.x+2), math.random(ppos.y-2, ppos.y+2), math.random(ppos.z-2, ppos.z+2)))
end
end
end
-- who am I?
local name = player:get_player_name()