Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c30e5b6947 | ||
|
92a065b591 | ||
|
af812515bb |
12
api.lua
Normal file
12
api.lua
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
local utils = ...
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- function (spawn_pos, itemstack, owner, spawner_pos, spawner_dir)
|
||||||
|
function lwcomponents.register_spawner (itemname, spawn_func)
|
||||||
|
return utils.register_spawner (itemname, spawn_func)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--
|
@@ -26,3 +26,8 @@ v0.1.3
|
|||||||
|
|
||||||
v0.1.4
|
v0.1.4
|
||||||
* Bug fix to spawning owned mobs.
|
* Bug fix to spawning owned mobs.
|
||||||
|
|
||||||
|
|
||||||
|
v0.1.5
|
||||||
|
* Added setting Spawn mobs.
|
||||||
|
* Added lwcomponents.register_spawner api.
|
||||||
|
@@ -7,6 +7,22 @@ if utils.digilines_supported or utils.mesecon_supported then
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local function dispense_dir (node)
|
||||||
|
if node.param2 == 0 then
|
||||||
|
return { x = 0, y = 0, z = -1 }
|
||||||
|
elseif node.param2 == 1 then
|
||||||
|
return { x = -1, y = 0, z = 0 }
|
||||||
|
elseif node.param2 == 2 then
|
||||||
|
return { x = 0, y = 0, z = 1 }
|
||||||
|
elseif node.param2 == 3 then
|
||||||
|
return { x = 1, y = 0, z = 0 }
|
||||||
|
else
|
||||||
|
return { x = 0, y = 0, z = 0 }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function dispense_pos (pos, node)
|
local function dispense_pos (pos, node)
|
||||||
if node.param2 == 0 then
|
if node.param2 == 0 then
|
||||||
return { x = pos.x, y = pos.y, z = pos.z - 1 }
|
return { x = pos.x, y = pos.y, z = pos.z - 1 }
|
||||||
@@ -64,8 +80,8 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function try_spawn (pos, node, item)
|
local function try_spawn (pos, node, item, owner)
|
||||||
if utils.mobs_supported then
|
if utils.mobs_supported and utils.settings.spawn_mobs then
|
||||||
local mob = item:get_name ()
|
local mob = item:get_name ()
|
||||||
local item_def = minetest.registered_craftitems[mob]
|
local item_def = minetest.registered_craftitems[mob]
|
||||||
local spawn_pos = dispense_pos (pos, node)
|
local spawn_pos = dispense_pos (pos, node)
|
||||||
@@ -80,16 +96,10 @@ local function try_spawn (pos, node, item)
|
|||||||
local ent = smob and smob:get_luaentity ()
|
local ent = smob and smob:get_luaentity ()
|
||||||
|
|
||||||
if ent then
|
if ent then
|
||||||
local meta = minetest.get_meta (pos)
|
-- set owner if not a monster
|
||||||
|
if owner:len () > 0 and ent.type ~= "monster" then
|
||||||
if meta then
|
ent.owner = owner
|
||||||
local owner = meta:get_string ("owner")
|
ent.tamed = true
|
||||||
|
|
||||||
-- set owner if not a monster
|
|
||||||
if owner:len () > 0 and ent.type ~= "monster" then
|
|
||||||
ent.owner = owner
|
|
||||||
ent.tamed = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -102,16 +112,10 @@ local function try_spawn (pos, node, item)
|
|||||||
local ent = smob and smob:get_luaentity ()
|
local ent = smob and smob:get_luaentity ()
|
||||||
|
|
||||||
if ent then
|
if ent then
|
||||||
local meta = minetest.get_meta (pos)
|
-- set owner if not a monster
|
||||||
|
if owner:len () > 0 and ent.type ~= "monster" then
|
||||||
if meta then
|
ent.owner = owner
|
||||||
local owner = meta:get_string ("owner")
|
ent.tamed = true
|
||||||
|
|
||||||
-- set owner if not a monster
|
|
||||||
if owner:len () > 0 and ent.type ~= "monster" then
|
|
||||||
ent.owner = owner
|
|
||||||
ent.tamed = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -126,16 +130,10 @@ local function try_spawn (pos, node, item)
|
|||||||
local ent = smob and smob:get_luaentity ()
|
local ent = smob and smob:get_luaentity ()
|
||||||
|
|
||||||
if ent then
|
if ent then
|
||||||
local meta = minetest.get_meta (pos)
|
-- set owner if not a monster
|
||||||
|
if owner:len () > 0 and ent.type ~= "monster" then
|
||||||
if meta then
|
ent.owner = owner
|
||||||
local owner = meta:get_string ("owner")
|
ent.tamed = true
|
||||||
|
|
||||||
-- set owner if not a monster
|
|
||||||
if owner:len () > 0 and ent.type ~= "monster" then
|
|
||||||
ent.owner = owner
|
|
||||||
ent.tamed = true
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -148,6 +146,7 @@ local function try_spawn (pos, node, item)
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-- slot:
|
-- slot:
|
||||||
-- nil - next item, no dispense if empty
|
-- nil - next item, no dispense if empty
|
||||||
-- number - 1 item from slot, no dispense if empty
|
-- number - 1 item from slot, no dispense if empty
|
||||||
@@ -202,11 +201,26 @@ local function dispense_item (pos, node, slot)
|
|||||||
|
|
||||||
if item then
|
if item then
|
||||||
item:set_count (1)
|
item:set_count (1)
|
||||||
|
local spawn_pos = dispense_pos (pos, node)
|
||||||
|
local owner = meta:get_string ("owner")
|
||||||
|
|
||||||
local obj = try_spawn (pos, node, item)
|
local obj, cancel = utils.spawn_registered (name,
|
||||||
|
spawn_pos,
|
||||||
|
item,
|
||||||
|
owner,
|
||||||
|
pos,
|
||||||
|
dispense_dir (node))
|
||||||
|
|
||||||
|
if obj == nil and cancel then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
if not obj then
|
if not obj then
|
||||||
obj = minetest.add_item (dispense_pos (pos, node), item)
|
obj = try_spawn (pos, node, item, owner)
|
||||||
|
end
|
||||||
|
|
||||||
|
if not obj then
|
||||||
|
obj = minetest.add_item (spawn_pos, item)
|
||||||
end
|
end
|
||||||
|
|
||||||
if obj then
|
if obj then
|
||||||
|
47
docs/api.txt
Normal file
47
docs/api.txt
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
|
||||||
|
lwcomponents.version ()
|
||||||
|
Returns this mod version as a string. eg. "0.1.5".
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
lwcomponents.register_spawner (itemname, spawn_func)
|
||||||
|
|
||||||
|
itemname:
|
||||||
|
Registered string name of the spawner item
|
||||||
|
|
||||||
|
spawn_func:
|
||||||
|
The function to call to spawn the mob of the form -
|
||||||
|
|
||||||
|
spawn_func (spawn_pos, itemstack, owner, spawner_pos, spawner_dir)
|
||||||
|
|
||||||
|
spawn_pos:
|
||||||
|
The position the entity should be spawned at.
|
||||||
|
|
||||||
|
itemstack:
|
||||||
|
The spawner ItemStack, of the name itemname.
|
||||||
|
|
||||||
|
owner:
|
||||||
|
As string of the player's name that will own the spawned entity,
|
||||||
|
if applicable. This may be "" for no owner.
|
||||||
|
|
||||||
|
spawner_pos:
|
||||||
|
The position of the block calling this function.
|
||||||
|
|
||||||
|
spawner_dir:
|
||||||
|
A single unit vector of the direction the spawner block is facing.
|
||||||
|
eg. { x = -1, y = 0, z = 0 }
|
||||||
|
|
||||||
|
This function should return the ObjectRef of the spawned entity or
|
||||||
|
nil. If this function returns nil for ObjectRef a second boolean
|
||||||
|
value should be returned for weather to cancel the action.
|
||||||
|
|
||||||
|
eg. If too many mobs:
|
||||||
|
return nil, true
|
||||||
|
|
||||||
|
eg. If only chance of spawn and out of luck:
|
||||||
|
return nil, false
|
||||||
|
|
||||||
|
The register function return true on success, or false on failure
|
||||||
|
(parameter type check failed or the spawn item has already been
|
||||||
|
registered).
|
4
init.lua
4
init.lua
@@ -1,4 +1,4 @@
|
|||||||
local version = "0.1.4"
|
local version = "0.1.5"
|
||||||
local mod_storage = minetest.get_mod_storage ()
|
local mod_storage = minetest.get_mod_storage ()
|
||||||
|
|
||||||
|
|
||||||
@@ -16,6 +16,8 @@ local utils = { }
|
|||||||
local modpath = minetest.get_modpath ("lwcomponents")
|
local modpath = minetest.get_modpath ("lwcomponents")
|
||||||
|
|
||||||
loadfile (modpath.."/utils.lua") (utils, mod_storage)
|
loadfile (modpath.."/utils.lua") (utils, mod_storage)
|
||||||
|
loadfile (modpath.."/settings.lua") (utils)
|
||||||
|
loadfile (modpath.."/api.lua") (utils)
|
||||||
loadfile (modpath.."/dropper.lua") (utils)
|
loadfile (modpath.."/dropper.lua") (utils)
|
||||||
loadfile (modpath.."/collector.lua") (utils)
|
loadfile (modpath.."/collector.lua") (utils)
|
||||||
loadfile (modpath.."/dispenser.lua") (utils)
|
loadfile (modpath.."/dispenser.lua") (utils)
|
||||||
|
12
readme.txt
12
readme.txt
@@ -13,7 +13,7 @@ CC BY-SA 3.0
|
|||||||
|
|
||||||
Version
|
Version
|
||||||
=======
|
=======
|
||||||
0.1.4
|
0.1.5
|
||||||
|
|
||||||
|
|
||||||
Minetest Version
|
Minetest Version
|
||||||
@@ -103,11 +103,11 @@ Contains an inventory and dispenses (with velocity) an item on command.
|
|||||||
Also acts as a digilines conductor. If the hopper mod is loaded, will take
|
Also acts as a digilines conductor. If the hopper mod is loaded, will take
|
||||||
items from the top and sides, and release them from the bottom.
|
items from the top and sides, and release them from the bottom.
|
||||||
|
|
||||||
Dispensers support mobs mod if loaded. Will spawn the entity from an 'egg'
|
Dispensers support mobs mod if loaded and Spawn mobs setting is enabled.
|
||||||
if possible, or the 'egg' is dispensed. If a chicken egg is dispensed a
|
Will spawn the entity from an 'egg' if possible, or the 'egg' is dispensed.
|
||||||
10% chance a chicken is dispensed instead. If the spawned entity can be
|
If a chicken egg is dispensed a 10% chance a chicken is dispensed instead.
|
||||||
owned (or tamed) and the dispenser is owned the owner of the dispenser is
|
If the spawned entity can be owned (or tamed) and the dispenser is owned
|
||||||
set as the owner of the entity.
|
the owner of the dispenser is set as the owner of the entity.
|
||||||
|
|
||||||
UI
|
UI
|
||||||
|
|
||||||
|
11
settings.lua
Normal file
11
settings.lua
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
local utils = ...
|
||||||
|
|
||||||
|
|
||||||
|
utils.settings = { }
|
||||||
|
|
||||||
|
utils.settings.spawn_mobs =
|
||||||
|
minetest.settings:get_bool ("lwcomponents_spawn_mobs", true)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
--
|
2
settingtypes.txt
Normal file
2
settingtypes.txt
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
# Allow dispensers to spawn mobs instead of spawners.
|
||||||
|
lwcomponents_spawn_mobs (Spawn mobs) bool true
|
39
utils.lua
39
utils.lua
@@ -171,4 +171,43 @@ end
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
utils.registered_spawners = { }
|
||||||
|
-- each entry [spawner_itemname] = spawner_func
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function utils.register_spawner (itemname, spawn_func)
|
||||||
|
if type (itemname) == "string" and type (spawn_func) == "function" then
|
||||||
|
if not utils.registered_spawners[itemname] then
|
||||||
|
utils.registered_spawners[itemname] = spawn_func
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
function utils.spawn_registered (itemname, spawn_pos, itemstack, owner, spawner_pos, spawner_dir)
|
||||||
|
local func = utils.registered_spawners[itemname]
|
||||||
|
|
||||||
|
if func then
|
||||||
|
local result, obj, cancel = pcall (func, spawn_pos, itemstack, owner, spawner_pos, spawner_dir)
|
||||||
|
|
||||||
|
if result and (obj == nil or type (obj) == "userdata") then
|
||||||
|
return obj, cancel
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.log ("error", "lwcomponents.register_spawner spawner function for "..itemname.." failed")
|
||||||
|
|
||||||
|
return nil, true
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil, false
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
|
Reference in New Issue
Block a user