Standalone Powercell, Lighting Fix's

Powercells can now power machines so long as they are charged up and connected to a machine/light bulb etc ie powercells can be a provider on there own now.

Lighting fixed a few issues:
Lights weren't getting power if you added them to a network while it was on powercell power rather than provider power.
Floodlights had the wrong drops listed
This commit is contained in:
Sirrobzeroone 2021-09-26 22:35:44 +10:00
parent 12eacba8f6
commit 5d14083f2c
3 changed files with 64 additions and 24 deletions

View File

@ -395,6 +395,24 @@ function elepower_lighting.rot_and_place(itemstack, placer, pointed_thing)
return minetest.item_place(itemstack, placer, pointed_thing, param2) return minetest.item_place(itemstack, placer, pointed_thing, param2)
end end
-------------------------------------
-- Light State Function --
-- "Active", "Off", "Out of Power" --
-------------------------------------
function elepower_lighting.status(on_off,storage,usage)
local status = "Active"
if on_off == 0 then
status = "Off"
elseif storage < usage then
status = "Out of Power!"
end
return status
end
------------------------------------ ------------------------------------
-- Main Lighting timer, what uses -- -- Main Lighting timer, what uses --
-- EpU's and allows lights to be -- -- EpU's and allows lights to be --
@ -413,7 +431,7 @@ function elepower_lighting.light_timer(pos)
local pow_percent = {capacity = capacity, storage = storage, usage = usage} local pow_percent = {capacity = capacity, storage = storage, usage = usage}
local light_strip_axis local light_strip_axis
local flood_light_change = false local flood_light_change = false
if light_shape ~= "flood" then if light_shape ~= "flood" then
light_strip_axis = elepower_lighting.p2_to_axis(node_p2) light_strip_axis = elepower_lighting.p2_to_axis(node_p2)
@ -539,7 +557,8 @@ function elepower_lighting.light_timer(pos)
end end
end end
meta:set_string("infotext", name .. "\n" .. ele.capacity_text(capacity, storage)) local status = elepower_lighting.status(on_off,pow_percent.storage,pow_percent.usage)
meta:set_string("infotext", name.." "..status.."\n" .. ele.capacity_text(capacity, storage))
if light_shape == "flood" then if light_shape == "flood" then
local tilt = meta:get_int("tilt") or 0 local tilt = meta:get_int("tilt") or 0
@ -709,9 +728,10 @@ function elepower_lighting.light_timer_colored(pos)
end end
end end
local status = elepower_lighting.status(on_off,pow_percent.storage,pow_percent.usage)
meta:set_string("formspec", get_formspec_panel_color(pow_percent,color_mode,color_sync)) meta:set_string("formspec", get_formspec_panel_color(pow_percent,color_mode,color_sync))
meta:set_string("infotext", name .. "\n" .. ele.capacity_text(capacity, storage)) meta:set_string("infotext", name .." "..status.. "\n" .. ele.capacity_text(capacity, storage))
cycles = 0 cycles = 0
end end
@ -866,7 +886,7 @@ end)
function elepower_lighting.light_punch(pos,player) function elepower_lighting.light_punch(pos,player)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local on_off = meta:get_int("on_off") or 1 local on_off = meta:get_int("on_off") or 1
if on_off == 1 then if on_off == 1 then
on_off = 0 on_off = 0
@ -880,6 +900,7 @@ end
function elepower_lighting.light_construct(pos) function elepower_lighting.light_construct(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("on_off",1) meta:set_int("on_off",1)
meta:set_string("infotext", "Active")
local is_colored = minetest.registered_items[minetest.get_node(pos).name].palette or nil local is_colored = minetest.registered_items[minetest.get_node(pos).name].palette or nil

View File

@ -13,15 +13,15 @@
------------------------------------------------------ ------------------------------------------------------
local flood_light_angles = { local flood_light_angles = {
xp0_yp0 = {groups = {cracky = 1, ele_user = 1, ele_lighting = 1}, drops = "elepower_lighting:incandescent_floodlight_xp0_yp0"}, xp0_yp0 = {groups = {cracky = 1, ele_user = 1, ele_lighting = 1}},
xp0_yp20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}, drops = "elepower_lighting:incandescent_floodlight_xp0_yp0"}, xp0_yp20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}},
xp0_yn20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}, drops = "elepower_lighting:incandescent_floodlight_xp0_yp0"}, xp0_yn20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}},
xp45_yp0 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}, drops = "elepower_lighting:incandescent_floodlight_xp0_yp0"}, xp45_yp0 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}},
xp45_yp20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}, drops = "elepower_lighting:incandescent_floodlight_xp0_yp0"}, xp45_yp20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}},
xp45_yn20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}, drops = "elepower_lighting:incandescent_floodlight_xp0_yp0"}, xp45_yn20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}},
xn45_yp0 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}, drops = "elepower_lighting:incandescent_floodlight_xp0_yp0"}, xn45_yp0 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}},
xn45_yp20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}, drops = "elepower_lighting:incandescent_floodlight_xp0_yp0"}, xn45_yp20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}},
xn45_yn20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}, drops = "elepower_lighting:incandescent_floodlight_xp0_yp0"} xn45_yn20 = {groups = {cracky = 1, ele_user = 1, not_in_creative_inventory = 1}}
} }
for angle,def in pairs(flood_light_angles) do for angle,def in pairs(flood_light_angles) do
@ -46,7 +46,7 @@ for angle,def in pairs(flood_light_angles) do
use_texture_alpha = "clip", use_texture_alpha = "clip",
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
drops = def.drops, drops = "elepower_lighting:incandescent_floodlight_xp0_yp0",
groups = def.groups, groups = def.groups,
ele_capacity = 64, ele_capacity = 64,
ele_usage = 8, ele_usage = 8,
@ -84,7 +84,7 @@ for angle,def in pairs(flood_light_angles) do
use_texture_alpha = "clip", use_texture_alpha = "clip",
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
drops = def.drops, drops = "elepower_lighting:cf_floodlight_xp0_yp0",
groups = def.groups, groups = def.groups,
ele_capacity = 128, ele_capacity = 128,
ele_usage = 4, ele_usage = 4,
@ -122,7 +122,7 @@ for angle,def in pairs(flood_light_angles) do
use_texture_alpha = "clip", use_texture_alpha = "clip",
paramtype = "light", paramtype = "light",
sunlight_propagates = true, sunlight_propagates = true,
drops = def.drops, drops = "elepower_lighting:led_floodlight_xp0_yp0",
groups = def.groups, groups = def.groups,
ele_capacity = 192, ele_capacity = 192,
ele_usage = 2, ele_usage = 2,

View File

@ -136,8 +136,13 @@ local function discover_branches(pr_pos, positions)
end end
end end
-- Add self to providers -- self/triggered abm node can be provider or powercell/user_gets
-- add to correct table provider or user
if ele.helpers.get_item_group(provider.name, "ele_storage") then
add_node(users, pr_pos, pnodeid, "ele_storage")
else
add_node(providers, pr_pos, pnodeid) add_node(providers, pr_pos, pnodeid)
end
users = ele.helpers.flatten(users) users = ele.helpers.flatten(users)
providers = ele.helpers.flatten(providers) providers = ele.helpers.flatten(providers)
@ -159,7 +164,7 @@ local function give_node_power(pos, available)
local storage = user_meta:get_int("storage") local storage = user_meta:get_int("storage")
local usage = ele.helpers.get_node_property(user_meta, pos, "usage") local usage = ele.helpers.get_node_property(user_meta, pos, "usage")
local status = user_meta:get_string("infotext") local status = user_meta:get_string("infotext")
local total_add = 0 local total_add = 0
if available >= inrush then if available >= inrush then
@ -182,17 +187,18 @@ end
minetest.register_abm({ minetest.register_abm({
nodenames = {"group:ele_provider"}, nodenames = {"group:ele_provider","group:ele_storage"},
label = "elepower Power Transfer Tick", label = "elepower Power Transfer Tick",
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider) action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local meta1 = nil local meta1 = nil
local users = {} local users = {}
local providers = {} local providers = {}
local providerdef = minetest.registered_nodes[node.name] local providerdef = minetest.registered_nodes[node.name]
-- TODO: Customizable output sides -- TODO: Customizable output sides
local positions = { local positions = {
@ -205,6 +211,7 @@ minetest.register_abm({
} }
local branches = {} local branches = {}
for _,pos1 in ipairs(positions) do for _,pos1 in ipairs(positions) do
local pnode = minetest.get_node(pos1) local pnode = minetest.get_node(pos1)
local name = pnode.name local name = pnode.name
@ -227,7 +234,19 @@ minetest.register_abm({
-- Find all users and providers -- Find all users and providers
users, providers = discover_branches(pos, branches) users, providers = discover_branches(pos, branches)
-- Standalone Powercell check
if ele.helpers.get_item_group(node.name, "ele_storage") and #providers >= 1 then
-- abm hits powercell but network has provider end here
-- as power distribution will be handled on provider abm hit
-- minetest.debug("provider present")
return
elseif ele.helpers.get_item_group(node.name, "ele_provider") then
--minetest.debug("Provider")
else
--minetest.debug("solo storage")
end
-- Calculate power data for providers -- Calculate power data for providers
local pw_supply = 0 local pw_supply = 0
local pw_demand = 0 local pw_demand = 0
@ -285,7 +304,7 @@ minetest.register_abm({
table.insert(bat_users, pg) -- save node_users who aren't batteries table.insert(bat_users, pg) -- save node_users who aren't batteries
end end
end end
users = bat_users -- replace users with bat_users so batteries arent users anymore users = bat_users -- replace users with bat_users so batteries arent users anymore
providers = bat_providers -- replace providers with bat_providers providers = bat_providers -- replace providers with bat_providers
pw_supply = bat_supply -- override with battery supply pw_supply = bat_supply -- override with battery supply
@ -298,7 +317,7 @@ minetest.register_abm({
for _,ndv in ipairs(users) do --ndv = pos table for _,ndv in ipairs(users) do --ndv = pos table
-- Check how much power a node wants and can get ie is it close to full charge -- Check how much power a node wants and can get ie is it close to full charge
local user_gets, user_storage, user_usage, user_status = give_node_power(ndv, (pw_supply - pw_demand)) -- pw_demand always 0 check old code local user_gets, user_storage, user_usage, user_status = give_node_power(ndv, (pw_supply - pw_demand)) -- pw_demand always 0 check old code
-- when on battery we dont want to provide user_inrush or if -- when on battery we dont want to provide user_inrush or if
-- machine is currently not in use we dont want to use bat power -- machine is currently not in use we dont want to use bat power
-- user_status provides the tooltip info when you point at a -- user_status provides the tooltip info when you point at a