This commit is contained in:
pagliaccio 2013-07-13 13:19:07 +02:00
commit ad0bef9d90
4 changed files with 530 additions and 515 deletions

View File

@ -1,4 +1,9 @@
--- HV battery box
local max_charge = 1500000
local max_charge_rate = 3000
local max_discharge_rate = 5000
-- HV battery box
minetest.register_craft({
output = 'technic:hv_battery_box 1',
recipe = {
@ -6,7 +11,7 @@ minetest.register_craft({
{'technic:mv_battery_box', 'technic:hv_transformer', 'technic:mv_battery_box'},
{'', 'technic:hv_cable', ''},
}
})
})
local battery_box_formspec =
"invsize[8,9;]"..
@ -20,23 +25,23 @@ local battery_box_formspec =
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node(
"technic:hv_battery_box", {
minetest.register_node("technic:hv_battery_box", {
description = "HV Battery Box",
tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png",
"technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png",
"technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png",
"technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
drop="technic:hv_battery_box",
drop = "technic:hv_battery_box",
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
meta:set_string("infotext", "HV Battery Box")
meta:set_float("technic_hv_power_machine", 1)
meta:set_string("formspec", battery_box_formspec)
meta:set_int("HV_EU_demand", 0) -- How much can this node charge
meta:set_int("HV_EU_supply", 0) -- How much can this node discharge
meta:set_int("HV_EU_input", 0) -- How much power is this machine getting.
meta:set_int("HV_EU_demand", 0) -- How much this node can charge
meta:set_int("HV_EU_supply", 0) -- How much this node can discharge
meta:set_int("HV_EU_input", 0) -- How much power this machine is getting.
meta:set_float("internal_EU_charge", 0)
inv:set_size("src", 1)
inv:set_size("dst", 1)
@ -51,15 +56,17 @@ minetest.register_node(
return true
end
end,
})
})
for i=1,8,1 do
minetest.register_node(
"technic:hv_battery_box"..i,
{description = "HV Battery Box",
tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_hv_battery_box_side0.png^technic_power_meter"..i..".png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
for i = 1,8,1 do
minetest.register_node("technic:hv_battery_box"..i, {
description = "HV Battery Box",
tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
paramtype="light",
light_source=9,
@ -79,98 +86,98 @@ end
local power_tools = technic.HV_power_tools
local charge_HV_tools = function(meta, charge)
local function charge_HV_tools(meta, charge)
--charge registered power tools
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
if not inv:is_empty("src") then
local srcstack = inv:get_stack("src", 1)
local src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
local src_item = srcstack:to_table()
local src_meta = get_item_meta(src_item["metadata"])
local toolname = src_item["name"]
if power_tools[toolname] ~= nil then
-- Set meta data for the tool if it didn't do it itself :-(
src_meta=get_item_meta(src_item["metadata"])
src_meta = get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_hv_power_tool"]=true
src_meta["charge"]=0
src_meta = {}
src_meta["technic_hv_power_tool"] = true
src_meta["charge"] = 0
else
if src_meta["technic_hv_power_tool"]==nil then
src_meta["technic_hv_power_tool"]=true
src_meta["charge"]=0
if src_meta["technic_hv_power_tool"] == nil then
src_meta["technic_hv_power_tool"] = true
src_meta["charge"] = 0
end
end
-- Do the charging
local item_max_charge = power_tools[toolname]
local load = src_meta["charge"]
local load_step = 1000 -- how much to charge per tick
if load<item_max_charge and charge>0 then
if charge-load_step<0 then load_step=charge end
if load+load_step>item_max_charge then load_step=item_max_charge-load end
load=load+load_step
charge=charge-load_step
technic.set_RE_wear(src_item,load,item_max_charge)
src_meta["charge"] = load
local tool_charge = src_meta["charge"]
local charge_step = 1000 -- how much to charge per tick
if tool_charge < item_max_charge and tool_charge > 0 then
if tool_charge - charge_step < 0 then
charge_step = charge
end
if tool_charge + charge_step > item_max_charge then
charge_step = item_max_charge - tool_charge
end
tool_charge = tool_charge + charge_step
charge = charge - charge_step
technic.set_RE_wear(src_item, tool_charge, item_max_charge)
src_meta["charge"] = tool_charge
src_item["metadata"] = set_item_meta(src_meta)
inv:set_stack("src", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
end
local discharge_HV_tools = function(meta, charge, max_charge)
local function discharge_HV_tools(meta, charge, max_charge)
-- discharging registered power tools
local inv = meta:get_inventory()
if inv:is_empty("dst") == false then
if not inv:is_empty("dst") then
srcstack = inv:get_stack("dst", 1)
src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
src_item = srcstack:to_table()
local src_meta = get_item_meta(src_item["metadata"])
local toolname = src_item["name"]
if power_tools[toolname] ~= nil then
-- Set meta data for the tool if it didn't do it itself :-(
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_hv_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_hv_power_tool"]==nil then
src_meta["technic_hv_power_tool"]=true
src_meta["charge"]=0
end
src_meta = get_item_meta(src_item["metadata"]) or {}
if src_meta["technic_hv_power_tool"] == nil then
src_meta["technic_hv_power_tool"] = true
src_meta["charge"] = 0
end
-- Do the discharging
local item_max_charge = power_tools[toolname]
local load = src_meta["charge"]
local load_step = 4000 -- how much to discharge per tick
if load>0 and charge<max_charge then
if charge+load_step>max_charge then load_step=max_charge-charge end
if load-load_step<0 then load_step=load end
load=load-load_step
charge=charge+load_step
technic.set_RE_wear(src_item,load,item_max_charge)
src_meta["charge"]=load
src_item["metadata"]=set_item_meta(src_meta)
local tool_charge = src_meta["charge"]
local charge_step = 4000 -- how much to discharge per tick
if tool_charge > 0 and charge < max_charge then
if tool_charge + charge_step > max_charge then
charge_step = max_charge - charge
end
if tool_charge - charge_step < 0 then
charge_step = charge
end
tool_charge = tool_charge - charge_step
charge = charge + charge_step
technic.set_RE_wear(src_item, tool_charge, item_max_charge)
src_meta["charge"] = tool_charge
src_item["metadata"] = set_item_meta(src_meta)
inv:set_stack("dst", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
end
minetest.register_abm(
{nodenames = {"technic:hv_battery_box","technic:hv_battery_box1","technic:hv_battery_box2","technic:hv_battery_box3","technic:hv_battery_box4",
"technic:hv_battery_box5","technic:hv_battery_box6","technic:hv_battery_box7","technic:hv_battery_box8"
},
minetest.register_abm({
nodenames = {"technic:hv_battery_box", "technic:hv_battery_box1", "technic:hv_battery_box2",
"technic:hv_battery_box3", "technic:hv_battery_box4", "technic:hv_battery_box5",
"technic:hv_battery_box6", "technic:hv_battery_box7", "technic:hv_battery_box8"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local max_charge = 1500000 -- Set maximum charge for the device here
local max_charge_rate = 3000 -- Set maximum rate of charging
local max_discharge_rate = 5000 -- Set maximum rate of discharging (16000)
local eu_input = meta:get_int("HV_EU_input")
local current_charge = meta:get_int("internal_EU_charge") -- Battery charge right now
@ -178,10 +185,10 @@ minetest.register_abm(
technic.switching_station_timeout_count(pos, "HV")
-- Charge/discharge the battery with the input EUs
if eu_input >=0 then
current_charge = math.min(current_charge+eu_input, max_charge)
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)
current_charge = math.max(current_charge + eu_input, 0)
end
-- Charging/discharging tools here
@ -195,24 +202,27 @@ minetest.register_abm(
meta:set_int("HV_EU_supply", math.min(max_discharge_rate, current_charge))
meta:set_int("internal_EU_charge", current_charge)
--dprint("BA: input:"..eu_input.." supply="..meta:get_int("HV_EU_supply").." demand="..meta:get_int("HV_EU_demand").." current:"..current_charge)
-- Select node textures
local i=math.ceil((current_charge/max_charge)*8)
if i > 8 then i = 8 end
local j = meta:get_float("last_side_shown")
if i~=j then
if i>0 then hacky_swap_node(pos,"technic:hv_battery_box"..i)
elseif i==0 then hacky_swap_node(pos,"technic:hv_battery_box") end
meta:set_float("last_side_shown",i)
local charge_count = math.ceil((current_charge / max_charge) * 8)
if charge_count > 8 then
charge_count = 8
end
local last_count = meta:get_float("last_side_shown")
if charge_count ~= last_count then
if charge_count > 0 then
hacky_swap_node(pos,"technic:hv_battery_box"..charge_count)
else
hacky_swap_node(pos,"technic:hv_battery_box")
end
meta:set_float("last_side_shown", charge_count)
end
local load = math.floor(current_charge/max_charge * 100)
local charge_percent = math.floor(current_charge / max_charge * 100)
meta:set_string("formspec",
battery_box_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"
)
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"
..charge_percent..":technic_power_meter_fg.png]")
if eu_input == 0 then
meta:set_string("infotext", "HV Battery box: "..current_charge.."/"..max_charge.." (idle)")
@ -220,7 +230,7 @@ minetest.register_abm(
meta:set_string("infotext", "HV Battery box: "..current_charge.."/"..max_charge)
end
end
})
})
-- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power

View File

@ -5,8 +5,8 @@
-- Forcefield Generator is a HV machine.
-- How expensive is the generator? Leaves room for upgrades lowering the power drain?
local forcefield_power_drain = 10 -- default 10
local forcefield_update_interval = 1
local forcefield_power_drain = 10
local forcefield_step_interval = 1
minetest.register_craft({
output = 'technic:forcefield_emitter_off',
@ -17,65 +17,63 @@ minetest.register_craft({
}
})
-- Idea: Let forcefields have different colors by upgrade slot.
-- Idea: Let forcefields add up by detecting if one hits another.
-- ___ __
-- / \/ \
-- | |
-- \___/\___/
--
local function add_forcefield(pos, range)
for x=-range,range do
for y=-range,range do
for z=-range,range do
if ((x*x+y*y+z*z) <= (range * range + range)) then
if ((range-1) * (range-1) + (range-1) <= x*x+y*y+z*z) then
local np={x=pos.x+x,y=pos.y+y,z=pos.z+z}
local n = minetest.env:get_node(np).name
if (n == "air") then
minetest.env:add_node(np, {name = "technic:forcefield"})
end
end
end
end
end
end
return true
end
local function remove_forcefield(p, range)
for x=-range,range do
for y=-range,range do
for z=-range,range do
if ((x*x+y*y+z*z) <= (range * range + range)) then
if ((range-1) * (range-1) + (range-1) <= x*x+y*y+z*z) then
local np={x=p.x+x,y=p.y+y,z=p.z+z}
local n = minetest.env:get_node(np).name
if (n == "technic:forcefield") then
minetest.env:remove_node(np)
end
end
end
local function update_forcefield(pos, range, active)
local vm = VoxelManip()
local p1 = {x = pos.x-range, y = pos.y-range, z = pos.z-range}
local p2 = {x = pos.x+range, y = pos.y+range, z = pos.z+range}
local MinEdge, MaxEdge = vm:read_from_map(p1, p2)
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
local data = vm:get_data()
local c_air = minetest.get_content_id("air")
local c_field = minetest.get_content_id("technic:forcefield")
for z=-range, range do
for y=-range, range do
local vi = area:index(pos.x+(-range), pos.y+y, pos.z+z)
for x=-range, range do
if x*x+y*y+z*z <= range * range + range and
x*x+y*y+z*z >= (range-1) * (range-1) + (range-1) and
((active and data[vi] == c_air) or ((not active) and data[vi] == c_field)) then
if active then
data[vi] = c_field
else
data[vi] = c_air
end
end
vi = vi + 1
end
end
end
vm:set_data(data)
vm:update_liquids()
vm:write_to_map()
vm:update_map()
end
local get_forcefield_formspec = function(range)
-- return "invsize[8,9;]".. (if upgrades added later - colors for instance)
return "invsize[3,4;]"..
"label[0,0;Forcefield emitter]"..
"label[1,1;Range]"..
"label[1,2;"..range.."]"..
"button[0,2;1,1;subtract;-]"..
"button[2,2;1,1;add;+]"..
"button[0,3;3,1;toggle;Enable/Disable]" -- ..
-- "list[current_player;main;0,5;8,4;]"
"button[0,3;3,1;toggle;Enable/Disable]"
end
local forcefield_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.env:get_meta(pos)
local range = meta:get_int("range")
if fields.add then range = range + 1 end
if fields.subtract then range = range - 1 end
if fields.toggle then
@ -85,19 +83,20 @@ local forcefield_receive_fields = function(pos, formname, fields, sender)
meta:set_int("enabled", 1)
end
end
-- Smallest field is 5. Anything less is asking for trouble.
-- Largest is 20. It is a matter of pratical node handling.
if range < 5 then range = 5 end
if range > 20 then range = 20 end
if range <= 20 and range >= 5 and meta:get_int("range") ~= range then
remove_forcefield(pos, meta:get_int("range"))
update_forcefield(pos, meta:get_int("range"), false)
meta:set_int("range", range)
meta:set_string("formspec", get_forcefield_formspec(range))
end
end
end
local forcefield_check = function(pos)
local function forcefield_step(pos)
local meta = minetest.env:get_meta(pos)
local node = minetest.env:get_node(pos)
local eu_input = meta:get_int("HV_EU_input")
@ -107,53 +106,49 @@ local forcefield_check = function(pos)
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "HV")
local power_requirement
local power_requirement = 0
if enabled == 1 then
power_requirement = math.floor(4*math.pi*math.pow(meta:get_int("range"), 2)) * forcefield_power_drain
power_requirement = math.floor(
4 * math.pi * math.pow(meta:get_int("range"), 2)
) * forcefield_power_drain
else
power_requirement = eu_demand
end
if eu_input == 0 then
meta:set_string("infotext", "Forcefield Generator Unpowered")
meta:set_int("HV_EU_demand", 100)
meta:set_int("enabled", 0)
if meta:get_int("enabled") == 0 then
if node.name == "technic:forcefield_emitter_on" then
remove_forcefield(pos, meta:get_int("range"))
update_forcefield(pos, meta:get_int("range"), false)
hacky_swap_node(pos, "technic:forcefield_emitter_off")
meta:set_int("HV_EU_demand", 100)
meta:set_string("infotext", "Forcefield Generator Disabled")
end
elseif eu_input < power_requirement then
meta:set_string("infotext", "Forcefield Generator Unpowered")
if node.name == "technic:forcefield_emitter_on" then
update_forcefield(pos, meta:get_int("range"), false)
hacky_swap_node(pos, "technic:forcefield_emitter_off")
end
elseif eu_input == power_requirement then
if meta:get_int("enabled") == 1 then
elseif eu_input >= power_requirement then
if node.name == "technic:forcefield_emitter_off" then
hacky_swap_node(pos, "technic:forcefield_emitter_on")
meta:set_string("infotext", "Forcefield Generator Active")
add_forcefield(pos, meta:get_int("range"))
else
-- Range updated. Move the forcefield.
add_forcefield(pos, meta:get_int("range"))
end
else
if node.name == "technic:forcefield_emitter_on" then
remove_forcefield(pos, meta:get_int("range"))
hacky_swap_node(pos, "technic:forcefield_emitter_off")
meta:set_int("HV_EU_demand", 100)
meta:set_string("infotext", "Forcefield Generator Idle")
update_forcefield(pos, meta:get_int("range"), true)
end
end
else
meta:set_int("HV_EU_demand", power_requirement)
end
return true
end
end
local mesecons = {effector = {
local mesecons = {
effector = {
action_on = function(pos, node)
minetest.env:get_meta(pos):set_int("enabled", 0)
end,
action_off = function(pos, node)
minetest.env:get_meta(pos):set_int("enabled", 1)
end
}}
}
}
minetest.register_node("technic:forcefield_emitter_off", {
description = "Forcefield emitter",
@ -161,10 +156,10 @@ minetest.register_node("technic:forcefield_emitter_off", {
tiles = {"technic_forcefield_emitter_off.png"},
is_ground_content = true,
groups = {cracky = 1},
on_timer = forcefield_check,
on_timer = forcefield_step,
on_receive_fields = forcefield_receive_fields,
on_construct = function(pos)
minetest.env:get_node_timer(pos):start(forcefield_update_interval)
minetest.env:get_node_timer(pos):start(forcefield_step_interval)
local meta = minetest.env:get_meta(pos)
meta:set_float("technic_hv_power_machine", 1)
meta:set_int("HV_EU_input", 0)
@ -183,10 +178,10 @@ minetest.register_node("technic:forcefield_emitter_on", {
is_ground_content = true,
groups = {cracky = 1, not_in_creative_inventory=1},
drop='"technic:forcefield_emitter_off" 1',
on_timer = forcefield_check,
on_timer = forcefield_step,
on_receive_fields = forcefield_receive_fields,
on_construct = function(pos)
minetest.env:get_node_timer(pos):start(forcefield_update_interval)
minetest.env:get_node_timer(pos):start(forcefield_step_interval)
local meta = minetest.env:get_meta(pos)
-- meta:set_float("technic_hv_power_machine", 1)
-- meta:set_float("HV_EU_input", 0)
@ -197,7 +192,7 @@ minetest.register_node("technic:forcefield_emitter_on", {
-- meta:set_string("infotext", "Forcefield emitter");
end,
on_dig = function(pos, node, digger)
remove_forcefield(pos, minetest.env:get_meta(pos):get_int("range"))
update_forcefield(pos, minetest.env:get_meta(pos):get_int("range"), false)
return minetest.node_dig(pos, node, digger)
end,
mesecons = mesecons
@ -208,9 +203,17 @@ minetest.register_node("technic:forcefield", {
sunlight_propagates = true,
drop = '',
light_source = 8,
tiles = {{name="technic_forcefield_animated.png", animation={type="vertical_frames", aspect_w=16, aspect_h=16, length=2.0}}},
tiles = {{
name = "technic_forcefield_animated.png",
animation = {
type = "vertical_frames",
aspect_w=16,
aspect_h=16,
length=2.0,
},
}},
is_ground_content = true,
groups = {not_in_creative_inventory=1, unbreakable=1},
groups = { not_in_creative_inventory=1, unbreakable=1 },
paramtype = "light",
drawtype = "nodebox",
node_box = { --hacky way to get the field blue and not see through the ground
@ -221,5 +224,5 @@ minetest.register_node("technic:forcefield", {
},
})
technic.register_HV_machine("technic:forcefield_emitter_on","RE")
technic.register_HV_machine("technic:forcefield_emitter_off","RE")
technic.register_HV_machine("technic:forcefield_emitter_on", "RE")
technic.register_HV_machine("technic:forcefield_emitter_off", "RE")

View File

@ -5,29 +5,30 @@
--
-- The nuclear reactor core needs water and a protective shield to work.
-- This is checked now and then and if the machine is tampered with... BOOM!
local burn_ticks = 24*60 -- [minutes]. How many minutes does the power plant burn per serving?
local power_supply = 10000 -- [HV] EUs
local fuel_type = "technic:enriched_uranium" -- This reactor burns this stuff
local fuel_type = "technic:enriched_uranium" -- The reactor burns this stuff
-- FIXME: recipe must make more sense like a rod recepticle, steam chamber, HV generator?
minetest.register_craft(
{output = 'technic:hv_nuclear_reactor_core',
minetest.register_craft({
output = 'technic:hv_nuclear_reactor_core',
recipe = {
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
{'technic:stainless_steel_ingot', '', 'technic:stainless_steel_ingot'},
{'technic:stainless_steel_ingot', 'technic:hv_cable', 'technic:stainless_steel_ingot'},
}
})
})
minetest.register_craftitem(
"technic:hv_nuclear_reactor_core",
{description = "Uranium Rod Driven HV Reactor",
minetest.register_craftitem("technic:hv_nuclear_reactor_core",{
description = "Uranium Rod Driven HV Reactor",
stack_max = 1,
})
})
local generator_formspec =
"invsize[8,9;]"..
-- "image[0,0;5,5;technic_generator_menu.png]"..
--"image[0,0;5,5;technic_generator_menu.png]"..
"label[0,0;Nuclear Reactor Rod Compartment]"..
"list[current_name;src;2,1;3,2;]"..
"list[current_player;main;0,5;8,4;]"
@ -52,14 +53,12 @@ local nodebox = {
{ -0.303, -0.303, -0.397, 0.303, 0.303, 0.397 },
}
minetest.register_node(
"technic:hv_nuclear_reactor_core",
{description = "Nuclear Reactor",
minetest.register_node("technic:hv_nuclear_reactor_core", {
description = "Nuclear Reactor",
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
-- paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
drawtype="nodebox",
@ -89,15 +88,14 @@ minetest.register_node(
return true
end
end,
})
})
minetest.register_node(
"technic:hv_nuclear_reactor_core_active",
{description = "Uranium Rod Driven HV Reactor",
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
-- paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
minetest.register_node("technic:hv_nuclear_reactor_core_active", {
description = "Uranium Rod Driven HV Reactor",
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
drop="technic:hv_nuclear_reactor_core",
@ -118,7 +116,7 @@ minetest.register_node(
return true
end
end,
})
})
local check_reactor_structure = function(pos)
-- The reactor consists of an 11x11x11 cube structure
@ -134,74 +132,81 @@ local check_reactor_structure = function(pos)
-- CCSSS|SSSCC
-- CCCCC|CCCCC
-- C = Concrete, S = Stainless Steel, W = water node (not floating), #=reactor core, |=HV cable
-- The man-hole and the HV cable is only in the middle.
local water_nodes = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y-1, z=pos.z-1},
-- The man-hole and the HV cable is only in the middle
-- The man-hole is optional
local source_water_nodes = minetest.find_nodes_in_area(
{x=pos.x-1, y=pos.y-1, z=pos.z-1},
{x=pos.x+1, y=pos.y+1, z=pos.z+1},
"default:water_source")
--print("Water ( 25):"..#water_nodes)
if #water_nodes ~= 25 then
--print("Water supply defect")
return 0
local flowing_water_nodes = minetest.find_nodes_in_area(
{x=pos.x-1, y=pos.y-1, z=pos.z-1},
{x=pos.x+1, y=pos.y+1, z=pos.z+1},
"default:water_flowing")
if not ((#source_water_nodes + #flowing_water_nodes) >= 25) then
return false
end
local inner_shield_nodes = minetest.find_nodes_in_area({x=pos.x-2, y=pos.y-2, z=pos.z-2},
local inner_shield_nodes = minetest.find_nodes_in_area(
{x=pos.x-2, y=pos.y-2, z=pos.z-2},
{x=pos.x+2, y=pos.y+2, z=pos.z+2},
"technic:concrete")
--print("Concrete 1 ( 96):"..#inner_shield_nodes)
if #inner_shield_nodes ~= 96 then
--print("Inner shield defect")
return 0
if not (#inner_shield_nodes >= 96) then
return false
end
local steel_shield_nodes = minetest.find_nodes_in_area({x=pos.x-3, y=pos.y-3, z=pos.z-3},
local steel_shield_nodes = minetest.find_nodes_in_area(
{x=pos.x-3, y=pos.y-3, z=pos.z-3},
{x=pos.x+3, y=pos.y+3, z=pos.z+3},
"default:steelblock")
--print("Steel ( 216):"..#steel_shield_nodes)
if #steel_shield_nodes ~= 216 then
--print("Steel shield defect")
return 0
if not (#steel_shield_nodes >= 216) then
return false
end
local outer_shield_nodes = minetest.find_nodes_in_area({x=pos.x-5, y=pos.y-5, z=pos.z-5},
local outer_shield_nodes = minetest.find_nodes_in_area(
{x=pos.x-5, y=pos.y-5, z=pos.z-5},
{x=pos.x+5, y=pos.y+5, z=pos.z+5},
"technic:concrete")
--print("Concrete 2 (1080):"..#outer_shield_nodes)
if #outer_shield_nodes ~= (984+#inner_shield_nodes) then
--print("Outer shield defect")
return 0
end
return 1
if not (#outer_shield_nodes >= (984 + #inner_shield_nodes)) then
return false
end
return true
end
local explode_reactor = function(pos)
print("BOOM A reactor exploded!")
end
end
minetest.register_abm(
{nodenames = {"technic:hv_nuclear_reactor_core","technic:hv_nuclear_reactor_core_active"},
minetest.register_abm({
nodenames = {"technic:hv_nuclear_reactor_core", "technic:hv_nuclear_reactor_core_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local burn_time= meta:get_int("burn_time")
local burn_time = meta:get_int("burn_time")
-- If more to burn and the energy produced was used: produce some more
if burn_time>0 then
if burn_time > 0 then
if not check_reactor_structure(pos) then
explode_reactor(pos)
end
if meta:get_int("HV_EU_supply") == 0 then
-- We did not use the power
meta:set_int("HV_EU_supply", power_sypply)
meta:set_int("HV_EU_supply", power_supply)
else
burn_time = burn_time - 1
meta:set_int("burn_time",burn_time)
meta:set_string("infotext", "Nuclear Reactor Core ("..math.floor(burn_time/(burn_ticks*60)*100).."%)")
meta:set_int("burn_time", burn_time)
local percent = math.floor(burn_time / (burn_ticks * 60) * 100)
meta:set_string("infotext", "Nuclear Reactor Core ("..percent.."%)")
end
end
-- Burn another piece of coal
if burn_time==0 then
if burn_time <= 0 then
local inv = meta:get_inventory()
local correct_fuel_count = 0
if inv:is_empty("src") == false then
local srclist= inv:get_list("src")
if not inv:is_empty("src") then
local srclist = inv:get_list("src")
for _, srcstack in pairs(srclist) do
if srcstack then
local src_item=srcstack:to_table()
@ -212,18 +217,15 @@ minetest.register_abm(
end
-- Check that the reactor is complete as well as the correct number of correct fuel
if correct_fuel_count == 6 then
if check_reactor_structure(pos) == 1 then
burn_time=burn_ticks*60
meta:set_int("burn_time",burn_time)
if not check_reactor_structure(pos) then
burn_time = burn_ticks * 60
meta:set_int("burn_time", burn_time)
hacky_swap_node (pos,"technic:hv_nuclear_reactor_core_active")
meta:set_int("HV_EU_supply", power_supply)
for idx, srcstack in pairs(srclist) do
srcstack:take_item()
inv:set_stack("src", idx, srcstack)
end
else
-- BOOM!!! (the reactor was compromised and it should explode after some time) TNT mod inspired??
explode_reactor(pos)
end
else
meta:set_int("HV_EU_supply", 0)
@ -232,12 +234,12 @@ minetest.register_abm(
end
-- Nothing left to burn
if burn_time==0 then
if burn_time == 0 then
meta:set_string("infotext", "Nuclear Reactor Core (idle)")
hacky_swap_node (pos,"technic:hv_nuclear_reactor_core")
hacky_swap_node(pos,"technic:hv_nuclear_reactor_core")
end
end
})
})
technic.register_HV_machine ("technic:hv_nuclear_reactor_core","PR")
technic.register_HV_machine ("technic:hv_nuclear_reactor_core_active","PR")

View File

@ -92,7 +92,7 @@ if z2==1 then temp_z2=str_z2 end
minetest.register_node("technic:hv_cable"..count, {
description = "Gigh Voltage Copper Cable",
description = "High Voltage Copper Cable",
tiles = {"technic_hv_cable.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),