Add files via upload
parent
785c692960
commit
9ca1d9ab72
|
@ -0,0 +1,3 @@
|
|||
|
||||
v 0.1.0
|
||||
* initial release
|
|
@ -0,0 +1,3 @@
|
|||
lwcomponents
|
||||
mobs?
|
||||
projectile?
|
|
@ -0,0 +1 @@
|
|||
Register spawners for lwcomponents.
|
|
@ -0,0 +1,23 @@
|
|||
local version = "0.1.0"
|
||||
|
||||
|
||||
|
||||
lwcomponents_spawners = { }
|
||||
|
||||
|
||||
|
||||
function lwcomponents_spawners.version ()
|
||||
return version
|
||||
end
|
||||
|
||||
|
||||
local utils = { }
|
||||
local modpath = minetest.get_modpath ("lwcomponents_spawners")
|
||||
|
||||
loadfile (modpath.."/settings.lua") (utils)
|
||||
loadfile (modpath.."/mobs.lua") (utils)
|
||||
loadfile (modpath.."/projectile.lua") (utils)
|
||||
|
||||
|
||||
|
||||
--
|
|
@ -0,0 +1,14 @@
|
|||
Source code license
|
||||
-------------------
|
||||
|
||||
GNU Lesser General Public License, version 2.1
|
||||
Copyright (C) 2021 loosewheel
|
||||
|
||||
This program is free software; you can redistribute it and/or modify it under the terms
|
||||
of the GNU Lesser General Public License as published by the Free Software Foundation;
|
||||
either version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU Lesser General Public License for more details:
|
||||
https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
|
|
@ -0,0 +1,137 @@
|
|||
local utils = ...
|
||||
|
||||
|
||||
|
||||
if minetest.global_exists ("mobs") then
|
||||
|
||||
|
||||
|
||||
local function register_spawner (mob)
|
||||
|
||||
lwcomponents.register_spawner (mob .. "_set",
|
||||
function (spawn_pos, itemstack, owner, spawner_pos, spawner_dir, force)
|
||||
if minetest.registered_entities[mob] then
|
||||
local data = itemstack:get_metadata ()
|
||||
local smob = minetest.add_entity (spawn_pos, mob, data)
|
||||
|
||||
if smob then
|
||||
local ent = smob:get_luaentity ()
|
||||
|
||||
if ent then
|
||||
-- set owner if not a monster
|
||||
if owner:len () > 0 and ent.type ~= "monster" then
|
||||
ent.owner = owner
|
||||
ent.tamed = true
|
||||
end
|
||||
end
|
||||
|
||||
smob:set_velocity (vector.multiply (spawner_dir, force))
|
||||
end
|
||||
|
||||
return smob, false
|
||||
end
|
||||
|
||||
return nil, false
|
||||
end)
|
||||
|
||||
|
||||
|
||||
lwcomponents.register_spawner (mob,
|
||||
function (spawn_pos, itemstack, owner, spawner_pos, spawner_dir, force)
|
||||
if minetest.registered_entities[mob] then
|
||||
local smob = minetest.add_entity (spawner_pos, mob)
|
||||
|
||||
if smob then
|
||||
local ent = smob:get_luaentity ()
|
||||
|
||||
if ent then
|
||||
-- set owner if not a monster
|
||||
if owner:len () > 0 and ent.type ~= "monster" then
|
||||
ent.owner = owner
|
||||
ent.tamed = true
|
||||
end
|
||||
end
|
||||
|
||||
smob:set_velocity (vector.multiply (spawner_dir, force))
|
||||
end
|
||||
|
||||
return smob, false
|
||||
end
|
||||
|
||||
return nil, false
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
for mob, def in pairs (minetest.registered_craftitems) do
|
||||
if def and def.groups and def.groups.spawn_egg then
|
||||
register_spawner (mob)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
--[[ doesn't spawn if thrown against wall and kills chickens when hit
|
||||
lwcomponents.register_spawner ("mobs:egg",
|
||||
function (spawn_pos, itemstack, owner, spawner_pos, spawner_dir)
|
||||
if minetest.registered_entities["mobs_animal:egg_entity"] then
|
||||
local obj = minetest.add_entity (spawn_pos, "mobs_animal:egg_entity")
|
||||
local ent = obj and obj:get_luaentity ()
|
||||
|
||||
if ent then
|
||||
ent.velocity = 25 -- needed for api internal timing
|
||||
ent.switch = 1 -- needed so that egg doesn't despawn straight away
|
||||
ent._is_arrow = true -- tell advanced mob protection this is an arrow
|
||||
|
||||
obj:setacceleration({
|
||||
x = spawner_dir.x * -3,
|
||||
y = -9, -- egg_GRAVITY,
|
||||
z = spawner_dir.z * -3
|
||||
})
|
||||
|
||||
-- set owner
|
||||
if owner:len () > 0 then
|
||||
ent.playername = owner
|
||||
end
|
||||
|
||||
return obj, false
|
||||
end
|
||||
end
|
||||
|
||||
return nil, false
|
||||
end)
|
||||
]]
|
||||
|
||||
|
||||
|
||||
lwcomponents.register_spawner ("mobs:egg",
|
||||
function (spawn_pos, itemstack, owner, spawner_pos, spawner_dir, force)
|
||||
if math.random (1, 10) == 5 then
|
||||
if minetest.registered_entities["mobs_animal:chicken"] then
|
||||
local smob = minetest.add_entity (spawn_pos, "mobs_animal:chicken")
|
||||
|
||||
if smob then
|
||||
local ent = smob:get_luaentity ()
|
||||
|
||||
if ent then
|
||||
-- set owner if not a monster
|
||||
if owner:len () > 0 and ent.type ~= "monster" then
|
||||
ent.owner = owner
|
||||
ent.tamed = true
|
||||
end
|
||||
end
|
||||
|
||||
smob:set_velocity (vector.multiply (spawner_dir, force))
|
||||
end
|
||||
|
||||
return smob, false
|
||||
end
|
||||
end
|
||||
|
||||
return nil, false
|
||||
end)
|
||||
|
||||
|
||||
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
author = loosewheel
|
||||
description = Register spawners for lwcomponents.
|
||||
title = LWComponents Spawners
|
||||
name = lwcomponents_spawners
|
||||
depends = lwcomponents
|
||||
optional_depends = mobs, projectile
|
|
@ -0,0 +1,76 @@
|
|||
local utils = ...
|
||||
|
||||
|
||||
|
||||
if minetest.global_exists ("projectile") then
|
||||
|
||||
|
||||
|
||||
local function shoot (spawn_pos, itemstack, owner, spawner_pos, spawner_dir, force, catagory)
|
||||
local pos = spawn_pos
|
||||
local level = 1
|
||||
local ammo_entity = projectile.registered_projectiles[catagory][itemstack:get_name ()]
|
||||
|
||||
if not itemstack:is_empty() and ammo_entity then
|
||||
local adef = minetest.registered_entities[ammo_entity]
|
||||
|
||||
-- Fire an amount of projectiles at once according to the ammo's defined "count".
|
||||
for n = 1, (adef.count or 1) do
|
||||
local projectile = minetest.add_entity (pos, ammo_entity)
|
||||
local luapro = projectile:get_luaentity()
|
||||
|
||||
-- Set velocity according to the direction it was fired.
|
||||
-- Speed is determined by the ammo. No weapon and always fully charged.
|
||||
projectile:set_velocity(vector.multiply (spawner_dir, luapro.speed))
|
||||
-- An acceleration of -9.81y is how gravity is applied.
|
||||
projectile:set_acceleration ({ x = 0, y = -9.81, z = 0 })
|
||||
|
||||
--If the ammo defines a spread, randomly rotate the direction of velocity by that given radius.
|
||||
if adef.spread then
|
||||
local rx = (math.random() * adef.spread * 2 - adef.spread) * math.pi / 180
|
||||
local ry = (math.random() * adef.spread * 2 - adef.spread) * math.pi / 180
|
||||
|
||||
projectile:set_velocity(vector.rotate(projectile:get_velocity(), {x = rx, y = ry, z = 0}))
|
||||
end
|
||||
|
||||
-- Store level for later, to determine impact damage
|
||||
luapro.level = level
|
||||
-- Also store the projectile's damage itself.
|
||||
luapro.damage = adef.damage
|
||||
-- The player's name is stored to prevent hitting yourself
|
||||
-- And by "hitting yourself" I mean accidentally being hit by the arrow just by firing it at a
|
||||
-- somewhat low angle, the moment it spawns.
|
||||
luapro.owner = owner
|
||||
-- Store the initial velocity for passing by objects when needed.
|
||||
luapro.oldvel = projectile:get_velocity()
|
||||
end
|
||||
|
||||
return projectile, false
|
||||
end
|
||||
|
||||
return nil, false
|
||||
end
|
||||
|
||||
|
||||
|
||||
local function register_spawner (ammo, catagory)
|
||||
|
||||
lwcomponents.register_spawner (ammo,
|
||||
function (spawn_pos, itemstack, owner, spawner_pos, spawner_dir, force)
|
||||
return shoot (spawn_pos, itemstack, owner, spawner_pos, spawner_dir, force, catagory)
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
|
||||
for weapon, def in pairs (projectile.registered_projectiles) do
|
||||
for ammo, def in pairs (projectile.registered_projectiles[weapon]) do
|
||||
if def then
|
||||
register_spawner (ammo, weapon)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
|
@ -0,0 +1,51 @@
|
|||
LWComponents Spawners
|
||||
by loosewheel
|
||||
|
||||
|
||||
Licence
|
||||
=======
|
||||
Code licence:
|
||||
LGPL 2.1
|
||||
|
||||
|
||||
Version
|
||||
=======
|
||||
0.1.0
|
||||
|
||||
|
||||
Minetest Version
|
||||
================
|
||||
This mod was developed on version 5.4.0
|
||||
|
||||
|
||||
Dependencies
|
||||
============
|
||||
lwcomponents
|
||||
|
||||
|
||||
Optional Dependencies
|
||||
=====================
|
||||
mobs
|
||||
|
||||
|
||||
Installation
|
||||
============
|
||||
Copy the 'lwcomponents_spawners' folder to your mods folder.
|
||||
|
||||
|
||||
Bug Report
|
||||
==========
|
||||
https://forum.minetest.net/viewtopic.php?f=9&t=27425
|
||||
|
||||
|
||||
Description
|
||||
===========
|
||||
Register spawners for lwcomponents for the following:
|
||||
|
||||
* Mobs - all spawn eggs and 10% chance of chicken spawning when egg is
|
||||
thrown.
|
||||
* Projectiles - all projectiles.
|
||||
|
||||
|
||||
|
||||
------------------------------------------------------------------------
|
|
@ -0,0 +1,8 @@
|
|||
local utils = ...
|
||||
|
||||
|
||||
utils.settings = { }
|
||||
|
||||
|
||||
|
||||
--
|
Loading…
Reference in New Issue