1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2025-07-17 15:50:28 +02:00

Compare commits

..

10 Commits

7 changed files with 139 additions and 109 deletions

122
api.lua
View File

@ -6,9 +6,9 @@ local use_cmi = minetest.global_exists("cmi")
mobs = {
mod = "redo",
version = "20190520",
version = "20191116",
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
@ -474,7 +474,7 @@ local ray_line_of_sight = function(self, pos1, pos2)
end
-- detect if using minetest 5.0 by searching for permafrost node
local is_50 = minetest.registered_nodes["default:permafrost"]
local is_50 = nil -- minetest.registered_nodes["default:permafrost"]
function mob_class:line_of_sight(pos1, pos2, stepsize)
@ -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
@ -586,11 +586,7 @@ function mob_class:do_stay_near()
local target = nearby_nodes[math.random(1, #nearby_nodes)]
local direction = vector.direction(pos, target)
local vec = {
x = target.x - pos.x,
z = target.z - pos.z
}
local vec = {x = target.x - pos.x, z = target.z - pos.z}
yaw = (atan(vec.z / vec.x) + pi / 2) - self.rotate
@ -631,7 +627,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 +660,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 +681,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 +713,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 +842,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 +1043,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 +1156,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 +1271,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 +1279,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 +1287,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 +1645,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
@ -2023,7 +2022,7 @@ function mob_class:do_states(dtime)
and self.walk_chance ~= 0
and self.facing_fence ~= true
and random(1, 100) <= self.walk_chance
and self:is_at_cliff() == false then
and self.at_cliff == false then
self:set_velocity(self.walk_velocity)
self.state = "walk"
@ -2104,10 +2103,8 @@ function mob_class:do_states(dtime)
end
-- stand for great fall in front
local temp_is_cliff = self:is_at_cliff()
if self.facing_fence == true
or temp_is_cliff
or self.at_cliff
or random(1, 100) <= self.stand_chance then
self:set_velocity(0)
@ -2133,7 +2130,7 @@ function mob_class:do_states(dtime)
-- stop after 5 seconds or when at cliff
if self.runaway_timer > 5
or self:is_at_cliff()
or self.at_cliff
or self.order == "stand" then
self.runaway_timer = 0
self:set_velocity(0)
@ -2235,9 +2232,9 @@ function mob_class:do_states(dtime)
self.blinktimer = 0
if self.blinkstatus then
self.object:settexturemod("")
self.object:set_texture_mod("")
else
self.object:settexturemod("^[brighten")
self.object:set_texture_mod("^[brighten")
end
self.blinkstatus = not self.blinkstatus
@ -2264,7 +2261,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
@ -2383,7 +2380,7 @@ function mob_class:do_states(dtime)
self:smart_mobs(s, p, dist, dtime)
end
if self:is_at_cliff() then
if self.at_cliff then
self:set_velocity(0)
self:set_animation("stand")
@ -2415,13 +2412,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
@ -3128,6 +3119,24 @@ function mob_class:on_step(dtime)
x = pos.x, y = pos.y + y_level + 0.25, z = pos.z}, "air").name
-- print ("standing in " .. self.standing_in)
-- if standing inside solid block then jump to escape
if minetest.registered_nodes[self.standing_in].walkable and
minetest.registered_nodes[self.standing_in].drawtype == "normal" then
self.object:set_velocity({
x = 0,
y = self.jump_height,
z = 0
})
end
-- check and stop if standing at cliff and fear of heights
self.at_cliff = self:is_at_cliff()
if self.at_cliff then
self:set_velocity(0)
end
-- check for mob expiration (0.25 instead of dtime since were in a timer)
self:mob_expire(pos, 0.25)
end
@ -3374,11 +3383,13 @@ end -- END mobs:register_mob function
-- count how many mobs of one type are inside an area
-- will also return true for second value if player is inside area
local count_mobs = function(pos, type)
local total = 0
local objs = minetest.get_objects_inside_radius(pos, aoc_range * 2)
local ent
local players
for n = 1, #objs do
@ -3390,10 +3401,12 @@ local count_mobs = function(pos, type)
if ent and ent.name and ent.name == type then
total = total + 1
end
else
players = true
end
end
return total
return total, players
end
@ -3462,7 +3475,12 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
end
-- get total number of this mob in area
local num_mob = count_mobs(pos, name)
local num_mob, is_pla = count_mobs(pos, name)
if not is_pla then
--print ("--- no players within active area, will not spawn " .. name)
return
end
if num_mob >= aoc then
--print ("--- too many " .. name .. " in area", num_mob .. "/" .. aoc)
@ -3509,7 +3527,7 @@ function mobs:spawn_specific(name, nodes, neighbors, min_light, max_light,
end
-- only spawn away from player
local objs = minetest.get_objects_inside_radius(pos, 10)
local objs = minetest.get_objects_inside_radius(pos, 8)
for n = 1, #objs do
@ -3586,8 +3604,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
@ -3647,7 +3664,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
@ -4171,8 +4188,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;"
@ -4233,6 +4248,11 @@ end)
-- compatibility function for old entities to new modpack entities
function mobs:alias_mob(old_name, new_name)
-- check old_name entity doesnt already exist
if minetest.registered_entities[old_name] then
return
end
-- spawn egg
minetest.register_alias(old_name, new_name)

15
api.txt
View File

@ -158,6 +158,11 @@ functions needed for the mob to work properly which contains the following:
'min' minimum number of items dropped, set to 0 for rare drops.
'max' maximum number of items dropped.
Note: If weapon has {fire=1} damage group set then cooked items will drop.
Note2: A function can now be passed which can also return drops table, e.g.
drops = function(pos)
-- do something
return { {name = "farming:bread"}, {name = "default:dirt", chance = 2} }
end
'visual' holds the look of the mob you wish to create:
'cube' looks like a normal node
@ -624,8 +629,14 @@ Players can override the spawn chance for each mob registered by adding a line
to their minetest.conf file with a new value, the lower the value the more each
mob will spawn e.g.
mobs_animal:sheep_chance 11000
mobs_monster:sand_monster_chance 100
mobs_animal:sheep 11000
mobs_monster:sand_monster 100
...you can also change how many of a certain mob appear in an active mapblock by
adding a comma and then a new value e.g.
mobs_animal:cow 8000,4 <-- 4 cows per mapblock at 8000 spawn chance
mobs_monster:dirt_monster ,20 <-- 20 dirt monsters per mapblock
Rideable Horse Example Mob

View File

@ -5,14 +5,14 @@ local S = mobs.intllib
minetest.register_craftitem("mobs:nametag", {
description = S("Name Tag"),
inventory_image = "mobs_nametag.png",
groups = {flammable = 2},
groups = {flammable = 2}
})
if minetest.get_modpath("dye") and minetest.get_modpath("farming") then
minetest.register_craft({
type = "shapeless",
output = "mobs:nametag",
recipe = {"default:paper", "dye:black", "farming:string"},
recipe = {"default:paper", "dye:black", "farming:string"}
})
end
@ -20,7 +20,7 @@ end
minetest.register_craftitem("mobs:leather", {
description = S("Leather"),
inventory_image = "mobs_leather.png",
groups = {flammable = 2},
groups = {flammable = 2}
})
-- raw meat
@ -28,7 +28,7 @@ minetest.register_craftitem("mobs:meat_raw", {
description = S("Raw Meat"),
inventory_image = "mobs_meat_raw.png",
on_use = minetest.item_eat(3),
groups = {food_meat_raw = 1, flammable = 2},
groups = {food_meat_raw = 1, flammable = 2}
})
-- cooked meat
@ -36,21 +36,21 @@ minetest.register_craftitem("mobs:meat", {
description = S("Meat"),
inventory_image = "mobs_meat.png",
on_use = minetest.item_eat(8),
groups = {food_meat = 1, flammable = 2},
groups = {food_meat = 1, flammable = 2}
})
minetest.register_craft({
type = "cooking",
output = "mobs:meat",
recipe = "mobs:meat_raw",
cooktime = 5,
cooktime = 5
})
-- lasso
minetest.register_tool("mobs:lasso", {
description = S("Lasso (right-click animal to put in inventory)"),
inventory_image = "mobs_magic_lasso.png",
groups = {flammable = 2},
groups = {flammable = 2}
})
if minetest.get_modpath("farming") then
@ -59,7 +59,7 @@ if minetest.get_modpath("farming") then
recipe = {
{"farming:string", "", "farming:string"},
{"", "default:diamond", ""},
{"farming:string", "", "farming:string"},
{"farming:string", "", "farming:string"}
}
})
end
@ -70,7 +70,7 @@ minetest.register_alias("mobs:magic_lasso", "mobs:lasso")
minetest.register_tool("mobs:net", {
description = S("Net (right-click animal to put in inventory)"),
inventory_image = "mobs_net.png",
groups = {flammable = 2},
groups = {flammable = 2}
})
if minetest.get_modpath("farming") then
@ -79,7 +79,7 @@ if minetest.get_modpath("farming") then
recipe = {
{"group:stick", "", "group:stick"},
{"group:stick", "", "group:stick"},
{"farming:string", "group:stick", "farming:string"},
{"farming:string", "group:stick", "farming:string"}
}
})
end
@ -88,14 +88,14 @@ end
minetest.register_tool("mobs:shears", {
description = S("Steel Shears (right-click to shear)"),
inventory_image = "mobs_shears.png",
groups = {flammable = 2},
groups = {flammable = 2}
})
minetest.register_craft({
output = 'mobs:shears',
output = "mobs:shears",
recipe = {
{'', 'default:steel_ingot', ''},
{'', 'group:stick', 'default:steel_ingot'},
{"", "default:steel_ingot", ""},
{"", "group:stick", "default:steel_ingot"}
}
})
@ -103,7 +103,7 @@ minetest.register_craft({
minetest.register_craftitem("mobs:protector", {
description = S("Mob Protection Rune"),
inventory_image = "mobs_protector.png",
groups = {flammable = 2},
groups = {flammable = 2}
})
minetest.register_craft({
@ -111,7 +111,7 @@ minetest.register_craft({
recipe = {
{"default:stone", "default:stone", "default:stone"},
{"default:stone", "default:goldblock", "default:stone"},
{"default:stone", "default:stone", "default:stone"},
{"default:stone", "default:stone", "default:stone"}
}
})
@ -119,7 +119,7 @@ minetest.register_craft({
minetest.register_craftitem("mobs:saddle", {
description = S("Saddle"),
inventory_image = "mobs_saddle.png",
groups = {flammable = 2},
groups = {flammable = 2}
})
minetest.register_craft({
@ -127,7 +127,7 @@ minetest.register_craft({
recipe = {
{"mobs:leather", "mobs:leather", "mobs:leather"},
{"mobs:leather", "default:steel_ingot", "mobs:leather"},
{"mobs:leather", "default:steel_ingot", "mobs:leather"},
{"mobs:leather", "default:steel_ingot", "mobs:leather"}
}
})
@ -142,38 +142,38 @@ default.register_fence("mobs:fence_wood", {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 1.9, 0.5},
},
},
}
}
})
-- mob fence top (has enlarged collisionbox to stop mobs getting over)
minetest.register_node("mobs:fence_top", {
description = S("Mob Fence Top"),
drawtype = "nodebox",
tiles = {"default_wood.png"},
paramtype = "light",
is_ground_content = false,
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2},
},
collision_box = {
type = "fixed",
fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4},
},
selection_box = {
type = "fixed",
fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4},
},
minetest.register_node("mobs:fence_top", {
description = S("Mob Fence Top"),
drawtype = "nodebox",
tiles = {"default_wood.png"},
paramtype = "light",
is_ground_content = false,
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 2},
sounds = default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = {-0.2, -0.5, -0.2, 0.2, 0, 0.2}
},
collision_box = {
type = "fixed",
fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4}
},
selection_box = {
type = "fixed",
fixed = {-0.4, -1.5, -0.4, 0.4, 0, 0.4}
}
})
minetest.register_craft({
output = "mobs:fence_top 12",
recipe = {
{"group:wood", "group:wood", "group:wood"},
{"", "default:fence_wood", ""},
{"", "default:fence_wood", ""}
}
})
@ -181,43 +181,43 @@ minetest.register_craft({
minetest.register_craft({
type = "fuel",
recipe = "mobs:nametag",
burntime = 3,
burntime = 3
})
minetest.register_craft({
type = "fuel",
recipe = "mobs:lasso",
burntime = 7,
burntime = 7
})
minetest.register_craft({
type = "fuel",
recipe = "mobs:net",
burntime = 8,
burntime = 8
})
minetest.register_craft({
type = "fuel",
recipe = "mobs:leather",
burntime = 4,
burntime = 4
})
minetest.register_craft({
type = "fuel",
recipe = "mobs:saddle",
burntime = 7,
burntime = 7
})
minetest.register_craft({
type = "fuel",
recipe = "mobs:fence_wood",
burntime = 7,
burntime = 7
})
minetest.register_craft({
type = "fuel",
recipe = "mobs:fence_top",
burntime = 2,
burntime = 2
})
-- this tool spawns same mob and adds owner, protected, nametag info
@ -284,7 +284,7 @@ minetest.register_tool(":mobs:mob_reset_stick", {
.. "button_exit[2.5,3.5;3,1;mob_texture_change;"
.. minetest.formspec_escape(S("Change")) .. "]")
end
end,
end
})
minetest.register_on_player_receive_fields(function(player, formname, fields)

View File

@ -13,6 +13,6 @@ if minetest.get_modpath("lucky_block") then
{"dro", {"mobs:protector"}, 1},
{"dro", {"mobs:fence_wood"}, 10},
{"dro", {"mobs:fence_top"}, 12},
{"lig"},
{"lig"}
})
end

View File

@ -212,7 +212,8 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
end
-- fix mob rotation
entity.object:set_yaw(entity.driver:get_look_horizontal() - entity.rotate)
local horz = entity.driver:get_look_horizontal() or 0
entity.object:set_yaw(horz - entity.rotate)
if can_fly then
@ -246,7 +247,6 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
acce_y = acce_y + (acce_y * 3) + 1
end
end
end
end
@ -259,7 +259,7 @@ function mobs.drive(entity, moving_anim, stand_anim, can_fly, dtime)
return
end
-- set moving animation
if moving_anim then
mobs:set_animation(entity, moving_anim)

View File

@ -23,7 +23,7 @@ Lucky Blocks: 9
Changelog:
- 1.50 - Added new line_of_sight function that uses raycasting if mt5.0 is found (thanks Astrobe)
- 1.50 - Added new line_of_sight function that uses raycasting if mt5.0 is found (thanks Astrobe), dont spawn mobs if world anchor nearby (technic or simple_anchor mods)
- 1.49- Added mobs:force_capture(self, player) function, api functions now use metatables thanks to bell07
- 1.48- Add mobs:set_velocity(self, velocity) global function
- 1.47- Mob damage changes, min and max light level for damage added, ignition sources checked for lava damage

View File

@ -68,7 +68,7 @@ minetest.register_node("mobs:spawner", {
minetest.chat_send_player(name,
S("Syntax: “name min_light[0-14] max_light[0-14] max_mobs_in_area[0 to disable] distance[1-20] y_offset[-10 to 10]”"))
end
end,
end
})
@ -174,6 +174,5 @@ minetest.register_abm({
minetest.add_entity(pos2, mob)
end
end
end
})