Compare commits

...

8 Commits

18 changed files with 177 additions and 57 deletions

View File

@ -3,7 +3,6 @@ local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = { "constants.lua", "smelting.lua", "crafting.lua", "drop.lua"}
local spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

View File

@ -3,7 +3,6 @@ local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = minetest.get_dir_list(PATH, false)
spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

View File

@ -1,9 +1,9 @@
local NAME = minetest.get_current_modname()
local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = minetest.get_dir_list(PATH, false)
local MODFILES = { "sapling.lua", "trunk.lua", "leaf.lua", "tree.lua", "flax.lua", "grass.lua", "bush.lua", "stick.lua"}
spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

View File

@ -3,7 +3,6 @@ local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = minetest.get_dir_list(PATH, false)
spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

View File

@ -3,7 +3,6 @@ local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = minetest.get_dir_list(PATH, false)
spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

View File

@ -1,9 +1,8 @@
local NAME = minetest.get_current_modname()
local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = { "overide.lua", "constants.lua", "math.lua", "dig.lua", "hud_notify.lua", "energy.lua", "formspec.lua", "tool.lua"}
local MODFILES = { "overide.lua", "constants.lua", "math.lua", "dig.lua", "hud_notify.lua", "energy.lua", "formspec.lua", "tool.lua", "io.lua"}
spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

27
mods/sparkapi/lua/io.lua Normal file
View File

@ -0,0 +1,27 @@
local iodebug = true
sparktech.getoption = function(nodepos, optionname)
local node = minetest.get_node(nodepos)
local meta = minetest.get_meta(nodepos)
local optionsdef = minetest.registered_nodes[node.name]._sparkoption
if iodebug and not optionsdef[optionname] then
error("optioname " ..optionname .. " for " .. node.name .." is not defined!")
end
local resultMeta = meta:get(optionname)
if resultMeta ~= nil then
return minetest.deserialize(resultMeta)
else
return minetest.registered_nodes[node.name]._sparkoption[optionname]
end
end
sparktech.setoption = function(nodepos, optionname, optionvalue)
local node = minetest.get_node(nodepos)
local meta = minetest.get_meta(nodepos)
if iodebug and not optionsdef[optionname] then
error("optioname " .. optionname .. " for " .. node.name .." is not defined!")
end
meta:set(optionname, minetest:serialize(optionvalue))
end

View File

@ -3,7 +3,6 @@ local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = minetest.get_dir_list(PATH, false)
spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

View File

@ -3,7 +3,6 @@ local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = minetest.get_dir_list(PATH, false)
spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

View File

@ -10,7 +10,6 @@ if not minetest.settings:get("spark_debug_enable") then
return false
end
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
for i=1,table.getn(MODFILES),1
do
minetest.debug(""..NAME .. string.rep(" ",spacenum) .."load " .. MODFILES[i])

View File

@ -20,32 +20,46 @@ minetest.register_tool("sparkdebug:multimeter", {
})
minetest.register_on_joinplayer(function(player)
local idx = player:hud_add({
hud_elem_type = "statbar",
position = {x = 0.5, y = 0.5},
offset = {x =-100, y = -40},
text = "bar_red.png",
direction = 0,
size = { x=1, y=20 }, -- looks correct with 2, less is invisble, more is too big :/
number = 20
local energyBar = player:hud_add({
hud_elem_type = "statbar",
position = { x = 0.5, y = 0.5 },
offset = { x = -100, y = -160 },
text = "bar_red.png",
direction = 0,
size = { x = 1, y = 20 }, -- looks correct with 2, less is invisble, more is too big :/
number = 20
})
local idy = player:hud_add({
hud_elem_type = "text",
position = {x = 0.5, y = 0.5},
offset = {x = 0, y = -50},
text = "",
direction = 0,
number = tonumber ("0xFFFFFF", 16)
local textEnergy = player:hud_add({
hud_elem_type = "text",
position = { x = 0.5, y = 0.5 },
offset = { x = 0, y = -170 },
text = "",
direction = 0,
number = tonumber ("0xFFFFFF", 16)
})
local idz = player:hud_add({
hud_elem_type = "text",
position = {x = 0.5, y = 0.5},
offset = {x = 0, y = 50},
text = "",
direction = 0,
number = tonumber ("0xFFFFFF", 16)
local textMaster = player:hud_add({
hud_elem_type = "text",
position = { x = 0.5, y = 0.5 },
offset = { x = 0, y = -120 },
text = "",
direction = 0,
number = tonumber ("0xFFFFFF", 16)
})
sparktech.energy_hud[player:get_player_name()] = {idb = idx, idt = idy, idm = idz, pos = {x = 0, y = 0, z = 0}}
local nodeOptionsText = player:hud_add({
hud_elem_type = "text",
position = { x = 0.5, y = 0.5 },
offset = { x = 0, y = -80 },
text = "",
direction = 0,
number = tonumber ("0xFFFFFF", 16)
})
sparktech.energy_hud[player:get_player_name()] = {
energyBar = energyBar,
textEnergy = textEnergy,
textMaster = textMaster,
nodeOptionsText = nodeOptionsText,
pos = { x = 0, y = 0, z = 0 }
}
end)
minetest.register_globalstep(function(dtime)
@ -57,13 +71,25 @@ minetest.register_globalstep(function(dtime)
return
end
player:hud_change(i["idb"], "number", meta:get_int("energy") / minetest.get_item_group(node.name, "sparktech_energy_max") * 400)
player:hud_change(i["energyBar"], "number", meta:get_int("energy") / minetest.get_item_group(node.name, "sparktech_energy_max") * 400)
local val = minetest.get_item_group(node.name, "sparktech_energy_max")
if val == 0 then
player:hud_change(i["idt"], "text", "")
player:hud_change(i["textEnergy"], "text", "")
else
player:hud_change(i["idt"], "text", meta:get_int("energy") .. " / " .. val)
player:hud_change(i["textEnergy"], "text", meta:get_int("energy") .. " / " .. val)
end
player:hud_change(i["idm"], "text", meta:get_string("net_master"))
local hudString = "Options\n"
if minetest.registered_nodes[node.name]._sparkoption then
for optionname, default in pairs(minetest.registered_nodes[node.name]._sparkoption) do
local option = sparktech.getoption(i["pos"], optionname)
hudString = hudString .. optionname .. "["..type(default) .. "]: "
hudString = hudString .. tostring(option) .. " (" .. tostring(default) .. ")\n"
end
player:hud_change(i["nodeOptionsText"], "text", hudString)
else
player:hud_change(i["nodeOptionsText"], "text", "")
end
player:hud_change(i["textMaster"], "text", meta:get_string("net_master"))
end
end)

View File

@ -3,7 +3,6 @@ local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = minetest.get_dir_list(PATH, false)
spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

View File

@ -18,9 +18,9 @@ end
local function is_item_allowed(pos, target, _, stack)
if stack == nil or not is_fuel({stack}) or target ~= "fuel" then
if stack == nil or not is_fuel({stack}) or target ~= "fuel" or not sparktech.getoption(pos, "accept_items") then
return 0 -- returning nil here crashes minetest 1942660955bc3684a60d527e2fafa0ec3e02dd54
else
else -- now it gives a lua error, neat :D
return stack:get_count()
end
end
@ -125,7 +125,38 @@ minetest.register_node(NAME .. ":burnergenerator", {
update_formspec(pos) -- Later this should only be done when a player looks into the block
minetest.get_node_timer(pos):start(INTERVAL)
end
end,
_sparkoptionchanged = function(pos, name)
if name == "enabled" then
local timer = minetest.get_node_timer(pos)
if sparktech.getoption(pos, name) then
timer:start(INTERVAL)
else
timer:stop()
end
end
end,
_sparkoption = {
enabled = true,
accept_items = true
},
_sparkoutput = {
burntime = function(nodepos)
local meta = minetest.get_meta(pos)
local inventory = meta:get_inventory()
local item = inventory:get_stack("fuel", 1)
return item:get_meta():get_int("rem_energy_")
end,
item = function(nodepos)
local meta = minetest.get_meta(pos)
local inventory = meta:get_inventory()
return inventory:get_stack("fuel", 1)
end
},
_sparkoutputtype = {
burntime = type(int),
item = type(ItemStack())
}
})

View File

@ -21,23 +21,39 @@ minetest.register_node(NAME .. ":solar", {
sparktech_techy = WRENCHABLE,
sparktech_energy_type = ENERGY_PRODUCER,
sparktech_net_trigger = TRUE,
sparktech_energy_max = MAX_ENERGY
}
sparktech_energy_max = MAX_ENERGY,
sparktech_io = TRUE
},
_sparkoptionchanged = function(pos, name)
-- Don't need to handle enabled here because solar runs on an ABM
end,
_sparkoption = {
enabled = true,
},
_sparkoutput = {
lightLevel = function(nodepos)
-- TODO: cap this at light that the sun /can/ generator for this time
return minetest.get_node_light(pos)
end
},
})
minetest.register_abm({
nodenames = {minetest.get_current_modname() .. ":solar"},
interval = 1.0,
chance = 1,
catch_up = true,
chance = 1,
catch_up = true,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
meta:set_int("energy", meta:get_int("energy") + 2 * ( minetest.get_node_light(pos) / 15 ) ) -- this needs to be sunlight only... api missing
local emax = minetest.get_item_group(node.name, "sparktech_energy_max")
if meta:get_int("energy") > emax then
meta:set_int("energy", emax)
end
if sparktech.getoption(pos, "enabled") then
local meta = minetest.get_meta(pos)
-- TODO: cap this at light that the sun /can/ generator for this time
meta:set_int("energy", meta:get_int("energy") + 2 * ( minetest.get_node_light(pos) / 15 ) ) -- this needs to be sunlight only... api missing
local emax = minetest.get_item_group(node.name, "sparktech_energy_max")
if meta:get_int("energy") > emax then
meta:set_int("energy", emax)
end
end
end
})

View File

@ -3,7 +3,6 @@ local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = minetest.get_dir_list(PATH, false)
local spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

View File

@ -3,7 +3,6 @@ local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = minetest.get_dir_list(PATH, false)
local spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

View File

@ -3,7 +3,6 @@ local PATH = minetest.get_modpath(NAME) .."/lua/"
local MODFILES = minetest.get_dir_list(PATH, false)
local spacenum = 20 - string.len(NAME)
minetest.debug("" .. NAME .. string.rep(" ",spacenum) .. "init")
-- This assumes that the lua/ subdir contains lua code only.

View File

@ -17,13 +17,15 @@ minetest.register_node(NAME ..":charger", {
NAME .. "_steel_backplate.png",
NAME .. "_charger_frontplate.png",
},
paramtype2 = "facedir",
groups = {
sparktech_techy = WRENCHABLE,
sparktech_energy_type = ENERGY_CONSUMER,
sparktech_energy_storeonbreak = TRUE,
sparktech_net_trigger = TRUE,
sparktech_energy_max = MAX_ENERGY,
sparktech_energy_wakeup = 10
sparktech_energy_wakeup = 10,
sparktech_io = TRUE
},
on_metadata_inventory_take = function(pos)
local meta = minetest.get_meta(pos)
@ -58,8 +60,7 @@ minetest.register_node(NAME ..":charger", {
local item = node_inventory:get_stack("charge", 1)
local item_meta = item:get_meta()
local item_charge_old = item_meta:get_int("energy") -- curr
local item_charge_max = minetest.get_item_group(item:get_name(), --max
"sparktech_chargable")
local item_charge_max = minetest.get_item_group(item:get_name(), "sparktech_chargable") / minetest.registered_nodes[NAME .. ":charger"]._sparkoption.max_chargeratio
local item_charge_diff = math.min(item_charge_max - item_charge_old, SPEED)
local item_charge_new = item_charge_old + item_charge_diff
@ -102,6 +103,37 @@ minetest.register_node(NAME ..":charger", {
local inventory = meta:get_inventory()
inventory:set_size('charge', 1)
end,
_sparkoptionchanged = function(pos, name)
if name == "enabled" then
local timer = minetest.get_node_timer(pos)
if sparktech.getoption(pos, name) then
timer:start(1.0)
else
timer:stop()
end
end
end,
_sparkoption = {
enabled = true,
max_chargeratio = 1
},
_sparkoutput = {
charge = function(nodepos)
local meta = minetest.get_meta(pos)
local inventory = meta:get_inventory()
local item = inventory:get_stack("charge", 1)
return item:get_meta():get_int("energy")
end,
item = function(nodepos)
local meta = minetest.get_meta(pos)
local inventory = meta:get_inventory()
return inventory:get_stack("charge", 1)
end
},
_sparkoutputtype = {
charge = type(int),
item = type(ItemStack())
}
})
minetest.register_craft({