mirror of
https://github.com/ElCeejo/creatura.git
synced 2025-04-30 13:51:41 -04:00
Add creatura.register_spawn_item
This commit is contained in:
parent
962ea68104
commit
a7af111180
1 changed files with 261 additions and 228 deletions
35
spawning.lua
35
spawning.lua
|
@ -26,6 +26,8 @@ end
|
|||
|
||||
-- Registration --
|
||||
|
||||
local creative = minetest.settings:get_bool("creative_mode")
|
||||
|
||||
local function format_name(str)
|
||||
if str then
|
||||
if str:match(":") then str = str:split(":")[2] end
|
||||
|
@ -33,7 +35,7 @@ local function format_name(str)
|
|||
end
|
||||
end
|
||||
|
||||
function creatura.register_spawn_egg(name, col1, col2, inventory_image)
|
||||
function creatura.register_spawn_egg(name, col1, col2, inventory_image) -- deprecated
|
||||
if col1 and col2 then
|
||||
local base = "(creatura_spawning_crystal.png^[multiply:#" .. col1 .. ")"
|
||||
local spots = "(creatura_spawning_crystal_overlay.png^[multiply:#" .. col2 .. ")"
|
||||
|
@ -63,6 +65,37 @@ function creatura.register_spawn_egg(name, col1, col2, inventory_image)
|
|||
})
|
||||
end
|
||||
|
||||
function creatura.register_spawn_item(name, def)
|
||||
if not def.inventory_image
|
||||
and def.col1 and def.col2 then
|
||||
local base = "(creatura_spawning_crystal.png^[multiply:#" .. def.col1 .. ")"
|
||||
local spots = "(creatura_spawning_crystal_overlay.png^[multiply:#" .. def.col2 .. ")"
|
||||
inventory_image = base .. "^" .. spots
|
||||
end
|
||||
local mod_name = name:split(":")[1]
|
||||
local mob_name = name:split(":")[2]
|
||||
minetest.register_craftitem(mod_name .. ":spawn_" .. mob_name, {
|
||||
description = def.description or "Spawn " .. format_name(name),
|
||||
inventory_image = def.inventory_image or inventory_image,
|
||||
stack_max = 99,
|
||||
on_place = function(itemstack, _, pointed_thing)
|
||||
local mobdef = minetest.registered_entities[name]
|
||||
local spawn_offset = math.abs(mobdef.collisionbox[2])
|
||||
local pos = minetest.get_pointed_thing_position(pointed_thing, true)
|
||||
pos.y = (pos.y - 0.49) + spawn_offset
|
||||
local object = minetest.add_entity(pos, name)
|
||||
if object then
|
||||
object:set_yaw(math.random(1, 6))
|
||||
object:get_luaentity().last_yaw = object:get_yaw()
|
||||
end
|
||||
if not creative then
|
||||
itemstack:take_item()
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
function creatura.register_mob_spawn(name, def)
|
||||
local spawn = {
|
||||
chance = def.chance or 5,
|
||||
|
|
Loading…
Add table
Reference in a new issue