Code tidy, upped mese monster step height
This commit is contained in:
parent
04f91248fa
commit
57125c243c
52
api.lua
52
api.lua
@ -38,7 +38,9 @@ set_velocity = function(self, v)
|
||||
local z = 0
|
||||
|
||||
if v and v ~= 0 then
|
||||
|
||||
local yaw = (self.object:getyaw() + self.rotate) or 0
|
||||
|
||||
x = math.sin(yaw) * -v
|
||||
z = math.cos(yaw) * v
|
||||
end
|
||||
@ -53,6 +55,7 @@ end
|
||||
get_velocity = function(self)
|
||||
|
||||
local v = self.object:getvelocity()
|
||||
|
||||
return (v.x ^ 2 + v.z ^ 2) ^ (0.5)
|
||||
end
|
||||
|
||||
@ -66,49 +69,61 @@ set_animation = function(self, type)
|
||||
|
||||
if type == "stand"
|
||||
and self.animation.current ~= "stand" then
|
||||
|
||||
if self.animation.stand_start
|
||||
and self.animation.stand_end
|
||||
and self.animation.speed_normal then
|
||||
|
||||
self.object:set_animation({
|
||||
x = self.animation.stand_start,
|
||||
y = self.animation.stand_end},
|
||||
|
||||
self.animation.speed_normal, 0)
|
||||
self.animation.current = "stand"
|
||||
end
|
||||
|
||||
elseif type == "walk"
|
||||
and self.animation.current ~= "walk" then
|
||||
and self.animation.current ~= "walk" then
|
||||
|
||||
if self.animation.walk_start
|
||||
and self.animation.walk_end
|
||||
and self.animation.speed_normal then
|
||||
|
||||
self.object:set_animation({
|
||||
x = self.animation.walk_start,
|
||||
y = self.animation.walk_end},
|
||||
self.animation.speed_normal, 0)
|
||||
|
||||
self.animation.current = "walk"
|
||||
end
|
||||
|
||||
elseif type == "run"
|
||||
and self.animation.current ~= "run" then
|
||||
and self.animation.current ~= "run" then
|
||||
|
||||
if self.animation.run_start
|
||||
and self.animation.run_end
|
||||
and self.animation.speed_run then
|
||||
|
||||
self.object:set_animation({
|
||||
x = self.animation.run_start,
|
||||
y = self.animation.run_end},
|
||||
self.animation.speed_run, 0)
|
||||
|
||||
self.animation.current = "run"
|
||||
end
|
||||
|
||||
elseif type == "punch"
|
||||
and self.animation.current ~= "punch" then
|
||||
and self.animation.current ~= "punch" then
|
||||
|
||||
if self.animation.punch_start
|
||||
and self.animation.punch_end
|
||||
and self.animation.speed_normal then
|
||||
|
||||
self.object:set_animation({
|
||||
x = self.animation.punch_start,
|
||||
y = self.animation.punch_end},
|
||||
self.animation.speed_normal, 0)
|
||||
|
||||
self.animation.current = "punch"
|
||||
end
|
||||
end
|
||||
@ -245,6 +260,7 @@ do_env_damage = function(self)
|
||||
and (minetest.get_node_light(pos) or 0) > 12 then
|
||||
|
||||
self.object:set_hp(self.object:get_hp() - self.light_damage)
|
||||
|
||||
effect(pos, 5, "tnt_smoke.png")
|
||||
end
|
||||
|
||||
@ -526,7 +542,9 @@ local function breed(self)
|
||||
ent2.tamed = true
|
||||
ent2.owner = self.owner
|
||||
end)
|
||||
|
||||
num = 0
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
@ -540,6 +558,7 @@ function replace(self, pos)
|
||||
and math.random(1, self.replace_rate) == 1 then
|
||||
|
||||
local pos = self.object:getpos()
|
||||
|
||||
pos.y = pos.y + self.replace_offset
|
||||
|
||||
-- print ("replace node = ".. minetest.get_node(pos).name, pos.y)
|
||||
@ -563,10 +582,13 @@ end
|
||||
function day_docile(self)
|
||||
|
||||
if self.docile_by_day == false then
|
||||
|
||||
return false
|
||||
|
||||
elseif self.docile_by_day == true
|
||||
and self.time_of_day > 0.2
|
||||
and self.time_of_day < 0.8 then
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
@ -819,6 +841,7 @@ minetest.register_entity(name, {
|
||||
type = "player"
|
||||
else
|
||||
obj = oir:get_luaentity()
|
||||
|
||||
if obj then
|
||||
player = obj.object
|
||||
type = obj.type
|
||||
@ -831,9 +854,10 @@ minetest.register_entity(name, {
|
||||
s = self.object:getpos()
|
||||
p = player:getpos()
|
||||
sp = s
|
||||
-- aim higher to make looking up hills more realistic
|
||||
p.y = p.y + 1
|
||||
sp.y = sp.y + 1 -- aim higher to make looking up hills more realistic
|
||||
dist = ((p.x - s.x) ^ 2 + (p.y - s.y) ^ 2 + (p.z - s.z) ^ 2) ^ 0.5
|
||||
sp.y = sp.y + 1
|
||||
dist = vector.distance(p, s)
|
||||
|
||||
if dist < self.view_range then
|
||||
-- field of view check goes here
|
||||
@ -874,7 +898,7 @@ minetest.register_entity(name, {
|
||||
-- attack monster
|
||||
p = obj.object:getpos()
|
||||
|
||||
dist = ((p.x - s.x) ^ 2 + (p.y - s.y) ^ 2 + (p.z - s.z) ^ 2) ^ 0.5
|
||||
dist = vector.distance(p, s)
|
||||
|
||||
if dist < min_dist then
|
||||
min_dist = dist
|
||||
@ -903,7 +927,7 @@ minetest.register_entity(name, {
|
||||
|
||||
s = self.object:getpos()
|
||||
p = player:getpos()
|
||||
dist = ((p.x - s.x) ^ 2 + (p.y - s.y) ^ 2 + (p.z - s.z) ^ 2) ^ 0.5
|
||||
dist = vector.distance(p, s)
|
||||
|
||||
if dist < self.view_range then
|
||||
self.following = player
|
||||
@ -949,7 +973,7 @@ minetest.register_entity(name, {
|
||||
|
||||
if p then
|
||||
|
||||
local dist = ((p.x - s.x) ^ 2 + (p.y - s.y) ^ 2 + (p.z - s.z) ^ 2) ^ 0.5
|
||||
local dist = vector.distance(p, s)
|
||||
|
||||
-- dont follow if out of range
|
||||
if dist > self.view_range then
|
||||
@ -1126,7 +1150,7 @@ minetest.register_entity(name, {
|
||||
-- calculate distance from mob and enemy
|
||||
local s = self.object:getpos()
|
||||
local p = self.attack:getpos() or s
|
||||
local dist = ((p.x - s.x) ^ 2 + (p.y - s.y) ^ 2 + (p.z - s.z) ^ 2) ^ 0.5
|
||||
local dist = vector.distance(p, s)
|
||||
|
||||
-- stop attacking if no player or out of range
|
||||
if dist > self.view_range
|
||||
@ -1363,7 +1387,7 @@ minetest.register_entity(name, {
|
||||
p.y = p.y - .5
|
||||
s.y = s.y + .5
|
||||
|
||||
local dist = ((p.x - s.x) ^ 2 + (p.y - s.y) ^ 2 + (p.z - s.z) ^ 2) ^ 0.5
|
||||
local dist = vector.distance(p, s)
|
||||
local vec = {x = p.x - s.x, y = p.y - s.y, z = p.z - s.z}
|
||||
|
||||
yaw = (math.atan(vec.z / vec.x) + pi / 2) - self.rotate
|
||||
@ -1396,9 +1420,11 @@ minetest.register_entity(name, {
|
||||
p.y = p.y + (self.collisionbox[2] + self.collisionbox[5]) / 2
|
||||
|
||||
local obj = minetest.add_entity(p, self.arrow)
|
||||
local ent = obj:get_luaentity()
|
||||
|
||||
local amount = (vec.x ^ 2 + vec.y ^ 2 + vec.z ^ 2) ^ 0.5
|
||||
local v = obj:get_luaentity().velocity
|
||||
obj:get_luaentity().switch = 1
|
||||
local v = ent.velocity
|
||||
ent.switch = 1
|
||||
|
||||
-- offset makes shoot aim accurate
|
||||
vec.y = vec.y + self.shoot_offset
|
||||
@ -1866,7 +1892,7 @@ function mobs:register_arrow(name, def)
|
||||
|
||||
local pos = self.object:getpos()
|
||||
|
||||
if switch == 0
|
||||
if self.switch == 0
|
||||
or self.timer > 150
|
||||
or not within_limits(pos, 0) then
|
||||
|
||||
|
@ -30,6 +30,7 @@ mobs:register_mob("mobs:mese_monster", {
|
||||
jump_height = 8,
|
||||
fall_damage = 0,
|
||||
fall_speed = -6,
|
||||
stepheight = 3,
|
||||
drops = {
|
||||
{name = "default:mese_crystal",
|
||||
chance = 9, min = 1, max = 3},
|
||||
|
Loading…
x
Reference in New Issue
Block a user