Make mod independent

master
Jordan Irwin 2021-05-05 04:45:32 -07:00
parent 63efe313f2
commit 7d64c8b98b
7 changed files with 153 additions and 149 deletions

View File

@ -1,6 +1,6 @@
MIT License
The MIT License (MIT)
Copyright © 2017 Jordan Irwin (AntumDeluge)
Copyright © 2021 Jordan Irwin (AntumDeluge)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in

75
api.lua Normal file
View File

@ -0,0 +1,75 @@
--[[ LICENSE HEADER
The MIT License (MIT)
Copyright © 2021 Jordan Irwin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]
asm.addEggRecipe = function(name, spawn, ingredients)
if type(ingredients) == "string" then
ingredients = {ingredients,}
end
table.insert(ingredients, 1, "spawneggs:egg")
core.register_craft({
output = "spawneggs:" .. name,
type = "shapeless",
recipe = ingredients,
})
end
asm.addEgg = function(eggdef)
local img = "spawneggs_" .. eggdef.name .. ".png"
if eggdef.inventory_image then
img = eggdef.inventory_image
end
core.register_craftitem(":spawneggs:" .. eggdef.name, {
description = eggdef.name:gsub("^%l", string.upper) .. " Spawn Egg",
inventory_image = img,
on_place = function(itemstack, placer, target)
if target.type == "node" then
local pos = target.above
pos.y = pos.y + 1
local ref = core.add_entity(pos, eggdef.spawn)
if ref and placer:is_player() then
local entity = ref:get_luaentity()
-- set owner
if entity.ownable then entity.owner = placer:get_player_name() end
end
if not core.settings:get_bool("creative_mode") then
itemstack:take_item()
end
return itemstack
end
end
})
asm.addEggRecipe(name, spawn, ingredients)
-- DEBUG
asm.log("action", "Registered spawnegg for " .. spawn)
end

View File

@ -1,10 +1,2 @@
antum
spawneggs
animal_chicken?
chicken?
default?
mobs?
mobs_monster?
oerrki?
sheep?
wool?
spawneggs?

121
eggs.lua
View File

@ -1,121 +0,0 @@
--[[ LICENSE HEADER
MIT License
Copyright © 2017 Jordan Irwin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]
antum.spawneggs.addEggRecipe = function(name, spawn, ingredients)
table.insert(ingredients, 1, 'spawneggs:egg')
core.register_craft({
output = 'spawneggs:' .. name,
type = 'shapeless',
recipe = ingredients,
})
end
antum.spawneggs.addEgg = function(name, spawn, ingredients)
core.register_craftitem(':spawneggs:' .. name, {
description = name:gsub("^%l", string.upper) .. ' Spawn Egg',
inventory_image = 'spawneggs_' .. name ..'.png',
on_place = function(itemstack, placer, target)
if target.type == 'node' then
local pos = target.above
pos.y = pos.y + 1
core.add_entity(pos, spawn)
if not core.settings:get_bool('creative_mode') then
itemstack:take_item()
end
return itemstack
end
end
})
antum.spawneggs.addEggRecipe(name, spawn, ingredients)
-- DEBUG
antum.logAction('Registered spawnegg for ' .. spawn)
end
if core.get_modpath('spawneggs') then
-- Clear all spawneggs
local spawneggs_default = {
'dirt_monster', 'dungeon_master', 'oerkki', 'rat',
'sand_monster', 'sheep', 'stone_monster', 'tree_monster'
}
for I in pairs(spawneggs_default) do
core.clear_craft({
output = 'spawneggs:' .. spawneggs_default[I],
})
end
end
-- Sheep spawnegg
if core.get_modpath('sheep') and core.get_modpath('wool') then
antum.spawneggs.addEgg('sheep', 'creatures:sheep', {'group:wool'})
end
-- Oerrki spawnegg
if core.get_modpath('oerrki') and core.get_modpath('default') then
antum.spawneggs.addEgg('oerrki', 'creatures:oerrki', {'default:obsidian'})
end
-- Chicken spawnegg
if core.get_modpath('chicken') then
antum.spawneggs.addEgg('chicken', 'creatures:chicken', {'creatures:feather'})
end
-- mobs_redo monsters
if core.get_modpath('mobs_monster') and core.get_modpath('default') then
-- Dirt monster
antum.spawneggs.addEgg('dirt_monster', 'mobs_monster:dirt_monster', {'default:dirt'})
-- Dungeon master
--addLocalEgg('dungeon_master', 'mobs_monster:dungeon_master', {''}) -- needs ingredient
-- Mese monster
antum.spawneggs.addEgg('mese_monster', 'mobs_monster:mese_monster', {'default:mese'})
-- Oerkki
-- Sand monster
antum.spawneggs.addEgg('sand_monster', 'mobs_monster:sand_monster', {'default:sand'})
antum.spawneggs.addEggRecipe('sand_monster', 'mobs_monster:sand_monster', {'default:desert_sand'})
-- Spider
--antum.spawneggs.addEgg('spider', 'mobs_monster:spider', {''}) -- need ingredient & egg
-- Stone monster
--antum.spawneggs.addEgg('stone_monster', 'mobs_monster:stone_monster', {'default:stone'}) -- DISABLED: too graphic
-- Tree monster
antum.spawneggs.addEgg('tree_monster', 'mobs_monster:tree_monster', {'default:sapling'})
end

View File

@ -1,8 +1,8 @@
--[[ LICENSE HEADER
MIT License
The MIT License (MIT)
Copyright © 2017 Jordan Irwin
Copyright © 2021 Jordan Irwin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
@ -25,19 +25,35 @@
--]]
antum.spawneggs = {}
asm = {}
antum.spawneggs.modname = core.get_current_modname()
antum.spawneggs.modpath = core.get_modpath(antum.spawneggs.modname)
asm.modname = core.get_current_modname()
asm.modpath = core.get_modpath(asm.modname)
antum.loadScript('eggs')
if core.registered_items["mobs:egg"] then
core.register_craft({
output = "spawneggs:egg",
recipe = {
{"mobs:egg", "mobs:egg"},
{"mobs:egg", "mobs:egg"},
},
})
asm.log = function(lvl, msg)
if not msg then
msg = lvl
lvl = nil
end
if lvl then
core.log(lvl, "[" .. asm.modname .. "] " .. msg)
else
core.log("[" ams.modname .. "] " .. msg)
end
end
if core.global_exists("spawneggs") then
asm.log("warning", "Overwriting \"spawneggs\" global")
end
spawneggs = asm
local scripts = {
"api",
"items",
}
for _, script in ipairs(scripts) do
dofile(asm.modpath .. "/" .. script .. ".lua")
end

41
items.lua Normal file
View File

@ -0,0 +1,41 @@
--[[ LICENSE HEADER
The MIT License (MIT)
Copyright © 2021 Jordan Irwin
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--]]
core.register_craftitem(":spawneggs:egg", {
description = "Spawning Egg",
inventory_image = "spawneggs_egg.png",
}
if core.registered_items["mobs:egg"] then
core.register_craft({
output = "asm:egg",
recipe = {
{"mobs:egg", "mobs:egg"},
{"mobs:egg", "mobs:egg"},
},
})
end

View File

@ -1,5 +1,6 @@
name = antum_spawneggs
name = asm
title = Another Spawneggs Mod
author = AntumDeluge
description = Spawneggs for the Antum game
description = Spawneggs for adding entities to game.
license = MIT
version = 0.1