Browse Source

drops can now be a function, also code tidy

pull/28/head
TenPlus1 8 months ago
parent
commit
b588452dea
6 changed files with 82 additions and 84 deletions
  1. +28
    -33
      api.lua
  2. +5
    -0
      api.txt
  3. +47
    -47
      crafts.lua
  4. +1
    -1
      lucky_block.lua
  5. +0
    -1
      mount.lua
  6. +1
    -2
      spawner.lua

+ 28
- 33
api.lua View File

@@ -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
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;"


+ 5
- 0
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


+ 47
- 47
crafts.lua 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",
recipe = {
{"", "default:steel_ingot", ""},
{"", "group:stick", "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)


+ 1
- 1
lucky_block.lua 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

+ 0
- 1
mount.lua View File

@@ -247,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



+ 1
- 2
spawner.lua 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
})

Loading…
Cancel
Save