mirror of
https://codeberg.org/tenplus1/mobs_redo.git
synced 2025-01-11 18:30:21 +01:00
added arrow rotation, added new mob eggs that save mob information, updated intllib routine
This commit is contained in:
parent
4e231429d9
commit
e3515482cc
97
api.lua
97
api.lua
@ -1,5 +1,5 @@
|
|||||||
|
|
||||||
-- Mobs Api (20th January 2017)
|
-- Mobs Api (21st January 2017)
|
||||||
|
|
||||||
mobs = {}
|
mobs = {}
|
||||||
mobs.mod = "redo"
|
mobs.mod = "redo"
|
||||||
@ -7,24 +7,18 @@ mobs.mod = "redo"
|
|||||||
|
|
||||||
-- Intllib
|
-- Intllib
|
||||||
local S
|
local S
|
||||||
|
|
||||||
if minetest.get_modpath("intllib") then
|
if minetest.get_modpath("intllib") then
|
||||||
S = intllib.Getter()
|
S = intllib.Getter()
|
||||||
else
|
else
|
||||||
S = function(s, a, ...)
|
S = function(s, a, ...) a = {a, ...}
|
||||||
if a == nil then
|
return s:gsub("@(%d+)", function(n)
|
||||||
return s
|
return a[tonumber(n)]
|
||||||
end
|
end)
|
||||||
a = {a, ...}
|
|
||||||
return s:gsub("(@?)@(%(?)(%d+)(%)?)",
|
|
||||||
function(e, o, n, c)
|
|
||||||
if e == "" then
|
|
||||||
return a[tonumber(n)] .. (o == "" and c or "")
|
|
||||||
else
|
|
||||||
return "@" .. o .. n .. c
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
mobs.intllib = S
|
mobs.intllib = S
|
||||||
|
|
||||||
|
|
||||||
@ -2868,6 +2862,9 @@ function mobs:register_arrow(name, def)
|
|||||||
timer = 0,
|
timer = 0,
|
||||||
switch = 0,
|
switch = 0,
|
||||||
owner_id = def.owner_id,
|
owner_id = def.owner_id,
|
||||||
|
rotate = def.rotate,
|
||||||
|
automatic_face_movement_dir = def.rotate
|
||||||
|
and (def.rotate - (pi / 180)) or false,
|
||||||
|
|
||||||
on_step = def.on_step or function(self, dtime)
|
on_step = def.on_step or function(self, dtime)
|
||||||
|
|
||||||
@ -3027,6 +3024,56 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
|
|||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- spawn egg containing mob information
|
||||||
|
minetest.register_craftitem(mob .. "_set", {
|
||||||
|
|
||||||
|
description = desc .. " (set)",
|
||||||
|
inventory_image = invimg,
|
||||||
|
groups = {not_in_creative_inventory = 1},
|
||||||
|
stack_max = 1,
|
||||||
|
|
||||||
|
on_place = function(itemstack, placer, pointed_thing)
|
||||||
|
|
||||||
|
local pos = pointed_thing.above
|
||||||
|
|
||||||
|
-- am I clicking on something with existing on_rightclick function?
|
||||||
|
local under = minetest.get_node(pointed_thing.under)
|
||||||
|
local def = minetest.registered_nodes[under.name]
|
||||||
|
if def and def.on_rightclick then
|
||||||
|
return def.on_rightclick(pointed_thing.under, under, placer, itemstack)
|
||||||
|
end
|
||||||
|
|
||||||
|
if pos
|
||||||
|
and within_limits(pos, 0)
|
||||||
|
and not minetest.is_protected(pos, placer:get_player_name()) then
|
||||||
|
|
||||||
|
pos.y = pos.y + 1
|
||||||
|
|
||||||
|
local data = itemstack:get_metadata()
|
||||||
|
local mob = minetest.add_entity(pos, mob, data)
|
||||||
|
local ent = mob:get_luaentity()
|
||||||
|
|
||||||
|
if not ent then
|
||||||
|
mob:remove()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if ent.type ~= "monster" then
|
||||||
|
-- set owner and tame if not monster
|
||||||
|
ent.owner = placer:get_player_name()
|
||||||
|
ent.tamed = true
|
||||||
|
end
|
||||||
|
|
||||||
|
-- if not in creative then take item
|
||||||
|
if not creative then
|
||||||
|
itemstack:take_item()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return itemstack
|
||||||
|
end,
|
||||||
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -3097,7 +3144,27 @@ function mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso,
|
|||||||
-- calculate chance.. add to inventory if successful?
|
-- calculate chance.. add to inventory if successful?
|
||||||
if random(1, 100) <= chance then
|
if random(1, 100) <= chance then
|
||||||
|
|
||||||
clicker:get_inventory():add_item("main", mobname)
|
-- add special mob egg containing all mob information
|
||||||
|
local new_stack = ItemStack(mobname .. "_set")
|
||||||
|
local tmp = {}
|
||||||
|
for _,stat in pairs(self) do
|
||||||
|
local t = type(stat)
|
||||||
|
if t ~= 'function'
|
||||||
|
and t ~= 'nil'
|
||||||
|
and t ~= 'userdata' then
|
||||||
|
tmp[_] = self[_]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local data_str = minetest.serialize(tmp)
|
||||||
|
local inv = clicker:get_inventory()
|
||||||
|
new_stack:set_metadata(data_str)
|
||||||
|
if inv:room_for_item("main", new_stack) then
|
||||||
|
inv:add_item("main", new_stack)
|
||||||
|
else
|
||||||
|
minetest.add_item(clicker:getpos(), new_stack)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- clicker:get_inventory():add_item("main", mobname)
|
||||||
|
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
else
|
else
|
||||||
|
1
api.txt
1
api.txt
@ -196,6 +196,7 @@ This function registers a arrow for mobs with the attack type shoot.
|
|||||||
'tail_size' has size for above texture (defaults to between 5 and 10)
|
'tail_size' has size for above texture (defaults to between 5 and 10)
|
||||||
'expire' contains float value for how long tail appears for (defaults to 0.25)
|
'expire' contains float value for how long tail appears for (defaults to 0.25)
|
||||||
'glow' has value for how brightly tail glows 1 to 10 (default is 0, no glow)
|
'glow' has value for how brightly tail glows 1 to 10 (default is 0, no glow)
|
||||||
|
'rotate' integer value in degrees to rotate arrow
|
||||||
'on_step' is a custom function when arrow is active, nil for default.
|
'on_step' is a custom function when arrow is active, nil for default.
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ minetest.register_craft({
|
|||||||
cooktime = 5,
|
cooktime = 5,
|
||||||
})
|
})
|
||||||
|
|
||||||
-- golden lasso
|
-- magic lasso
|
||||||
minetest.register_tool("mobs:magic_lasso", {
|
minetest.register_tool("mobs:magic_lasso", {
|
||||||
description = S("Magic Lasso (right-click animal to put in inventory)"),
|
description = S("Magic Lasso (right-click animal to put in inventory)"),
|
||||||
inventory_image = "mobs_magic_lasso.png",
|
inventory_image = "mobs_magic_lasso.png",
|
||||||
|
Loading…
Reference in New Issue
Block a user