Compare commits
33 Commits
Author | SHA1 | Date | |
---|---|---|---|
63409be0ee | |||
5a5ca11ecd | |||
be54e91335 | |||
64805c5cba | |||
6fcb3ea6ac | |||
81ed2d3122 | |||
e7a194a08c | |||
3e1a298f08 | |||
53efb78c81 | |||
45f3ca4732 | |||
8bb8a49701 | |||
4d97ea6d80 | |||
f86e433680 | |||
daedd72a66 | |||
e33131a695 | |||
1638d081eb | |||
ce8269fb03 | |||
d58afdee89 | |||
2de5cfe2a2 | |||
e8dbb44db4 | |||
6c912106fb | |||
169ea1ce76 | |||
9cb4790f40 | |||
080ee17335 | |||
ad80c63682 | |||
e0e5702053 | |||
81705adbdc | |||
7245476030 | |||
45f28d18cf | |||
cad8033e34 | |||
b1c894871f | |||
f4671fb685 | |||
f11fe2ff90 |
127
api.lua
@ -3,44 +3,86 @@ local BASENAME = "microexpansion"
|
||||
|
||||
-- [function] Register Recipe
|
||||
function microexpansion.register_recipe(output, recipe)
|
||||
-- Check if disabled
|
||||
if recipe.disabled == true then
|
||||
return
|
||||
end
|
||||
|
||||
local function isint(n)
|
||||
return n==math.floor(n)
|
||||
end
|
||||
|
||||
local function getAmount()
|
||||
if isint(recipe[2][1]) then
|
||||
local q = recipe[2][1]
|
||||
recipe[2][1] = nil
|
||||
return q
|
||||
local function get_amount(_)
|
||||
if isint(recipe[_][1]) then
|
||||
return recipe[_][1]
|
||||
else return 1 end
|
||||
end
|
||||
|
||||
local function register(amount, recipe)
|
||||
minetest.register_craft({
|
||||
output = output.." "..amount,
|
||||
recipe = recipe,
|
||||
})
|
||||
end
|
||||
|
||||
local function single()
|
||||
register(getAmount(), recipe[2])
|
||||
end
|
||||
|
||||
local function multiple()
|
||||
for i, item in ipairs(recipe) do
|
||||
if i == 0 then return end
|
||||
register(getAmount(), recipe[i])
|
||||
local function get_type(_)
|
||||
if type(recipe[_][2]) == "string" then
|
||||
return recipe[_][2]
|
||||
end
|
||||
end
|
||||
|
||||
-- Check type
|
||||
if recipe[1] == "single" then single()
|
||||
elseif recipe[1] == "multiple" then multiple()
|
||||
else return microexpansion.log("invalid recipe for definition "..output..". "..dump(recipe[2])) end
|
||||
local function register(_)
|
||||
local def = {
|
||||
type = get_type(_),
|
||||
output = output.." "..tostring(get_amount(_)),
|
||||
recipe = recipe[_][3] or recipe[_][2]
|
||||
}
|
||||
minetest.register_craft(def)
|
||||
end
|
||||
|
||||
for _, i in ipairs(recipe) do
|
||||
-- Check if disabled
|
||||
if recipe.disabled == true then
|
||||
return
|
||||
end
|
||||
|
||||
register(_)
|
||||
end
|
||||
end
|
||||
|
||||
-- [function] Register oredef
|
||||
function microexpansion.register_oredef(ore, def)
|
||||
-- Check if disabled
|
||||
if def.disabled == true then
|
||||
return
|
||||
end
|
||||
|
||||
local function register(_)
|
||||
local def = def[_]
|
||||
def.ore = "microexpansion:"..ore
|
||||
minetest.register_ore(def)
|
||||
end
|
||||
|
||||
for _, i in ipairs(def) do
|
||||
-- Check if disabled
|
||||
if def.disabled == true then
|
||||
return
|
||||
end
|
||||
|
||||
register(_)
|
||||
end
|
||||
end
|
||||
|
||||
-- [local function] Choose description colour
|
||||
local function desc_colour(status, desc)
|
||||
if status == "unstable" then
|
||||
return minetest.colorize("orange", desc)
|
||||
elseif status == "no" then
|
||||
return minetest.colorize("red", desc)
|
||||
else
|
||||
return minetest.colorize("white", desc)
|
||||
end
|
||||
end
|
||||
|
||||
-- [function] Register Item
|
||||
function microexpansion.register_item(itemstring, def)
|
||||
-- Check if disabled
|
||||
if def.disabled == true then
|
||||
return
|
||||
end
|
||||
-- Set usedfor
|
||||
if def.usedfor then
|
||||
def.description = def.description .. "\n"..minetest.colorize("grey", def.usedfor)
|
||||
@ -51,6 +93,8 @@ function microexpansion.register_item(itemstring, def)
|
||||
else
|
||||
def.inventory_image = BASENAME.."_"..itemstring..".png"
|
||||
end
|
||||
-- Colour description
|
||||
def.description = desc_colour(def.status, def.description)
|
||||
|
||||
-- Register craftitem
|
||||
minetest.register_craftitem(BASENAME..":"..itemstring, def)
|
||||
@ -63,22 +107,47 @@ end
|
||||
|
||||
-- [function] Register Node
|
||||
function microexpansion.register_node(itemstring, def)
|
||||
-- Check if disabled
|
||||
if def.disabled == true then
|
||||
return
|
||||
end
|
||||
-- Set usedfor
|
||||
if def.usedfor then
|
||||
def.description = def.description .. "\n"..minetest.colorize("grey", def.usedfor)
|
||||
end
|
||||
-- Update texture
|
||||
if auto_complete ~= false then
|
||||
--if auto_complete ~= false then
|
||||
if true then
|
||||
for _,i in ipairs(def.tiles) do
|
||||
def.tiles[_] = BASENAME.."_"..i..".png"
|
||||
end
|
||||
if #def.tiles[_]:split("^") <= 1 then
|
||||
local prefix = ""
|
||||
if def.type == "ore" then
|
||||
prefix = "ore_"
|
||||
end
|
||||
|
||||
-- register craftitem
|
||||
def.tiles[_] = BASENAME.."_"..prefix..i..".png"
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Colour description
|
||||
def.description = desc_colour(def.status, def.description)
|
||||
-- Update connect_sides
|
||||
if def.connect_sides == "nobottom" then
|
||||
def.connect_sides = { "top", "front", "left", "back", "right" }
|
||||
elseif def.connect_sides == "machine" then
|
||||
def.connect_sides = { "top", "bottom", "left", "back", "right" }
|
||||
end
|
||||
|
||||
-- Register node
|
||||
minetest.register_node(BASENAME..":"..itemstring, def)
|
||||
|
||||
-- if recipe, register recipe
|
||||
-- if recipe, Register recipe
|
||||
if def.recipe then
|
||||
microexpansion.register_recipe(BASENAME..":"..itemstring, def.recipe)
|
||||
end
|
||||
|
||||
-- if oredef, Register oredef
|
||||
if def.oredef then
|
||||
microexpansion.register_oredef(BASENAME..":"..itemstring, def.oredef)
|
||||
end
|
||||
end
|
||||
|
58
doc/api.md
@ -1,49 +1,59 @@
|
||||
# Core API
|
||||
The core API is composed of several functions to make registering new items, nodes, and recipes for items and nodes more efficient and intuitive. Code for this public API is in `./api.lua`. This documentation is divided up per function.
|
||||
|
||||
__Note:__ Any definition table for registering anything using the ME API allow a `disabled` property to be specified. If set to `false`, the node/item will not be registered, if not set, it will.
|
||||
|
||||
#### `register_recipe(output, def)`
|
||||
__Usage:__ `microexpansion.register_recipe(<output (string)>, <recipe (table)>)`
|
||||
|
||||
Though this may seem rather complex to understand, this is a very useful timesaving function when registering recipes. It allows registering multiple recipes at once in one table. The output must always remain the same as is specified as the first parameter, while the second parameter should be a table structured like one of the tables below.
|
||||
Though this may seem rather complex to understand, this is a very useful timesaving function when registering recipes. It allows registering multiple recipes at once in one table. The output must always remain the same as is specified as the first parameter, while the second parameter should be a table structured like the table below.
|
||||
|
||||
__Single Recipe:__
|
||||
__Example:__
|
||||
```lua
|
||||
microexpansion.register_recipe("default:steelblock", {
|
||||
"single",
|
||||
{
|
||||
{ 1, {
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
The above registers a single recipe for the item specified.
|
||||
|
||||
__Multiple Recipes:__
|
||||
```lua
|
||||
microexpansion.register_recipe("default:steelblock", {
|
||||
"multiple",
|
||||
{
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
},
|
||||
{
|
||||
{ "default:steel_ingot", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot" },
|
||||
}
|
||||
{ 1, "shapeless", {
|
||||
"default:steel_ingot", "default:obsidian_shard", "default:steel_ingot",
|
||||
},
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
The above registers multiple recipes for the item specified.
|
||||
The above registers a two recipes for the item specified. The `1` specifies the output quantity. `shapeless` causes the second recipe to be of the `shapeless` type. After the first one or two definitions (amount, type), the recipe can be specified as normal inside another sub-table. You can have as many recipe sub-tables as you want.
|
||||
|
||||
#### `register_oredef(ore, def)`
|
||||
__Usage:__ `microexpansion.register_oredef(<ore itemstring (string)>, <definition (table)>`
|
||||
|
||||
This custom API allows registering multiple ore definitions for a single node in one table. The table structure is quite simple, each definition is placed in an annonymous table in which the normal ore definitions are placed (excluding the ore itemstring). See below for a basic example.
|
||||
|
||||
```lua
|
||||
microexpansion.register_oredef("microexpansion:incranium", {
|
||||
{
|
||||
ore_type = "blob",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 4*4*4,
|
||||
clust_num_ores = 4,
|
||||
clust_size = 3,
|
||||
y_min = -300,
|
||||
y_max = -90,
|
||||
},
|
||||
...
|
||||
})
|
||||
```
|
||||
|
||||
See the [wiki documentation](http://dev.minetest.net/minetest.register_ore) for more information about the accepted or parameters.
|
||||
|
||||
#### `register_item(itemstring, def)`
|
||||
__Usage:__ `microexpansion.register_item(<itemstring (string)>, <item definition (table)>`
|
||||
|
||||
This API function accepts the same parameters in the definition table as does `minetest.register_craftitem`, however, it makes several modifications to the parameters before passing them on. A new parameter, `usedfor`, is introduced, which if provided is appened on a new line in grey to the item description, a good way to specify what the item does or include more information about it. The `inventory_image` parameter is modified to enforce the naming style adding `microexpansion_` to the beginning of the specified path, and `.png` to the end. If not `inventory_image` is provided, the itemstring is used and then undergoes the above modification. This allows shortening and even removing the `inventory_image` code, while passing everything else (aside from `usedfor`) on to `minetest.register_craftitem`.
|
||||
This API function accepts the same parameters in the definition table as does `minetest.register_craftitem`, however, it makes several modifications to the parameters before passing them on. A new parameter, `usedfor`, is introduced, which if provided is appened on a new line in grey to the item description, a good way to specify what the item does or include more information about it. The `inventory_image` parameter is modified to enforce the naming style adding `microexpansion_` to the beginning of the specified path, and `.png` to the end. If not `inventory_image` is provided, the itemstring is used and then undergoes the above modification. This allows shortening and even removing the `inventory_image` code, while passing everything else (aside from `usedfor`) on to `minetest.register_craftitem`. One final extra parameter is `status`, which if set to `no` the description is red, if set to `unstable` the description is `orange`, and if anything else the description is red. The recipe can be automatically registered and defined right in the item definition with the `recipe` table. See `microexpansion.register_recipe` for more information.
|
||||
|
||||
#### `register_node(itemstring, def)`
|
||||
__Usage:__ `microexpansion.register_node(<itemstring (string)>, <item definition (table)>`
|
||||
|
||||
This API function accepts the same parameters in the definition table as does `minetest.register_craftitem`, however, it makes several modifications to the parameters before passing them on. A new parameter, `usedfor`, is introduced, which if provided is appened on a new line in grey to the item description, a good way to specify what the item does or include more information about it. The `tiles` table is modified so as to simplify the definition when registering the node. Each texture in the `tiles` table has `microexpansion_` added to the beginning and `.png` to the end. This means that rather than specifying something like `microexpansion_chest_top.png`, only `chest_top` is required. __Note:__ the texture path "autocomplete" functionality can be disabled by settings `auto_complete` to `false` in the definition (useful if using textures from another mod).
|
||||
This API function accepts the same parameters in the definition table as does `minetest.register_craftitem`, however, it makes several modifications to the parameters before passing them on. A new parameter, `usedfor`, is introduced, which if provided is appened on a new line in grey to the item description, a good way to specify what the item does or include more information about it. The `tiles` table is modified so as to simplify the definition when registering the node. Each texture in the `tiles` table has `microexpansion_` added to the beginning and `.png` to the end. This means that rather than specifying something like `microexpansion_chest_top.png`, only `chest_top` is required. __Note:__ the texture path "autocomplete" functionality can be disabled by settings `auto_complete` to `false` in the definition (useful if using textures from another mod). One final extra parameter is `status`, which if set to `no` the description is red, if set to `unstable` the description is `orange`, and if anything else the description is red. The recipe can be automatically registered and defined right in the item definition with the `recipe` table. See `microexpansion.register_recipe` for more information. You can also automatically register ore definitions for the current node with `microexpansion.register_oredef`.
|
39
init.lua
@ -1,7 +1,11 @@
|
||||
-- microexpansion/init.lua
|
||||
microexpansion = {}
|
||||
microexpansion.modpath = minetest.get_modpath("microexpansion") -- modpath
|
||||
local modpath = microexpansion.modpath -- modpath pointer
|
||||
microexpansion.data = {}
|
||||
microexpansion.modpath = minetest.get_modpath("microexpansion") -- Get modpath
|
||||
microexpansion.worldpath = minetest.get_worldpath() -- Get worldpath
|
||||
|
||||
local modpath = microexpansion.modpath -- Modpath pointer
|
||||
local worldpath = microexpansion.worldpath -- Worldpath pointer
|
||||
|
||||
-- Formspec GUI related stuff
|
||||
microexpansion.gui_bg = "bgcolor[#080808BB;true]background[5,5;1,1;gui_formbg.png;true]"
|
||||
@ -9,6 +13,7 @@ microexpansion.gui_slots = "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]"
|
||||
|
||||
-- logger
|
||||
function microexpansion.log(content, log_type)
|
||||
assert(content, "microexpansion.log: missing content")
|
||||
if not content then return false end
|
||||
if log_type == nil then log_type = "action" end
|
||||
minetest.log(log_type, "[MicroExpansion] "..content)
|
||||
@ -17,6 +22,36 @@ end
|
||||
-- Load API
|
||||
dofile(modpath.."/api.lua")
|
||||
|
||||
-----------------
|
||||
---- ME DATA ----
|
||||
-----------------
|
||||
|
||||
-- [function] Load
|
||||
function microexpansion.load()
|
||||
local res = io.open(worldpath.."/microexpansion.txt", "r")
|
||||
if res then
|
||||
res = minetest.deserialize(res:read("*all"))
|
||||
if type(res) == "table" then
|
||||
microexpansion.networks = res.networks or {}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Load
|
||||
microexpansion.load()
|
||||
|
||||
-- [function] Save
|
||||
function microexpansion.save()
|
||||
local data = {
|
||||
networks = microexpansion.networks,
|
||||
}
|
||||
|
||||
io.open(worldpath.."/microexpansion.txt", "w"):write(minetest.serialize(data))
|
||||
end
|
||||
|
||||
-- [register on] Server Shutdown
|
||||
minetest.register_on_shutdown(microexpansion.save)
|
||||
|
||||
-------------------
|
||||
----- MODULES -----
|
||||
-------------------
|
||||
|
@ -1 +1,5 @@
|
||||
shared = true
|
||||
power = true
|
||||
storage = true
|
||||
ores = true
|
||||
tools = true
|
||||
|
45
modules/ores/init.lua
Normal file
@ -0,0 +1,45 @@
|
||||
-- ores/init.lua
|
||||
|
||||
local me = microexpansion
|
||||
|
||||
-- [register] Incranium Ore
|
||||
me.register_node("incranium", {
|
||||
description = "Incranium Ore",
|
||||
tiles = { "incranium" },
|
||||
is_ground_content = true,
|
||||
groups = { cracky=3, stone=1 },
|
||||
type = "ore",
|
||||
oredef = {
|
||||
{
|
||||
ore_type = "blob",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 4*4*4,
|
||||
clust_num_ores = 4,
|
||||
clust_size = 3,
|
||||
y_min = -300,
|
||||
y_max = -90,
|
||||
},
|
||||
},
|
||||
disabled = true,
|
||||
})
|
||||
|
||||
-- "Supernatet", pronounced "Super-nat-et" is Latin for "float", this ore will
|
||||
-- float up if there are no blocks above it, so be careful!
|
||||
-- Supernatet ore will be used to craft wings of flight
|
||||
me.register_node("supernatet", {
|
||||
description = "Supernatant Ore",
|
||||
tiles = { "default_stone.png^microexpansion_ore_supernatet.png" },
|
||||
is_ground_content = true,
|
||||
type = "ore",
|
||||
groups = { cracky=3, stone=1 },
|
||||
oredef = {
|
||||
ore_type = "blob",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 4*4*4,
|
||||
clust_num_ores = 4,
|
||||
clust_size = 3,
|
||||
y_min = -300,
|
||||
y_max = -90,
|
||||
},
|
||||
status = "unstable",
|
||||
})
|
96
modules/power/ctrl.lua
Normal file
@ -0,0 +1,96 @@
|
||||
-- power/ctrl.lua
|
||||
|
||||
local me = microexpansion
|
||||
|
||||
-- [register node] Controller
|
||||
me.register_node("ctrl", {
|
||||
description = "Power Controller",
|
||||
tiles = {
|
||||
"ctrl_sides",
|
||||
"ctrl_bottom",
|
||||
"ctrl_sides",
|
||||
"ctrl_sides",
|
||||
"ctrl_sides",
|
||||
"ctrl_sides"
|
||||
},
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.375, -0.375, -0.375, 0.375, 0.375, 0.375}, -- Core
|
||||
{0.1875, -0.5, -0.5, 0.5, 0.5, -0.1875}, -- Corner1
|
||||
{-0.5, -0.5, -0.5, -0.1875, 0.5, -0.1875}, -- Corner2
|
||||
{-0.5, -0.5, 0.1875, -0.1875, 0.5, 0.5}, -- Corner3
|
||||
{0.1875, -0.5, 0.1875, 0.5, 0.5, 0.5}, -- Corner4
|
||||
{-0.5, -0.4375, -0.5, 0.5, -0.1875, 0.5}, -- Bottom
|
||||
{-0.5, 0.1875, -0.5, 0.5, 0.5, -0.1875}, -- Top1
|
||||
{0.1875, 0.1875, -0.5, 0.5, 0.5, 0.5}, -- Top2
|
||||
{-0.5, 0.1875, -0.5, -0.1875, 0.5, 0.5}, -- Top3
|
||||
{-0.5, 0.1875, 0.1875, 0.5, 0.5, 0.5}, -- Top4
|
||||
{-0.1875, -0.5, -0.1875, 0.1875, -0.25, 0.1875}, -- Bottom2
|
||||
},
|
||||
},
|
||||
groups = { cracky = 1, me_connect = 1, },
|
||||
connect_sides = "nobottom",
|
||||
status = "unstable",
|
||||
|
||||
after_place_node = function(pos, player)
|
||||
local name = player:get_player_name()
|
||||
local meta = minetest.get_meta(pos)
|
||||
local id = power.new_id()
|
||||
|
||||
meta:set_string("infotext", "Network Controller (owned by "..name..")"
|
||||
.."\nNetwork ID: "..id)
|
||||
meta:set_string("network_id", id)
|
||||
meta:set_string("owner", name)
|
||||
|
||||
-- Initialize other meta
|
||||
meta:set_int("input", 0)
|
||||
meta:set_int("output", 0)
|
||||
meta:set_int("storage", 0)
|
||||
|
||||
me.networks[id] = pos
|
||||
|
||||
-- Trace Network
|
||||
power.trace(pos)
|
||||
end,
|
||||
on_destruct = function(pos, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local id = meta:get_string("network_id")
|
||||
me.networks[id] = nil
|
||||
|
||||
-- Remove unit from network
|
||||
me.network_remove(pos)
|
||||
-- Trace/clear network
|
||||
power.trace(pos)
|
||||
end,
|
||||
machine = {
|
||||
type = "transporter",
|
||||
},
|
||||
})
|
||||
|
||||
-- [register node] Cable
|
||||
me.register_machine("cable", {
|
||||
description = "ME Cable",
|
||||
tiles = {
|
||||
"cable",
|
||||
},
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "connected",
|
||||
fixed = {-0.25, -0.25, -0.25, 0.25, 0.25, 0.25},
|
||||
connect_top = {-0.25, -0.25, -0.25, 0.25, 0.5, 0.25}, -- y+
|
||||
connect_bottom = {-0.25, -0.5, -0.25, 0.25, 0.25, 0.25}, -- y-
|
||||
connect_front = {-0.25, -0.25, -0.5, 0.25, 0.25, 0.25}, -- z-
|
||||
connect_back = {-0.25, -0.25, 0.25, 0.25, 0.25, 0.5 }, -- z+
|
||||
connect_left = {-0.5, -0.25, -0.25, 0.25, 0.25, 0.25}, -- x-
|
||||
connect_right = {-0.25, -0.25, -0.25, 0.5, 0.25, 0.25}, -- x+
|
||||
},
|
||||
paramtype = "light",
|
||||
groups = { crumbly = 1, },
|
||||
status = "unstable",
|
||||
machine = {
|
||||
type = "transporter",
|
||||
},
|
||||
})
|
89
modules/power/gen.lua
Normal file
@ -0,0 +1,89 @@
|
||||
-- power/gen.lua
|
||||
|
||||
local me = microexpansion
|
||||
|
||||
-- [register node] Fuel Fired Generator
|
||||
me.register_machine("fuel_fired_generator", {
|
||||
description = "Fuel-Fired Generator",
|
||||
tiles = {
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"fuelgen_front",
|
||||
},
|
||||
recipe = {
|
||||
{ 1, {
|
||||
{ "default:steel_ingot", "default:furnace", "default:steel_ingot" },
|
||||
{"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
},
|
||||
}
|
||||
},
|
||||
groups = { cracky = 1 },
|
||||
connect_sides = "machine",
|
||||
paramtype2 = "facedir",
|
||||
status = "unstable",
|
||||
machine = {
|
||||
type = "provider",
|
||||
on_survey = function(pos)
|
||||
return 5 -- Generate 5 ME/tick
|
||||
end,
|
||||
},
|
||||
})
|
||||
|
||||
-- [register node] Super Smelter
|
||||
me.register_node("super_smelter", {
|
||||
description = "Super Smelter",
|
||||
tiles = {
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"super_smelter_front",
|
||||
},
|
||||
recipe = {
|
||||
{ 1, {
|
||||
{ "default:furnace", "default:furnace", "default:furnace" },
|
||||
{ "default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
},
|
||||
},
|
||||
},
|
||||
groups = { cracky = 1, me_connect = 1, },
|
||||
connect_sides = "machine",
|
||||
paramtype2 = "facedir",
|
||||
status = "unstable",
|
||||
machine = {
|
||||
type = "consumer",
|
||||
on_survey = function(pos)
|
||||
return 5 -- Consume 5 ME/tick
|
||||
end,
|
||||
},
|
||||
})
|
||||
|
||||
-- [register item] Geothermal Generator
|
||||
me.register_node("geo_generator", {
|
||||
description = "Geothermal Generator",
|
||||
tiles = {
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"machine_sides",
|
||||
"geogen_front",
|
||||
},
|
||||
groups = { cracky = 1, me_connect = 1, },
|
||||
connect_sides = "machine",
|
||||
paramtype2 = "facedir",
|
||||
status = "unstable",
|
||||
machine = {
|
||||
type = "provider",
|
||||
on_survey = function(pos)
|
||||
return 10 -- Generate 10 ME/tick
|
||||
end,
|
||||
},
|
||||
})
|
16
modules/power/init.lua
Normal file
@ -0,0 +1,16 @@
|
||||
-- power/init.lua
|
||||
|
||||
local me = microexpansion
|
||||
|
||||
local networks = me.networks
|
||||
local path = microexpansion.get_module_path("power")
|
||||
|
||||
me.power = {}
|
||||
local power = me.power
|
||||
|
||||
-- Load Resources
|
||||
|
||||
dofile(path.."/network.lua") -- Network Management
|
||||
dofile(path.."/register.lua") -- Machine Registration
|
||||
dofile(path.."/ctrl.lua") -- Controller/wires
|
||||
dofile(path.."/gen.lua") -- Generators
|
244
modules/power/network.lua
Normal file
@ -0,0 +1,244 @@
|
||||
-- power/network.lua
|
||||
|
||||
local me = microexpansion
|
||||
|
||||
---
|
||||
--- Helper Functions
|
||||
---
|
||||
|
||||
-- [local function] Renumber table
|
||||
local function renumber_table(t)
|
||||
local result = {}
|
||||
for _, value in pairs(t) do
|
||||
result[#result+1] = value
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
-- [local function] Get netitem by position
|
||||
local function get_netitem_by_pos(list, pos)
|
||||
for _, i in pairs(list) do
|
||||
if vector.equals(pos, i.pos) then
|
||||
return i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---
|
||||
--- API Functions
|
||||
---
|
||||
|
||||
-- [function] Get node
|
||||
function me.get_node(pos)
|
||||
local node = minetest.get_node_or_nil(pos)
|
||||
if node then return node end
|
||||
local vm = VoxelManip()
|
||||
local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
|
||||
return minetest.get_node(pos)
|
||||
end
|
||||
|
||||
-- [function] Generate new network ID
|
||||
function me.power.new_id()
|
||||
local count = 1
|
||||
for _, i in pairs(me.networks) do
|
||||
count = count + 1
|
||||
end
|
||||
|
||||
return "network_"..count
|
||||
end
|
||||
|
||||
-- [function] Can connect
|
||||
function me.power.can_connect(pos)
|
||||
local node = me.get_node(pos)
|
||||
local res = minetest.get_item_group(node.name, "me_connect")
|
||||
|
||||
if res == 1 then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- [function] Get connected nodes
|
||||
function me.power.get_connected_nodes(pos, include_ctrl)
|
||||
local nodes = {
|
||||
{x=pos.x+1, y=pos.y, z=pos.z},
|
||||
{x=pos.x-1, y=pos.y, z=pos.z},
|
||||
{x=pos.x, y=pos.y+1, z=pos.z},
|
||||
{x=pos.x, y=pos.y-1, z=pos.z},
|
||||
{x=pos.x, y=pos.y, z=pos.z+1},
|
||||
{x=pos.x, y=pos.y, z=pos.z-1},
|
||||
}
|
||||
|
||||
for _, pos in pairs(nodes) do
|
||||
if not power.can_connect(pos) then
|
||||
nodes[_] = nil
|
||||
else
|
||||
if include_ctrl == false then
|
||||
if me.get_node(pos).name == "microexpansion:ctrl" then
|
||||
nodes[_] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return renumber_table(nodes)
|
||||
end
|
||||
|
||||
-- [function] Add machine to network
|
||||
function me.power.add_machine(pos, def)
|
||||
|
||||
end
|
||||
|
||||
-- [function] Remove machine from network
|
||||
function me.power.remove_machine(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("network_ignore", "true")
|
||||
end
|
||||
|
||||
-- [function] Trace network
|
||||
function me.power.trace(pos)
|
||||
local netpos = me.networks[minetest.get_meta(pos):get_string("network_id")]
|
||||
|
||||
-- if no network, return
|
||||
if not netpos then
|
||||
return
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(netpos)
|
||||
local netid = meta:get_string("network_id")
|
||||
local list = {}
|
||||
local demand
|
||||
|
||||
local delete = false
|
||||
if meta:get_string("network_ignore") == "true" then
|
||||
delete = true
|
||||
end
|
||||
|
||||
-- [local function] Indexed
|
||||
local function indexed(pos)
|
||||
for _, i in pairs(list) do
|
||||
if vector.equals(pos, i.pos) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- [local function] Trace
|
||||
local function trace(nodes)
|
||||
for _, pos in pairs(nodes) do
|
||||
if not indexed(pos) then
|
||||
local machine = minetest.get_meta(pos)
|
||||
if machine:get_string("network_ignore") ~= "true" then
|
||||
local node = me.get_node(pos).name
|
||||
local desc = minetest.registered_nodes[node].description
|
||||
if delete then
|
||||
machine:set_string("network_id", nil)
|
||||
machine:set_string("infotext", desc.."\nNo Network")
|
||||
me.network_set_demand(pos, 0)
|
||||
else
|
||||
machine:set_string("network_id", netid)
|
||||
machine:set_string("infotext", desc.."\nNetwork ID: "..netid)
|
||||
end
|
||||
|
||||
list[#list + 1] = { pos = pos, demand = machine:get_int("demand") }
|
||||
trace(power.get_connected_nodes(pos, false))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
trace(power.get_connected_nodes(netpos))
|
||||
|
||||
-- Check original list
|
||||
local original = minetest.deserialize(meta:get_string("netitems"))
|
||||
if original then
|
||||
for _, i in pairs(original) do
|
||||
if not indexed(i.pos) then
|
||||
local node = me.get_node(i.pos).name
|
||||
local desc = minetest.registered_nodes[node].description
|
||||
local machine = minetest.get_meta(i.pos)
|
||||
machine:set_string("network_id", nil)
|
||||
machine:set_string("infotext", desc.."\nNo Network")
|
||||
me.network_set_demand(pos, 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
meta:set_string("netitems", minetest.serialize(list))
|
||||
|
||||
-- Update infotext
|
||||
meta:set_string("infotext", "Network Controller (owned by "..
|
||||
meta:get_string("owner")..")\nNetwork ID: "..meta:get_string("network_id")..
|
||||
"\nDemand: "..dump(me.network_get_demand(netpos)))
|
||||
end
|
||||
|
||||
---
|
||||
--- Load Management
|
||||
---
|
||||
|
||||
-- [function] Get load information
|
||||
function me.network_get_load(pos)
|
||||
local ctrl = me.networks[minetest.get_meta(pos):get_string("network_id")]
|
||||
if ctrl then
|
||||
local meta = minetest.get_meta(ctrl)
|
||||
local list = minetest.deserialize(meta:get_string("netitems"))
|
||||
end
|
||||
end
|
||||
|
||||
---- Generators ----
|
||||
|
||||
---- Output ----
|
||||
|
||||
-- [function] Get total network demand
|
||||
function me.network_get_demand(pos)
|
||||
local ctrl = me.networks[minetest.get_meta(pos):get_string("network_id")]
|
||||
|
||||
-- if no network, return
|
||||
if not ctrl then
|
||||
return
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(ctrl)
|
||||
local list = minetest.deserialize(meta:get_string("netitems"))
|
||||
|
||||
local demand = 0
|
||||
for _, i in pairs(list) do
|
||||
if i.demand then
|
||||
demand = demand + i.demand
|
||||
end
|
||||
end
|
||||
|
||||
return demand
|
||||
end
|
||||
|
||||
-- [function] Set demand for machine
|
||||
function me.network_set_demand(pos, demand)
|
||||
-- Update original metadata
|
||||
minetest.get_meta(pos):set_int("demand", demand)
|
||||
|
||||
local ctrl = me.networks[minetest.get_meta(pos):get_string("network_id")]
|
||||
|
||||
-- if no network, return
|
||||
if not ctrl then
|
||||
return
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(ctrl)
|
||||
local list = minetest.deserialize(meta:get_string("netitems"))
|
||||
local item = get_netitem_by_pos(list, pos)
|
||||
|
||||
if not item then
|
||||
return
|
||||
end
|
||||
|
||||
item.demand = demand
|
||||
meta:set_string("netitems", minetest.serialize(list))
|
||||
|
||||
-- Update infotext
|
||||
meta:set_string("infotext", "Network Controller (owned by "..
|
||||
meta:get_string("owner")..")\nNetwork ID: "..meta:get_string("network_id")..
|
||||
"\nDemand: "..dump(me.network_get_demand(pos)))
|
||||
end
|
||||
|
||||
---- Storage ----
|
88
modules/power/register.lua
Normal file
@ -0,0 +1,88 @@
|
||||
-- power/register.lua
|
||||
|
||||
--[[ Machine Registration API ]]
|
||||
|
||||
local me = microexpansion
|
||||
local power = me.power
|
||||
|
||||
-- [function] Register machine
|
||||
function me.register_machine(itemstring, def)
|
||||
-- Set after_place_node
|
||||
def.after_place_node = function(pos, player)
|
||||
if def.after_place_node then
|
||||
def.after_place_node(pos, player)
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local nodes = me.get_connected_nodes(pos)
|
||||
|
||||
meta:set_string("infotext", def.description.."\nNo Network")
|
||||
|
||||
for _, pos2 in pairs(nodes) do
|
||||
local id = minetest.get_meta(pos2):get_string("network_id")
|
||||
|
||||
if id ~= "" then
|
||||
meta:set_string("infotext", def.description.."\nNetwork ID: "..id)
|
||||
meta:set_string("network_id", id)
|
||||
end
|
||||
end
|
||||
|
||||
-- Trace Network
|
||||
power.trace(pos)
|
||||
|
||||
-- Set demand
|
||||
if def.demand then
|
||||
me.network_set_demand(pos, def.demand)
|
||||
end
|
||||
|
||||
if type(def.machine) == "table" then
|
||||
power.add_machine(pos, def.machine)
|
||||
end
|
||||
end
|
||||
-- Set on_destruct
|
||||
def.on_destruct = function(pos, player)
|
||||
if def.on_destruct then
|
||||
def.on_destruct(pos, player)
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
||||
if meta:get_string("network_id") ~= "" then
|
||||
-- Set demand
|
||||
me.network_set_demand(pos, 0)
|
||||
-- Remove item from network
|
||||
me.network_remove(pos)
|
||||
-- Retrace Network
|
||||
power.trace(pos)
|
||||
end
|
||||
end
|
||||
-- Set connects_to
|
||||
def.connects_to = {"group:me_connect"}
|
||||
-- Set me_connect group
|
||||
def.groups = def.groups or {}
|
||||
def.groups.me_connect = 1
|
||||
|
||||
me.register_node(itemstring, def)
|
||||
end
|
||||
|
||||
-- [function] Get machine definition
|
||||
function me.get_def(name, key)
|
||||
if type(name) == "table" then
|
||||
local node = me.get_node(name)
|
||||
if node then
|
||||
name = node.name
|
||||
end
|
||||
end
|
||||
|
||||
local def = minetest.registered_nodes[name]
|
||||
-- Check name and if registered
|
||||
if not name or not def then
|
||||
return
|
||||
end
|
||||
|
||||
if key then
|
||||
return def[key]
|
||||
else
|
||||
return def
|
||||
end
|
||||
end
|
30
modules/shared/init.lua
Normal file
@ -0,0 +1,30 @@
|
||||
-- shared/init.lua
|
||||
|
||||
local me = microexpansion
|
||||
|
||||
-- This mostly contains items that are used by multiple modules and
|
||||
-- don't really fit with anything else.
|
||||
|
||||
-- [register item] Steel Infused Obsidian Ingot
|
||||
me.register_item("steel_infused_obsidian_ingot", {
|
||||
description = "Steel Infused Obsidian Ingot",
|
||||
recipe = {
|
||||
{ 1, {
|
||||
{ "default:steel_ingot", "default:obsidian_shard", "default:steel_ingot" },
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- [register item] Machine Casing
|
||||
me.register_item("machine_casing", {
|
||||
description = "Machine Casing",
|
||||
recipe = {
|
||||
{ 1, {
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
@ -88,9 +88,12 @@ function microexpansion.cell_desc(inv, listname, spos)
|
||||
end
|
||||
end
|
||||
|
||||
-- Calculate Percentage
|
||||
local percent = math.floor(items / max_items * 100)
|
||||
|
||||
-- Update description
|
||||
meta:set_string("description", base_desc.."\n"..
|
||||
minetest.colorize("grey", tostring(items).."/"..tostring(max_items).." Items"))
|
||||
minetest.colorize("grey", tostring(items).."/"..tostring(max_items).." Items ("..tostring(percent).."%)"))
|
||||
-- Update stack
|
||||
inv:set_stack(listname, spos, stack)
|
||||
end
|
||||
|
@ -6,20 +6,29 @@ local me = microexpansion
|
||||
local function chest_formspec(pos, start_id, listname, page_max, query)
|
||||
local list
|
||||
local page_number = ""
|
||||
local to_chest = ""
|
||||
local buttons = ""
|
||||
local query = query or ""
|
||||
|
||||
if not listname then
|
||||
list = "label[3,2;" .. minetest.colorize("red", "No cell!") .. "]"
|
||||
else
|
||||
list = "list[current_name;" .. listname .. ";0,0.3;8,4;" .. (start_id - 1) .. "]"
|
||||
to_chest = [[
|
||||
buttons = [[
|
||||
button[3.56,4.35;1.8,0.9;tochest;To Drive]
|
||||
tooltip[tochest;Move everything from your inventory to the ME drive.]
|
||||
button[5.4,4.35;0.8,0.9;prev;<]
|
||||
button[7.25,4.35;0.8,0.9;next;>]
|
||||
tooltip[prev;Previous]
|
||||
tooltip[next;Next]
|
||||
field[0.29,4.6;2.2,1;filter;;]]..query..[[]
|
||||
button[2.1,4.5;0.8,0.5;search;?]
|
||||
button[2.75,4.5;0.8,0.5;clear;X]
|
||||
tooltip[search;Search]
|
||||
tooltip[clear;Reset]
|
||||
]]
|
||||
end
|
||||
if page_max then
|
||||
page_number = "label[6.05,4.5;" .. math.floor((start_id / 32)) + 1 ..
|
||||
page_number = "label[6.15,4.5;" .. math.floor((start_id / 32)) + 1 ..
|
||||
"/" .. page_max .."]"
|
||||
end
|
||||
|
||||
@ -34,19 +43,12 @@ local function chest_formspec(pos, start_id, listname, page_max, query)
|
||||
list[current_name;cells;8.06,1.8;1,1;]
|
||||
list[current_player;main;0,5.5;8,1;]
|
||||
list[current_player;main;0,6.73;8,3;8]
|
||||
button[5.4,4.35;0.8,0.9;prev;<]
|
||||
button[7.25,4.35;0.8,0.9;next;>]
|
||||
field[0.3,4.6;2.2,1;filter;;]]..query..[[]
|
||||
button[2.1,4.5;0.8,0.5;search;?]
|
||||
button[2.75,4.5;0.8,0.5;clear;X]
|
||||
tooltip[search;Search]
|
||||
tooltip[clear;Reset]
|
||||
listring[current_name;main]
|
||||
listring[current_player;main]
|
||||
field_close_on_enter[filter;false]
|
||||
]]..
|
||||
page_number ..
|
||||
to_chest
|
||||
buttons
|
||||
end
|
||||
|
||||
-- [me chest] Register node
|
||||
|
@ -5,3 +5,21 @@ microexpansion.register_cell("cell_8k", {
|
||||
description = "8k ME Storage Cell",
|
||||
capacity = 8000,
|
||||
})
|
||||
|
||||
-- [drive] 16k
|
||||
microexpansion.register_cell("cell_16k", {
|
||||
description = "16k ME Storage Cell",
|
||||
capacity = 16000,
|
||||
})
|
||||
|
||||
-- [drive] 32k
|
||||
microexpansion.register_cell("cell_32k", {
|
||||
description = "32k ME Storage Cell",
|
||||
capacity = 32000,
|
||||
})
|
||||
|
||||
-- [drive] 64k
|
||||
microexpansion.register_cell("cell_64k", {
|
||||
description = "64k ME Storage Cell",
|
||||
capacity = 64000,
|
||||
})
|
||||
|
6
modules/tools/init.lua
Normal file
@ -0,0 +1,6 @@
|
||||
-- tools/init.lua
|
||||
|
||||
local path = microexpansion.get_module_path("tools")
|
||||
|
||||
-- Load In Xtremo Tools
|
||||
dofile(path.."/xtremo.lua")
|
29
modules/tools/xtremo.lua
Normal file
@ -0,0 +1,29 @@
|
||||
-- tools/xtremo.lua
|
||||
|
||||
-- [register tool] Pickaxe
|
||||
minetest.register_tool("microexpansion:xtremo_pickaxe", {
|
||||
description = "In Xtremo Pickaxe",
|
||||
inventory_image = "microexpansion_in_xtremo_pickaxe.png",
|
||||
tool_capabilities = {
|
||||
full_punch_interval = 0.9,
|
||||
max_drop_level=3,
|
||||
groupcaps={
|
||||
cracky = {times={[1]=1.90, [2]=0.90, [3]=0.40}, uses=300, maxlevel=4},
|
||||
},
|
||||
damage_groups = {fleshy=5},
|
||||
},
|
||||
})
|
||||
|
||||
-- [register tool] Axe
|
||||
minetest.register_tool("microexpansion:xtremo_axe", {
|
||||
description = "In Xtremo Axe",
|
||||
inventory_image = "microexpansion_in_xtremo_axe.png",
|
||||
tool_capabilities = {
|
||||
full_punch_interval = 0.9,
|
||||
max_drop_level=3,
|
||||
groupcaps={
|
||||
choppy={times={[1]=2.00, [2]=0.80, [3]=0.40}, uses=300, maxlevel=4},
|
||||
},
|
||||
damage_groups = {fleshy=7},
|
||||
},
|
||||
})
|
BIN
screenshot.png
Before Width: | Height: | Size: 696 KiB After Width: | Height: | Size: 213 KiB |
BIN
textures/microexpansion_cable.png
Normal file
After Width: | Height: | Size: 255 B |
BIN
textures/microexpansion_cell_16k.png
Normal file
After Width: | Height: | Size: 555 B |
BIN
textures/microexpansion_cell_32k.png
Normal file
After Width: | Height: | Size: 547 B |
BIN
textures/microexpansion_cell_64k.png
Normal file
After Width: | Height: | Size: 543 B |
BIN
textures/microexpansion_ctrl_bottom.png
Normal file
After Width: | Height: | Size: 333 B |
BIN
textures/microexpansion_ctrl_sides.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
textures/microexpansion_fuelgen_front.png
Normal file
After Width: | Height: | Size: 339 B |
BIN
textures/microexpansion_geogen_front.png
Normal file
After Width: | Height: | Size: 317 B |
BIN
textures/microexpansion_in_xtremo_axe.png
Normal file
After Width: | Height: | Size: 391 B |
BIN
textures/microexpansion_in_xtremo_pickaxe.png
Normal file
After Width: | Height: | Size: 418 B |
BIN
textures/microexpansion_machine_casing.png
Normal file
After Width: | Height: | Size: 326 B |
BIN
textures/microexpansion_machine_sides.png
Normal file
After Width: | Height: | Size: 459 B |
BIN
textures/microexpansion_ore_supernatet.png
Normal file
After Width: | Height: | Size: 309 B |
BIN
textures/microexpansion_solar_gen_down.png
Normal file
After Width: | Height: | Size: 252 B |
BIN
textures/microexpansion_solar_gen_sides.png
Normal file
After Width: | Height: | Size: 166 B |
BIN
textures/microexpansion_solar_gen_top.png
Normal file
After Width: | Height: | Size: 212 B |
BIN
textures/microexpansion_steel_infused_obsidian_ingot.png
Normal file
After Width: | Height: | Size: 315 B |
BIN
textures/microexpansion_super_smelter_front.png
Normal file
After Width: | Height: | Size: 369 B |
BIN
textures/microexpansion_supersmelter_front.png
Normal file
After Width: | Height: | Size: 328 B |