mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-06-30 23:40:22 +02:00
drops can now be a function, also code tidy
This commit is contained in:
62
api.lua
62
api.lua
@ -6,9 +6,9 @@ local use_cmi = minetest.global_exists("cmi")
|
||||
|
||||
mobs = {
|
||||
mod = "redo",
|
||||
version = "20190823",
|
||||
version = "20190912",
|
||||
intllib = S,
|
||||
invis = minetest.global_exists("invisibility") and invisibility or {},
|
||||
invis = minetest.global_exists("invisibility") and invisibility or {}
|
||||
}
|
||||
|
||||
-- creative check
|
||||
@ -79,11 +79,11 @@ local node_snow = "default:snow"
|
||||
mobs.fallback_node = minetest.registered_aliases["mapgen_dirt"] or "default:dirt"
|
||||
|
||||
local mob_class = {
|
||||
stepheight = 1.1, -- was 0.6
|
||||
stepheight = 1.1,
|
||||
fly_in = "air",
|
||||
owner = "",
|
||||
order = "",
|
||||
jump_height = 4, -- was 6
|
||||
jump_height = 4,
|
||||
lifetimer = 180, -- 3 minutes
|
||||
physical = true,
|
||||
collisionbox = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
|
||||
@ -142,8 +142,9 @@ local mob_class = {
|
||||
attack_players = true,
|
||||
attack_npcs = true,
|
||||
facing_fence = false,
|
||||
_cmi_is_mob = true,
|
||||
_cmi_is_mob = true
|
||||
}
|
||||
|
||||
local mob_class_meta = {__index = mob_class}
|
||||
|
||||
-- play sound
|
||||
@ -232,7 +233,7 @@ function mob_class:set_velocity(v)
|
||||
self.object:set_velocity({
|
||||
x = (sin(yaw) * -v) + c_x,
|
||||
y = self.object:get_velocity().y,
|
||||
z = (cos(yaw) * v) + c_y,
|
||||
z = (cos(yaw) * v) + c_y
|
||||
})
|
||||
end
|
||||
|
||||
@ -285,7 +286,7 @@ function mob_class:set_animation(anim, force)
|
||||
|
||||
self.animation.current = self.animation.current or ""
|
||||
|
||||
-- only set different animation for attacks when using same set
|
||||
-- only use different animation for attacks when using same set
|
||||
if force ~= true and anim ~= "punch" and anim ~= "shoot"
|
||||
and string.find(self.animation.current, anim) then
|
||||
return
|
||||
@ -393,7 +394,6 @@ local line_of_sight = function(self, pos1, pos2, stepsize)
|
||||
|
||||
-- New Nodename found
|
||||
nn = minetest.get_node(pos).name
|
||||
|
||||
end
|
||||
|
||||
return false
|
||||
@ -528,7 +528,7 @@ function mob_class:flight_check()
|
||||
|
||||
local def = minetest.registered_nodes[self.standing_in]
|
||||
|
||||
if not def then return false end -- nil check
|
||||
if not def then return false end
|
||||
|
||||
if type(self.fly_in) == "string"
|
||||
and self.standing_in == self.fly_in then
|
||||
@ -631,7 +631,7 @@ local effect = function(pos, amount, texture, min_size, max_size, radius, gravit
|
||||
minsize = min_size,
|
||||
maxsize = max_size,
|
||||
texture = texture,
|
||||
glow = glow,
|
||||
glow = glow
|
||||
})
|
||||
end
|
||||
|
||||
@ -664,6 +664,11 @@ end
|
||||
-- drop items
|
||||
function mob_class:item_drop()
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
|
||||
-- check for drops function
|
||||
self.drops = type(self.drops) == "function" and self.drops(pos) or self.drops
|
||||
|
||||
-- check for nil or no drops
|
||||
if not self.drops or #self.drops == 0 then
|
||||
return
|
||||
@ -680,7 +685,6 @@ function mob_class:item_drop()
|
||||
and self.cause_of_death.puncher:is_player() or nil
|
||||
|
||||
local obj, item, num
|
||||
local pos = self.object:get_pos()
|
||||
|
||||
for n = 1, #self.drops do
|
||||
|
||||
@ -713,7 +717,7 @@ function mob_class:item_drop()
|
||||
obj:set_velocity({
|
||||
x = random(-10, 10) / 9,
|
||||
y = 6,
|
||||
z = random(-10, 10) / 9,
|
||||
z = random(-10, 10) / 9
|
||||
})
|
||||
|
||||
elseif obj then
|
||||
@ -842,8 +846,7 @@ function mob_class:is_at_cliff()
|
||||
|
||||
if minetest.line_of_sight(
|
||||
{x = pos.x + dir_x, y = ypos, z = pos.z + dir_z},
|
||||
{x = pos.x + dir_x, y = ypos - self.fear_height, z = pos.z + dir_z}
|
||||
, 1) then
|
||||
{x = pos.x + dir_x, y = ypos - self.fear_height, z = pos.z + dir_z}, 1) then
|
||||
|
||||
return true
|
||||
end
|
||||
@ -1044,9 +1047,9 @@ function mob_class:do_jump()
|
||||
if self.object:get_luaentity() then
|
||||
|
||||
self.object:set_acceleration({
|
||||
x = v.x * 2,--1.5,
|
||||
x = v.x * 2,
|
||||
y = 0,
|
||||
z = v.z * 2,--1.5
|
||||
z = v.z * 2
|
||||
})
|
||||
end
|
||||
end, self, v)
|
||||
@ -1157,7 +1160,7 @@ function mob_class:breed()
|
||||
mesh = self.base_mesh,
|
||||
visual_size = self.base_size,
|
||||
collisionbox = self.base_colbox,
|
||||
selectionbox = self.base_selbox,
|
||||
selectionbox = self.base_selbox
|
||||
})
|
||||
|
||||
-- custom function when child grows up
|
||||
@ -1272,7 +1275,7 @@ function mob_class:breed()
|
||||
textures = textures,
|
||||
visual_size = {
|
||||
x = self.base_size.x * .5,
|
||||
y = self.base_size.y * .5,
|
||||
y = self.base_size.y * .5
|
||||
},
|
||||
collisionbox = {
|
||||
self.base_colbox[1] * .5,
|
||||
@ -1280,7 +1283,7 @@ function mob_class:breed()
|
||||
self.base_colbox[3] * .5,
|
||||
self.base_colbox[4] * .5,
|
||||
self.base_colbox[5] * .5,
|
||||
self.base_colbox[6] * .5,
|
||||
self.base_colbox[6] * .5
|
||||
},
|
||||
selectionbox = {
|
||||
self.base_selbox[1] * .5,
|
||||
@ -1288,7 +1291,7 @@ function mob_class:breed()
|
||||
self.base_selbox[3] * .5,
|
||||
self.base_selbox[4] * .5,
|
||||
self.base_selbox[5] * .5,
|
||||
self.base_selbox[6] * .5,
|
||||
self.base_selbox[6] * .5
|
||||
},
|
||||
})
|
||||
-- tamed and owned by parents' owner
|
||||
@ -1646,7 +1649,7 @@ local specific_attack = function(list, what)
|
||||
end
|
||||
|
||||
|
||||
-- general attack function for all mobs ==========
|
||||
-- general attack function for all mobs
|
||||
function mob_class:general_attack()
|
||||
|
||||
-- return if already attacking, passive or docile during day
|
||||
@ -2264,7 +2267,7 @@ function mob_class:do_states(dtime)
|
||||
tnt.boom(pos, {
|
||||
radius = node_break_radius,
|
||||
damage_radius = entity_damage_radius,
|
||||
sound = self.sounds.explode,
|
||||
sound = self.sounds.explode
|
||||
})
|
||||
else
|
||||
|
||||
@ -2415,13 +2418,7 @@ function mob_class:do_states(dtime)
|
||||
if self.timer > 1 then
|
||||
|
||||
self.timer = 0
|
||||
|
||||
-- if self.double_melee_attack
|
||||
-- and random(1, 2) == 1 then
|
||||
-- self:set_animation("punch2")
|
||||
-- else
|
||||
self:set_animation("punch")
|
||||
-- end
|
||||
self:set_animation("punch")
|
||||
|
||||
local p2 = p
|
||||
local s2 = s
|
||||
@ -3606,8 +3603,7 @@ function mobs:spawn(def)
|
||||
def.min_height or -31000,
|
||||
def.max_height or 31000,
|
||||
def.day_toggle,
|
||||
def.on_spawn
|
||||
)
|
||||
def.on_spawn)
|
||||
end
|
||||
|
||||
|
||||
@ -3667,7 +3663,7 @@ function mobs:register_arrow(name, def)
|
||||
collisiondetection = false,
|
||||
texture = def.tail_texture,
|
||||
size = def.tail_size or 5,
|
||||
glow = def.glow or 0,
|
||||
glow = def.glow or 0
|
||||
})
|
||||
end
|
||||
|
||||
@ -4191,8 +4187,6 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
|
||||
local tag = self.nametag or ""
|
||||
|
||||
minetest.show_formspec(name, "mobs_nametag", "size[8,4]"
|
||||
.. default.gui_bg
|
||||
.. default.gui_bg_img
|
||||
.. "field[0.5,1;7.5,0;name;"
|
||||
.. minetest.formspec_escape(S("Enter name:")) .. ";" .. tag .. "]"
|
||||
.. "button_exit[2.5,3.5;3,1;mob_rename;"
|
||||
|
Reference in New Issue
Block a user