Added Coal Driven Generator

This commit is contained in:
Maciej Kasatkin 2012-09-02 05:46:20 +02:00
parent 02a9acdc3c
commit ad8932ac99
3 changed files with 149 additions and 0 deletions

View File

@ -510,6 +510,7 @@ meta = minetest.env:get_meta(pos1)
if meta:get_float("cablelike")==1 then new_node_added=add_new_cable_node(LV_nodes,pos1) end
if minetest.env:get_node(pos1).name == "technic:solar_panel" then new_node_added=add_new_cable_node(PR_nodes,pos1) end
if minetest.env:get_node(pos1).name == "technic:generator" then new_node_added=add_new_cable_node(PR_nodes,pos1) end
if minetest.env:get_node(pos1).name == "technic:generator_active" then new_node_added=add_new_cable_node(PR_nodes,pos1) end
if minetest.env:get_node(pos1).name == "technic:electric_furnace" then new_node_added=add_new_cable_node(RE_nodes,pos1) end
if minetest.env:get_node(pos1).name == "technic:electric_furnace_active" then new_node_added=add_new_cable_node(RE_nodes,pos1) end
if minetest.env:get_node(pos1).name == "technic:tool_workshop" then new_node_added=add_new_cable_node(RE_nodes,pos1) end

147
generator.lua Normal file
View File

@ -0,0 +1,147 @@
minetest.register_alias("generator", "technic:generator")
minetest.register_alias("generator", "technic:generator_active")
minetest.register_craft({
output = 'technic:generator',
recipe = {
{'default:stone', 'default:stone', 'default:stone'},
{'default:stone', '', 'default:stone'},
{'default:stone', 'moreores:copper_ingot', 'default:stone'},
}
})
minetest.register_craftitem("technic:generator", {
description = "Coal Driven Generator",
stack_max = 99,
})
generatorr_formspec =
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"label[0,0;Generator]"..
"label[1,3;Power level]"..
"list[current_name;src;3,1;1,1;]"..
"image[4,1;1,1;default_furnace_fire_bg.png]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:generator", {
description = "Coal Driven Generator",
tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png",
"technic_generator_side.png", "technic_generator_side.png", "technic_generator_front.png"},
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
technic_power_machine=1,
internal_EU_buffer=0;
internal_EU_buffer_size=5000;
burn_time=0;
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Generator")
meta:set_float("technic_power_machine", 1)
meta:set_float("internal_EU_buffer", 0)
meta:set_float("internal_EU_buffer_size", 5000)
meta:set_string("formspec", generator_formspec)
meta:set_float("burn_time", 0)
local inv = meta:get_inventory()
inv:set_size("src", 1)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") then
return false
end
return true
end,
})
minetest.register_node("technic:generator_active", {
description = "Coal Driven Generator",
tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png",
"technic_generator_side.png", "technic_generator_side.png", "technic_generator_front_active.png"},
paramtype2 = "facedir",
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:generator",
technic_power_machine=1,
internal_EU_buffer=0;
internal_EU_buffer_size=0;
burn_time=0;
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") then
return false
end
return true
end,
})
minetest.register_abm({
nodenames = {"technic:generator","technic:generator_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_float("burn_time")
local charge= meta:get_float("internal_EU_buffer")
local max_charge= meta:get_float("internal_EU_buffer_size")
local burn_charge=200
if burn_time>0 then
if charge+burn_charge>max_charge then
burn_charge=max_charge-charge
end
if burn_charge>0 then
burn_time=burn_time-1
meta:set_float("burn_time",burn_time)
charge=charge+burn_charge
meta:set_float("internal_EU_buffer",charge)
end
end
if burn_time==0 then
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
local srcstack = inv:get_stack("src", 1)
src_item=srcstack:to_table()
if src_item["name"]== "default:coal_lump" then
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
burn_time=16
meta:set_float("burn_time",burn_time)
hacky_swap_node (pos,"technic:generator_active")
end
end
end
local load = math.floor((charge/max_charge)*100)
local percent = math.floor((burn_time/16)*100)
meta:set_string("formspec",
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"..
"label[0,0;Generator]"..
"label[1,3;Power level]"..
"list[current_name;src;3,1;1,1;]"..
"image[4,1;1,1;default_furnace_fire_bg.png^[lowpart:"..
(percent)..":default_furnace_fire_fg.png]"..
"list[current_player;main;0,5;8,4;]"
)
if burn_time==0 then
hacky_swap_node (pos,"technic:generator")
end
end
})

View File

@ -31,6 +31,7 @@ dofile(minetest.get_modpath("technic").."/grinder.lua")
dofile(minetest.get_modpath("technic").."/mining_laser_mk1.lua")
--dofile(minetest.get_modpath("technic").."/project_table.lua")
--dofile(minetest.get_modpath("technic").."/injector.lua")
dofile(minetest.get_modpath("technic").."/generator.lua")
dofile(minetest.get_modpath("technic").."/solar_panel.lua")