Added Bioreactor as power source for batteries

Bioreactors produce the energy inside Voltic Batteries.

  Bioreactors produce continuous energy at a constant rate.
This commit is contained in:
david 2021-03-16 20:40:08 -04:00
parent ce19345866
commit 277af6cfb9
20 changed files with 322 additions and 24 deletions

View File

@ -1,13 +1,9 @@
# Voltic Battery
A Voltic Battery is able to produce a small amount of charge on it's own, without anything except the standard stuff (requires a Switch Station).
Voltic Batteries are essentially the mix of a small bioreactor and a battery.
## Required
Thus it produces a small but continuous amount of power. (Or commonly also known as free energy)
All you really need is technic, though I do have support (just like technic does) for digilines.
The Bioreactor is simply a device that produces more free energy.
## Why
So I was thinking of something to add to technic, just as a fun extra to include... and here this mod is.
The point of this is so you could build a quick base to do things like charge your tools or to power something that doesn't eat the power quickly.
But is fairly expensive in terms of construction.

24
hv.lua
View File

@ -1,3 +1,23 @@
-- HV Bio Reactor
minetest.register_craft({
output = "voltic_battery:hv_bioreactor0",
recipe = {
{"group:leaves", "default:steelblock", "group:leaves"},
{"group:leaves", "voltic_battery:mv_bioreactor0", "group:leaves"},
{"group:leaves", "technic:hv_cable", "group:leaves"}
}
})
tech.register_bioreactor({
tier = "HV",
max_charge = 130,
charge_rate = 130,
discharge_rate = 130,
charge_step = 1300,
discharge_step = 1300,
generate = 130,
})
-- HV battery box
minetest.register_craft({
@ -10,13 +30,13 @@ minetest.register_craft({
tech.register_battery_box2({
tier = "HV",
max_charge = 980000,
max_charge = 650000, -- 65% of 1,000,000
charge_rate = 100500,
discharge_rate = 400500,
charge_step = 10000,
discharge_step = 40000,
upgrade = 1,
tube = 1,
generate = 9800,
generate = 105, -- 0.001 of max (Or 80.7% of a HV Bioreactor)
})

View File

@ -20,18 +20,18 @@ dofile(path.."/hv.lua")
--[[ Stats:
LV:
Max: 38,000 (38 k)
Max: 26,000 (26 k)
Input: 1,500 (1.5k)
Output: 4,500 (4.5k)
Generates: 380
Generates: 26
MV:
Max: 170,000 (170 k)
Max: 130,000 (130 k)
Input: 20,500 (20.5k)
Output: 80,500 (80.5k)
Generates: 1,700 (1.5 k)
Generates: 130
HV:
Max: 980,000 (980 k)
Max: 650,000 (650 k)
Input: 100,500 (100.5k)
Output: 400,500 (400.5k)
Generates: 9,800 (9.8 k)
Generates: 650
--]]

29
lv.lua
View File

@ -1,19 +1,40 @@
-- LV Bio Reactor
minetest.register_craft({
output = "voltic_battery:lv_bioreactor0",
recipe = {
{"group:leaves", "default:steelblock", "group:leaves"},
{"group:leaves", "technic:machine_casing", "group:leaves"},
{"group:leaves", "technic:lv_cable", "group:leaves"}
}
})
tech.register_bioreactor({
tier = "LV",
max_charge = 32,
charge_rate = 32,
discharge_rate = 32,
charge_step = 320,
discharge_step = 320,
generate = 32,
})
-- LV Battery box
minetest.register_craft({
type = "shapeless",
output = 'voltic_battery:lv_battery_volt0',
recipe = {
{"technic:lv_battery_box0"},
{"technic:solar_panel"},
"technic:lv_battery_box0",
"voltic_battery:lv_bioreactor",
}
})
tech.register_battery_box2({
tier = "LV",
max_charge = 38000,
max_charge = 26000, -- 65% of 40,000
charge_rate = 1500,
discharge_rate = 4500,
charge_step = 500,
discharge_step = 800,
generate = 380,
generate = 26, -- 0.001 of max (Or 81.25% of a LV Bioreactor)
})

24
mv.lua
View File

@ -1,3 +1,23 @@
-- MV Bio Reactor
minetest.register_craft({
output = "voltic_battery:mv_bioreactor0",
recipe = {
{"group:leaves", "default:steelblock", "group:leaves"},
{"group:leaves", "voltic_battery:lv_bioreactor0", "group:leaves"},
{"group:leaves", "technic:mv_cable", "group:leaves"}
}
})
tech.register_bioreactor({
tier = "MV",
max_charge = 58,
charge_rate = 58,
discharge_rate = 58,
charge_step = 580,
discharge_step = 580,
generate = 58,
})
-- MV Battery box
minetest.register_craft({
@ -10,12 +30,12 @@ minetest.register_craft({
tech.register_battery_box2({
tier = "MV",
max_charge = 170000,
max_charge = 130000, -- 65% of 200,000
charge_rate = 20500,
discharge_rate = 80500,
charge_step = 2000,
discharge_step = 8000,
upgrade = 1,
tube = 1,
generate = 1700,
generate = 47, -- 0.001 of max (Or 81% of a MV Bioreactor)
})

View File

@ -92,7 +92,7 @@ function tech.register_battery_box2(data)
"size[8,9]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"list[context;src;3,1;1,1;]"..
"image[4,1;1,1;voltic_battery_reload.png]"..
"image[4,1;1,1;technic_battery_reload.png]"..
"list[context;dst;5,1;1,1;]"..
"label[0,0;"..S("Voltic %s Battery"):format(tier).."]"..
"label[3,0;"..S("Charge").."]"..
@ -328,4 +328,245 @@ function tech.register_battery_box2(data)
end -- End registration
-- Reuse the other functions
-- Adding code for bioreactor,
-- Simply reuse the code for the Voltic Battery except set's the capacity way down, make is so it generates more power
function tech.register_bioreactor(data)
local tier = data.tier
local ltier = string.lower(tier)
local self_charge = data.generate
-- Need to add some form of indicator internally to show how much we charge ourselves by.
-- Would be nice to have it actually display some numbers rather than nothing
local formspec =
"size[8,9]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"list[context;src;3,1;1,1;]"..
"image[4,1;1,1;technic_battery_reload.png]"..
"list[context;dst;5,1;1,1;]"..
"label[0,0;"..S("%s Bioreactor"):format(tier).."]"..
"label[3,0;"..S("Charge").."]"..
"label[5,0;"..S("Discharge").."]"..
"label[1,3;"..S("Power level").."]"..
"list[current_player;main;0,5;8,4;]"..
"listring[context;dst]"..
"listring[current_player;main]"..
"listring[context;src]"..
"listring[current_player;main]"
if digilines_path then
formspec = formspec.."button[0.6,3.7;2,1;edit_channel;edit Channel]"
end
if data.upgrade then
formspec = formspec..
"list[context;upgrade1;3.5,3;1,1;]"..
"list[context;upgrade2;4.5,3;1,1;]"..
"label[3.5,4;"..S("Upgrade Slots").."]"..
"listring[context;upgrade1]"..
"listring[current_player;main]"..
"listring[context;upgrade2]"..
"listring[current_player;main]"
end
local run = function(pos, node)
local below = minetest.get_node({x=pos.x, y=pos.y-1, z=pos.z})
local meta = minetest.get_meta(pos)
if not tech.is_tier_cable(below.name, tier) then
meta:set_string("infotext", S("%s Bioreactor Has No Network"):format(tier))
return
end
local eu_input = meta:get_int(tier.."_EU_input")
eu_input = eu_input + self_charge -- Append the self charge input
-- This should mean it always sees a charge input
-- I.E. With nothing drawing power we'd produce our normal 380 Eu (Voltic LV Battery),
-- But lets say that we have a power draw of 100, the battery will still charge up as we have 280 Eu surplus,
-- Or our power draw could be say 500, then the really cost would be -120 Eu (We'd then start consuming power if avalible)
local current_charge = meta:get_int("internal_EU_charge")
local EU_upgrade, tube_upgrade = 0, 0
if data.upgrade then
EU_upgrade, tube_upgrade = tech.handle_machine_upgrades(meta)
end
local max_charge = data.max_charge * (1 + EU_upgrade / 10)
-- Charge/discharge the battery with the input EUs
if eu_input >= 0 then
current_charge = math.min(current_charge + eu_input, max_charge)
else
current_charge = math.max(current_charge + eu_input, 0)
end
-- Charging/discharging tools here
local tool_full, tool_empty
current_charge, tool_full = tech.charge_tools(meta,
current_charge, data.charge_step)
current_charge, tool_empty = tech.discharge_tools(meta,
current_charge, data.discharge_step,
max_charge)
if data.tube then
local inv = meta:get_inventory()
tech.handle_machine_pipeworks(pos, tube_upgrade,
function(pos, x_velocity, z_velocity)
if tool_full and not inv:is_empty("src") then
tech.send_items(pos, x_velocity, z_velocity, "src")
elseif tool_empty and not inv:is_empty("dst") then
tech.send_items(pos, x_velocity, z_velocity, "dst")
end
end)
end
-- We allow batteries to charge on less than the demand
meta:set_int(tier.."_EU_demand",
math.min(data.charge_rate, max_charge - current_charge))
meta:set_int(tier.."_EU_supply",
math.min(data.discharge_rate, current_charge))
meta:set_int("internal_EU_charge", current_charge)
-- Select node textures
local charge_count = math.ceil((current_charge / max_charge) * 8)
charge_count = math.min(charge_count, 8)
charge_count = math.max(charge_count, 0)
local last_count = meta:get_float("last_side_shown")
if charge_count ~= last_count then
tech.swap_node(pos,"voltic_battery:"..ltier.."_bioreactor"..charge_count)
meta:set_float("last_side_shown", charge_count)
end
local charge_percent = math.floor(current_charge / max_charge * 100)
meta:set_string("formspec", formspec..add_on_off_buttons(meta, ltier, charge_percent))
-- Display the amount we are getting (Or net value)
local infotext = S("@1 Bioreactor: @2 / @3 (@4)", tier,
tech.EU_string(current_charge),
tech.EU_string(max_charge),
tech.EU_string(eu_input)) -- Could be negative
if eu_input == 0 then
infotext = S("%s Idle"):format(infotext)
end
meta:set_string("infotext", infotext)
end
for i = 0, 8 do
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
technic_machine=1, ["technic_"..ltier]=1}
if i ~= 0 then
groups.not_in_creative_inventory = 1
end
if data.tube then
groups.tubedevice = 1
groups.tubedevice_receiver = 1
end
-- Changed textures so they look different so a user doesn't need the info in the hud
local top_tex = "voltic_battery_"..ltier.."_bioreactor.png"
local front_tex = "voltic_battery_"..ltier.."_bioreactor.png"
local side_tex = "voltic_battery_"..ltier.."_bioreactor.png"
local bottom_tex = "voltic_battery_"..ltier.."_bioreactor.png"..cable_entry
minetest.register_node("voltic_battery:"..ltier.."_bioreactor"..i, {
description = S("%s Bioreactor"):format(tier),
tiles = {
top_tex,
bottom_tex,
side_tex,
side_tex,
side_tex,
front_tex},
groups = groups,
connect_sides = {"bottom"},
tube = data.tube and tube or nil,
paramtype2 = "facedir",
sounds = default.node_sound_wood_defaults(),
drop = "voltic_battery:"..ltier.."_bioreactor0",
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local EU_upgrade, tube_upgrade = 0, 0
if data.upgrade then
EU_upgrade, tube_upgrade = tech.handle_machine_upgrades(meta)
end
local max_charge = data.max_charge * (1 + EU_upgrade / 10)
local charge = meta:get_int("internal_EU_charge")
local cpercent = math.floor(charge / max_charge * 100)
local inv = meta:get_inventory()
meta:set_string("infotext", S("%s Bioreactor"):format(tier))
meta:set_string("formspec", formspec..add_on_off_buttons(meta, ltier, cpercent))
meta:set_string("channel", ltier.."_bioreactor"..minetest.pos_to_string(pos))
meta:set_int(tier.."_EU_demand", 0)
meta:set_int(tier.."_EU_supply", 0)
meta:set_int(tier.."_EU_input", 0)
meta:set_float("internal_EU_charge", 0)
inv:set_size("src", 1)
inv:set_size("dst", 1)
inv:set_size("upgrade1", 1)
inv:set_size("upgrade2", 1)
end,
can_dig = tech.machine_can_dig,
allow_metadata_inventory_put = tech.machine_inventory_put,
allow_metadata_inventory_take = tech.machine_inventory_take,
allow_metadata_inventory_move = tech.machine_inventory_move,
technic_run = run,
on_rotate = screwdriver.rotate_simple,
after_place_node = data.tube and pipeworks.after_place,
after_dig_node = tech.machine_after_dig_node,
on_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
if fields.edit_channel then
minetest.show_formspec(sender:get_player_name(),
"technic:battery_box_edit_channel"..minetest.pos_to_string(pos),
"field[channel;Digiline Channel;"..meta:get_string("channel").."]")
elseif fields["fs_helpers_cycling:0:split_src_stacks"]
or fields["fs_helpers_cycling:0:split_dst_stacks"]
or fields["fs_helpers_cycling:1:split_src_stacks"]
or fields["fs_helpers_cycling:1:split_dst_stacks"] then
meta = minetest.get_meta(pos)
if not pipeworks.may_configure(pos, sender) then return end
fs_helpers.on_receive_fields(pos, fields)
local EU_upgrade, tube_upgrade = 0, 0
if data.upgrade then
EU_upgrade, tube_upgrade = tech.handle_machine_upgrades(meta)
end
local max_charge = data.max_charge * (1 + EU_upgrade / 10)
local charge = meta:get_int("internal_EU_charge")
local cpercent = math.floor(charge / max_charge * 100)
meta:set_string("formspec", formspec..add_on_off_buttons(meta, ltier, cpercent))
end
end,
digiline = {
receptor = {action = function() end},
effector = {
action = function(pos, node, channel, msg)
if msg ~= "GET" and msg ~= "get" then
return
end
local meta = minetest.get_meta(pos)
if channel ~= meta:get_string("channel") then
return
end
local inv = meta:get_inventory()
digilines.receptor_send(pos, digilines.rules.default, channel, {
demand = meta:get_int(tier.."_EU_demand"),
supply = meta:get_int(tier.."_EU_supply"),
input = meta:get_int(tier.."_EU_input"),
charge = meta:get_int("internal_EU_charge"),
max_charge = data.max_charge * (1 + tech.handle_machine_upgrades(meta) / 10),
src = inv:get_stack("src", 1):to_table(),
dst = inv:get_stack("dst", 1):to_table(),
upgrade1 = inv:get_stack("upgrade1", 1):to_table(),
upgrade2 = inv:get_stack("upgrade2", 1):to_table()
})
end
},
},
})
end
-- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power
for i = 0, 8 do
tech.register_machine(tier, "voltic_battery:"..ltier.."_bioreactor"..i, tech.producer)
end
end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 421 B

After

Width:  |  Height:  |  Size: 424 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 525 B

After

Width:  |  Height:  |  Size: 492 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 557 B

After

Width:  |  Height:  |  Size: 524 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 661 B

After

Width:  |  Height:  |  Size: 668 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 668 B

After

Width:  |  Height:  |  Size: 679 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 318 B

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 273 B

After

Width:  |  Height:  |  Size: 277 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 668 B

After

Width:  |  Height:  |  Size: 683 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 320 B

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 273 B

After

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 273 B

After

Width:  |  Height:  |  Size: 277 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B