Merge pull request #38 from kpoppel/master

Changed the way energy is distributed.

This merge will likely require machines to be dug up and placed again.
Added is less server load, electrical lighting, up/down conversion.
It can all be reduxed to a songle ABM if we like to.
This commit is contained in:
kpoppel 2013-07-01 15:19:06 -07:00
commit 053fa59739
49 changed files with 4301 additions and 2978 deletions

View File

@ -1,12 +1,14 @@
-- LV Alloy furnace
minetest.register_craft({ minetest.register_craft({
output = 'technic:coal_alloy_furnace', output = 'technic:coal_alloy_furnace',
recipe = { recipe = {
{'default:brick', 'default:brick', 'default:brick'}, {'default:brick', 'default:brick', 'default:brick'},
{'default:brick', '', 'default:brick'}, {'default:brick', '', 'default:brick'},
{'default:brick', 'default:brick', 'default:brick'}, {'default:brick', 'default:brick', 'default:brick'},
} }
}) })
-- FIXME: kpoppel: I'd like to introduce an induction heating element here...
minetest.register_craft({ minetest.register_craft({
output = 'technic:alloy_furnace', output = 'technic:alloy_furnace',
recipe = { recipe = {
@ -16,193 +18,178 @@ minetest.register_craft({
} }
}) })
-- LV alloy furnace local alloy_furnace_formspec =
"invsize[8,9;]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;src2;3,2;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"..
"label[0,0;Electric Alloy Furnace]"
alloy_furnace_formspec = minetest.register_node(
"invsize[8,9;]".. "technic:alloy_furnace",
"image[1,1;1,2;technic_power_meter_bg.png]".. {
"list[current_name;src;3,1;1,1;]".. description = "Electric alloy furnace",
"list[current_name;src2;3,2;1,1;]".. tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png",
"list[current_name;dst;5,1;2,2;]".. "technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front.png"},
"list[current_player;main;0,5;8,4;]".. paramtype2 = "facedir",
"label[0,0;Electric Alloy Furnace]".. groups = {cracky=2},
"label[1,3;Power level]" legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
minetest.register_node("technic:alloy_furnace", { on_construct = function(pos)
description = "Electric alloy furnace", local meta = minetest.env:get_meta(pos)
tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png", meta:set_string("infotext", "Electric Alloy furnace")
"technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front.png"}, meta:set_float("technic_power_machine", 1)
paramtype2 = "facedir", meta:set_string("formspec", alloy_furnace_formspec)
groups = {cracky=2}, local inv = meta:get_inventory()
legacy_facedir_simple = true, inv:set_size("src", 1)
sounds = default.node_sound_stone_defaults(), inv:set_size("src2", 1)
technic_power_machine=1, inv:set_size("dst", 4)
internal_EU_buffer=0; end,
interal_EU_buffer_size=2000; can_dig = function(pos,player)
on_construct = function(pos) local meta = minetest.env:get_meta(pos);
local meta = minetest.env:get_meta(pos) local inv = meta:get_inventory()
meta:set_float("technic_power_machine", 1) if not inv:is_empty("src") or not inv:is_empty("src2") or not inv:is_empty("dst") then
meta:set_string("formspec", alloy_furnace_formspec) minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
meta:set_string("infotext", "Electric Alloy furnace") return false
local inv = meta:get_inventory() else
inv:set_size("src", 1) return true
inv:set_size("src2", 1) end
inv:set_size("dst", 4) end,
local EU_used = 0
local furnace_is_cookin = 0
local cooked = nil
meta:set_float("internal_EU_buffer",0)
meta:set_float("internal_EU_buffer_size",2000)
meta:set_float("tube_time", 0)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("dst") then
return false end
if not inv:is_empty("src") then
return false end
if not inv:is_empty("src2") then
return false end
return true
end,
}) })
minetest.register_node("technic:alloy_furnace_active", { minetest.register_node(
description = "Alloy Furnace", "technic:alloy_furnace_active",
tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png", {
"technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front_active.png"}, description = "Alloy Furnace",
paramtype2 = "facedir", tiles = {"technic_alloy_furnace_top.png", "technic_machine_bottom.png", "technic_alloy_furnace_side.png",
light_source = 8, "technic_alloy_furnace_side.png", "technic_alloy_furnace_side.png", "technic_alloy_furnace_front_active.png"},
drop = "technic:alloy_furnace", paramtype2 = "facedir",
groups = {cracky=2,not_in_creative_inventory=1}, light_source = 8,
legacy_facedir_simple = true, drop = "technic:alloy_furnace",
sounds = default.node_sound_stone_defaults(), groups = {cracky=2,not_in_creative_inventory=1},
internal_EU_buffer=0; legacy_facedir_simple = true,
interal_EU_buffer_size=2000; sounds = default.node_sound_stone_defaults(),
technic_power_machine=1, can_dig = function(pos,player)
can_dig = function(pos,player) local meta = minetest.env:get_meta(pos);
local meta = minetest.env:get_meta(pos); local inv = meta:get_inventory()
local inv = meta:get_inventory() if not inv:is_empty("src") or not inv:is_empty("src2") or not inv:is_empty("dst") then
if not inv:is_empty("dst") then minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
return false return false
elseif not inv:is_empty("src") then else
return false return true
end end
return true end,
end, })
})
minetest.register_abm({ minetest.register_abm(
nodenames = {"technic:alloy_furnace","technic:alloy_furnace_active"}, { nodenames = {"technic:alloy_furnace","technic:alloy_furnace_active"},
interval = 1, interval = 1,
chance = 1, chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local eu_input = meta:get_int("LV_EU_input")
local state = meta:get_int("state")
local next_state = state
action = function(pos, node, active_object_count, active_object_count_wider) -- Machine information
local machine_name = "Electric Alloy Furnace"
local machine_node = "technic:alloy_furnace"
local machine_state_demand = { 50, 600 }
local meta = minetest.env:get_meta(pos) -- Setup meta data if it does not exist. state is used as an indicator of this
internal_EU_buffer=meta:get_float("internal_EU_buffer") if state == 0 then
internal_EU_buffer_size=meta:get_float("internal_EU_buffer") meta:set_int("state", 1)
local load = math.floor(internal_EU_buffer/2000 * 100) meta:set_int("LV_EU_demand", machine_state_demand[1])
meta:set_string("formspec", meta:set_int("LV_EU_input", 0)
"invsize[8,9;]".. meta:set_int("tube_time", 0)
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. return
(load)..":technic_power_meter_fg.png]".. end
"list[current_name;src;3,1;1,1;]"..
"list[current_name;src2;3,2;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"..
"label[0,0;Electric Alloy Furnace]"..
"label[1,3;Power level]")
local inv = meta:get_inventory() -- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
local furnace_is_cookin = meta:get_int("furnace_is_cookin") -- State machine
if eu_input == 0 then
-- Unpowered - go idle
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
next_state = 1
elseif eu_input == machine_state_demand[state] then
-- Powered - do the state specific actions
local srclist = inv:get_list("src") -- Execute always if powered logic
local srclist2 = inv:get_list("src2") local inv = meta:get_inventory()
local empty = 1
local recipe = nil
local result = nil
srcstack = inv:get_stack("src", 1) -- Get what to cook if anything
if srcstack then src_item1=srcstack:to_table() end local srcstack = inv:get_stack("src", 1)
srcstack = inv:get_stack("src2", 1) local src2stack = inv:get_stack("src2", 1)
if srcstack then src_item2=srcstack:to_table() end local src_item1 = nil
dst_index=nil local src_item2 = nil
if srcstack and src2stack then
src_item1 = srcstack:to_table()
src_item2 = src2stack:to_table()
empty = 0
end
if src_item1 and src_item2 then if src_item1 and src_item2 then
dst_index=get_cook_result(src_item1,src_item2) recipe = technic.get_alloy_recipe(src_item1,src_item2)
end end
if recipe then
result = { name=recipe.dst_name, count=recipe.dst_count}
end
if recipe then
print("recipe "..recipe.dst_name.." : result "..result.name.." : empty "..empty.." : src_item1 "..src_item1.name.." : src_item2 "..src_item2.name)
end
if (furnace_is_cookin == 1) then if state == 1 then
if internal_EU_buffer>=150 then hacky_swap_node(pos, machine_node)
internal_EU_buffer=internal_EU_buffer-150; meta:set_string("infotext", machine_name.." Idle")
meta:set_float("internal_EU_buffer",internal_EU_buffer)
meta:set_float("src_time", meta:get_float("src_time") + 1)
if dst_index and meta:get_float("src_time") >= 4 then
-- check if there's room for output in "dst" list
dst_stack={}
dst_stack["name"]=alloy_recipes[dst_index].dst_name
dst_stack["count"]=alloy_recipes[dst_index].dst_count
if inv:room_for_item("dst",dst_stack) then
-- Put result in "dst" list
inv:add_item("dst",dst_stack)
-- take stuff from "src" list
for i=1,alloy_recipes[dst_index].src1_count,1 do
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
end
for i=1,alloy_recipes[dst_index].src2_count,1 do
srcstack = inv:get_stack("src2", 1)
srcstack:take_item()
inv:set_stack("src2", 1, srcstack)
end
if empty == 0 and recipe and inv:room_for_item("dst", result) then
meta:set_string("infotext", machine_name.." Active")
meta:set_string("src_time", 0)
next_state = 2
end
else elseif state == 2 then
print("Furnace inventory full!") hacky_swap_node(pos, machine_node.."_active")
end meta:set_int("src_time", meta:get_int("src_time") + 1)
meta:set_string("src_time", 0) if meta:get_int("src_time") == 4 then -- 4 ticks per output
end meta:set_string("src_time", 0)
end -- check if there's room for output in "dst" list and that we have the materials
end if recipe and inv:room_for_item("dst", result) then
-- Take stuff from "src" list
srcstack:take_item(recipe.src1_count)
inv:set_stack("src", 1, srcstack)
src2stack:take_item(recipe.src2_count)
inv:set_stack("src2", 1, src2stack)
-- Put result in "dst" list
inv:add_item("dst",result)
else
next_state = 1
end
end
end
-- Change state?
if next_state ~= state then
meta:set_int("LV_EU_demand", machine_state_demand[next_state])
meta:set_int("state", next_state)
end
end
end,
})
if dst_index and meta:get_int("furnace_is_cookin")==0 then technic.register_LV_machine ("technic:alloy_furnace","RE")
hacky_swap_node(pos,"technic:alloy_furnace_active") technic.register_LV_machine ("technic:alloy_furnace_active","RE")
meta:set_string("infotext","Electric Alloy Furnace active")
meta:set_int("furnace_is_cookin",1)
meta:set_string("src_time", 0)
return
end
if meta:get_int("furnace_is_cookin")==0 or dst_index==nil then
hacky_swap_node(pos,"technic:alloy_furnace")
meta:set_string("infotext","Electric Alloy Furnace inactive")
meta:set_int("furnace_is_cookin",0)
meta:set_string("src_time", 0)
end
end,
})
function get_cook_result(src_item1, src_item2)
local counter=registered_recipes_count-1
for i=1, counter,1 do
if alloy_recipes[i].src1_name==src_item1["name"] and
alloy_recipes[i].src2_name==src_item2["name"] and
alloy_recipes[i].src1_count<=src_item1["count"] and
alloy_recipes[i].src2_count<=src_item2["count"]
then return i end
end
return nil
end
register_LV_machine ("technic:alloy_furnace","RE")
register_LV_machine ("technic:alloy_furnace_active","RE")
--coal driven alloy furnace:
--------------------------------------------------
-- coal driven alloy furnace. This uses no EUs:
--------------------------------------------------
coal_alloy_furnace_formspec = coal_alloy_furnace_formspec =
"size[8,9]".. "size[8,9]"..
"label[0,0;Alloy Furnace]".. "label[0,0;Alloy Furnace]"..
@ -230,9 +217,6 @@ minetest.register_node("technic:coal_alloy_furnace", {
inv:set_size("src", 1) inv:set_size("src", 1)
inv:set_size("src2", 1) inv:set_size("src2", 1)
inv:set_size("dst", 4) inv:set_size("dst", 4)
local furnace_is_cookin = 0
local dst_index = nil
end, end,
can_dig = function(pos,player) can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos); local meta = minetest.env:get_meta(pos);
@ -271,7 +255,7 @@ minetest.register_abm({
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.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
for i, name in ipairs({ for i, name in pairs({
"fuel_totaltime", "fuel_totaltime",
"fuel_time", "fuel_time",
"src_totaltime", "src_totaltime",
@ -282,100 +266,94 @@ minetest.register_abm({
end end
end end
local inv = meta:get_inventory() local inv = meta:get_inventory()
local recipe = nil
srcstack = inv:get_stack("src", 1) -- Get what to cook if anything
local srcstack = inv:get_stack("src", 1)
if srcstack then src_item1=srcstack:to_table() end if srcstack then src_item1=srcstack:to_table() end
srcstack = inv:get_stack("src2", 1)
if srcstack then src_item2=srcstack:to_table() end local src2stack = inv:get_stack("src2", 1)
dst_index=nil if src2stack then src_item2=src2stack:to_table() end
if src_item1 and src_item2 then if src_item1 and src_item2 then
dst_index=get_cook_result(src_item1,src_item2) recipe = technic.get_alloy_recipe(src_item1,src_item2)
end end
local was_active = false local was_active = false
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
was_active = true was_active = true
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1) meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
meta:set_float("src_time", meta:get_float("src_time") + 1) meta:set_float("src_time", meta:get_float("src_time") + 1)
if dst_index and meta:get_float("src_time") >= 5 then if recipe and meta:get_float("src_time") == 6 then
-- check if there's room for output in "dst" list -- check if there's room for output in "dst" list
dst_stack={} local dst_stack = { name=recipe.dst_name, count=recipe.dst_count}
dst_stack["name"]=alloy_recipes[dst_index].dst_name if inv:room_for_item("dst",dst_stack) then
dst_stack["count"]=alloy_recipes[dst_index].dst_count -- Take stuff from "src" list
if inv:room_for_item("dst",dst_stack) then srcstack:take_item(recipe.src1_count)
-- Put result in "dst" list inv:set_stack("src", 1, srcstack)
inv:add_item("dst", dst_stack) src2stack:take_item(recipe.src2_count)
-- take stuff from "src" list inv:set_stack("src2", 1, src2stack)
for i=1,alloy_recipes[dst_index].src1_count,1 do -- Put result in "dst" list
srcstack = inv:get_stack("src", 1) inv:add_item("dst",dst_stack)
srcstack:take_item() else
inv:set_stack("src", 1, srcstack) print("Furnace inventory full!") -- Silly code...
end end
for i=1,alloy_recipes[dst_index].src2_count,1 do meta:set_string("src_time", 0)
srcstack = inv:get_stack("src2", 1) end
srcstack:take_item()
inv:set_stack("src2", 1, srcstack)
end
else
print("Furnace inventory full!")
end
meta:set_string("src_time", 0)
end
end end
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
local percent = math.floor(meta:get_float("fuel_time") / local percent = math.floor(meta:get_float("fuel_time") /
meta:get_float("fuel_totaltime") * 100) meta:get_float("fuel_totaltime") * 100)
meta:set_string("infotext","Furnace active: "..percent.."%") meta:set_string("infotext","Furnace active: "..percent.."%")
hacky_swap_node(pos,"technic:coal_alloy_furnace_active") hacky_swap_node(pos,"technic:coal_alloy_furnace_active")
meta:set_string("formspec", meta:set_string("formspec",
"size[8,9]".. "size[8,9]"..
"label[0,0;Electric Alloy Furnace]".. "label[0,0;Electric Alloy Furnace]"..
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:".. "image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
(100-percent)..":default_furnace_fire_fg.png]".. (100-percent)..":default_furnace_fire_fg.png]"..
"list[current_name;fuel;2,3;1,1;]".. "list[current_name;fuel;2,3;1,1;]"..
"list[current_name;src;2,1;1,1;]".. "list[current_name;src;2,1;1,1;]"..
"list[current_name;src2;3,1;1,1;]".. "list[current_name;src2;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]".. "list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]") "list[current_player;main;0,5;8,4;]")
return return
end end
local fuel = nil -- FIXME: Make this look more like the electrical version.
local fuellist = inv:get_list("fuel") -- This code refetches the recipe to see if it can be done again after the iteration
srcstack = inv:get_stack("src", 1) srcstack = inv:get_stack("src", 1)
if srcstack then src_item1=srcstack:to_table() end if srcstack then src_item1=srcstack:to_table() end
srcstack = inv:get_stack("src2", 1) srcstack = inv:get_stack("src2", 1)
if srcstack then src_item2=srcstack:to_table() end if srcstack then src_item2=srcstack:to_table() end
dst_index=nil
if src_item1 and src_item2 then if src_item1 and src_item2 then
dst_index=get_cook_result(src_item1,src_item2) recipe = technic.get_alloy_recipe(src_item1,src_item2)
end end
if recipe==nil then
if was_active then
meta:set_string("infotext","Furnace is empty")
hacky_swap_node(pos,"technic:coal_alloy_furnace")
meta:set_string("formspec", coal_alloy_furnace_formspec)
end
return
end
-- Next take a hard look at the fuel situation
local fuel = nil
local fuellist = inv:get_list("fuel")
if fuellist then if fuellist then
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist}) fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
end end
if fuel.time <= 0 then if fuel.time <= 0 then
meta:set_string("infotext","Furnace out of fuel") meta:set_string("infotext","Furnace out of fuel")
hacky_swap_node(pos,"technic:coal_alloy_furnace") hacky_swap_node(pos,"technic:coal_alloy_furnace")
meta:set_string("formspec", coal_alloy_furnace_formspec) meta:set_string("formspec", coal_alloy_furnace_formspec)
return return
end
if dst_index==nil then
if was_active then
meta:set_string("infotext","Furnace is empty")
hacky_swap_node(pos,"technic:coal_alloy_furnace")
meta:set_string("formspec", coal_alloy_furnace_formspec)
end
return
end end
meta:set_string("fuel_totaltime", fuel.time) meta:set_string("fuel_totaltime", fuel.time)
@ -384,6 +362,5 @@ minetest.register_abm({
local stack = inv:get_stack("fuel", 1) local stack = inv:get_stack("fuel", 1)
stack:take_item() stack:take_item()
inv:set_stack("fuel", 1, stack) inv:set_stack("fuel", 1, stack)
end,
end, })
})

View File

@ -9,262 +9,451 @@ minetest.register_craft({
} }
}) })
MV_alloy_furnace_formspec = local mv_alloy_furnace_formspec =
"invsize[8,10;]".. "invsize[8,10;]"..
"label[0,0;MV Alloy Furnace]".. "label[0,0;MV Alloy Furnace]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "list[current_name;src;3,1;1,2;]"..
"label[1,2.8;Power level]"..
"list[current_name;src;3,1;1,2;]"..
"list[current_name;dst;5,1;2,2;]".. "list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,6;8,4;]".. "list[current_player;main;0,6;8,4;]"..
"list[current_name;upgrade1;1,4;1,1;]".. "list[current_name;upgrade1;1,4;1,1;]"..
"list[current_name;upgrade2;2,4;1,1;]".. "list[current_name;upgrade2;2,4;1,1;]"..
"label[1,5;Upgrade Slots]" "label[1,5;Upgrade Slots]"
minetest.register_node("technic:mv_alloy_furnace", { minetest.register_node(
description = "MV Alloy Furnace", "technic:mv_alloy_furnace",
tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png", {description = "MV Alloy Furnace",
"technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front.png"}, tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png",
paramtype2 = "facedir", "technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front.png"},
groups = {cracky=2, tubedevice=1,tubedevice_receiver=1}, paramtype2 = "facedir",
tube={insert_object=function(pos,node,stack,direction) groups = {cracky=2, tubedevice=1,tubedevice_receiver=1},
local meta=minetest.env:get_meta(pos) tube={insert_object=function(pos,node,stack,direction)
local inv=meta:get_inventory() local meta=minetest.env:get_meta(pos)
return inv:add_item("src",stack) local inv=meta:get_inventory()
end, return inv:add_item("src",stack)
can_insert=function(pos,node,stack,direction) end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos) local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory() local inv=meta:get_inventory()
return inv:room_for_item("src",stack) return inv:room_for_item("src",stack)
end, end,
}, },
legacy_facedir_simple = true, legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
technic_power_machine=1, on_construct = function(pos)
internal_EU_buffer=0; local meta = minetest.env:get_meta(pos)
interal_EU_buffer_size=2000; meta:set_string("infotext", "MV Alloy furnace")
on_construct = function(pos) meta:set_float("technic_mv_power_machine", 1)
local meta = minetest.env:get_meta(pos) meta:set_int("tube_time", 0)
meta:set_float("technic_power_machine", 1) meta:set_string("formspec", mv_alloy_furnace_formspec)
meta:set_string("formspec", mv_alloy_furnace_formspec) local inv = meta:get_inventory()
meta:set_string("infotext", "MV Electric Alloy furnace") inv:set_size("src", 2)
local inv = meta:get_inventory() inv:set_size("dst", 4)
inv:set_size("src", 2) inv:set_size("upgrade1", 1)
inv:set_size("dst", 4) inv:set_size("upgrade2", 1)
inv:set_size("upgrade1", 1) end,
inv:set_size("upgrade2", 1) can_dig = function(pos,player)
local EU_used = 0 local meta = minetest.env:get_meta(pos);
local furnace_is_cookin = 0 local inv = meta:get_inventory()
local cooked = nil if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
meta:set_float("internal_EU_buffer",0) minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
meta:set_float("internal_EU_buffer_size",2000) return false
else
end, return true
can_dig = function(pos,player) end
local meta = minetest.env:get_meta(pos); end,
local inv = meta:get_inventory()
if not inv:is_empty("dst") then
return false end
if not inv:is_empty("src") then
return false end
if not inv:is_empty("upgrade1") then
return false end
if not inv:is_empty("upgrade2") then
return false end
return true
end,
}) })
minetest.register_node("technic:mv_alloy_furnace_active", { minetest.register_node(
description = "MV Alloy Furnace", "technic:mv_alloy_furnace_active",
tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png", {description = "MV Alloy Furnace",
"technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front_active.png"}, tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png",
paramtype2 = "facedir", "technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front_active.png"},
light_source = 8, paramtype2 = "facedir",
drop = "technic:mv_alloy_furnace", light_source = 8,
groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1}, drop = "technic:mv_alloy_furnace",
tube={insert_object=function(pos,node,stack,direction) groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1},
local meta=minetest.env:get_meta(pos) tube={insert_object=function(pos,node,stack,direction)
local inv=meta:get_inventory() local meta=minetest.env:get_meta(pos)
return inv:add_item("src",stack) local inv=meta:get_inventory()
end, return inv:add_item("src",stack)
can_insert=function(pos,node,stack,direction) end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos) local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory() local inv=meta:get_inventory()
return inv:room_for_item("src",stack) return inv:room_for_item("src",stack)
end, end,
}, },
legacy_facedir_simple = true, legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
internal_EU_buffer=0; can_dig = function(pos,player)
interal_EU_buffer_size=2000; local meta = minetest.env:get_meta(pos);
technic_power_machine=1, local inv = meta:get_inventory()
can_dig = function(pos,player) if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
local meta = minetest.env:get_meta(pos); minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
local inv = meta:get_inventory() return false
if not inv:is_empty("dst") then else
return false end return true
if not inv:is_empty("src") then end
return false end end,
if not inv:is_empty("upgrade1") then -- These three makes sure upgrades are not moved in or out while the furnace is active.
return false end allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if not inv:is_empty("upgrade2") then if listname == "src" or listname == "dst" then
return false end return 99
return true else
end, return 0 -- Disallow the move
end
end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if listname == "src" or listname == "dst" then
return 99
else
return 0 -- Disallow the move
end
end,
allow_metadata_inventory_move = function(pos, from_list, to_list, to_list, to_index, count, player)
return 0
end,
}) })
minetest.register_abm({ local send_cooked_items = function(pos,x_velocity,z_velocity)
nodenames = {"technic:mv_alloy_furnace","technic:mv_alloy_furnace_active"}, -- Send items on their way in the pipe system.
interval = 1, local meta=minetest.env:get_meta(pos)
chance = 1, local inv = meta:get_inventory()
local i=0
action = function(pos, node, active_object_count, active_object_count_wider) for _,stack in ipairs(inv:get_list("dst")) do
local pos1={} i=i+1
pos1.x=pos.x if stack then
pos1.y=pos.y local item0=stack:to_table()
pos1.z=pos.z if item0 then
local x_velocity=0 item0["count"]="1"
local z_velocity=0 local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},item0)
item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z}
-- output is on the left side of the furnace item1:setvelocity({x=x_velocity, y=0, z=z_velocity})
if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end item1:setacceleration({x=0, y=0, z=0})
if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end stack:take_item(1);
if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end inv:set_stack("dst", i, stack)
if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end return
local output_tube_connected = false
local meta=minetest.env:get_meta(pos1)
if meta:get_int("tubelike")==1 then output_tube_connected=true end
meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
local upg_item1
local upg_item1_name=""
local upg_item2
local upg_item2_name=""
local srcstack = inv:get_stack("upgrade1", 1)
if srcstack then upg_item1=srcstack:to_table() end
srcstack = inv:get_stack("upgrade2", 1)
if srcstack then upg_item2=srcstack:to_table() end
if upg_item1 then upg_item1_name=upg_item1.name end
if upg_item2 then upg_item2_name=upg_item2.name end
local speed=0
if upg_item1_name=="technic:control_logic_unit" then speed=speed+1 end
if upg_item2_name=="technic:control_logic_unit" then speed=speed+1 end
tube_time=meta:get_float("tube_time")
tube_time=tube_time+speed
if tube_time>3 then
tube_time=0
if output_tube_connected then send_cooked_alloys(pos,x_velocity,z_velocity) end
end
meta:set_float("tube_time", tube_time)
local extra_buffer_size = 0
if upg_item1_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end
if upg_item2_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end
local internal_EU_buffer_size=2000+extra_buffer_size
meta:set_float("internal_EU_buffer_size",internal_EU_buffer_size)
internal_EU_buffer=meta:get_float("internal_EU_buffer")
if internal_EU_buffer > internal_EU_buffer_size then internal_EU_buffer = internal_EU_buffer_size end
local meta = minetest.env:get_meta(pos)
local load = math.floor(internal_EU_buffer/internal_EU_buffer_size * 100)
meta:set_string("formspec",
MV_alloy_furnace_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]")
local inv = meta:get_inventory()
local furnace_is_cookin = meta:get_int("furnace_is_cookin")
local srclist = inv:get_list("src")
local srclist2 = inv:get_list("src2")
srcstack = inv:get_stack("src", 1)
if srcstack then src_item1=srcstack:to_table() end
srcstack = inv:get_stack("src", 2)
if srcstack then src_item2=srcstack:to_table() end
dst_index=nil
if src_item1 and src_item2 then
dst_index=get_cook_result(src_item1,src_item2)
end end
end
end
end
local smelt_item = function(pos)
local meta=minetest.env:get_meta(pos)
local inv = meta:get_inventory()
meta:set_int("src_time", meta:get_int("src_time") + 3) -- Cooking time 3x faster
local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")})
dst_stack={}
dst_stack["name"]=alloy_recipes[dst_index].dst_name
dst_stack["count"]=alloy_recipes[dst_index].dst_count
if (furnace_is_cookin == 1) then if result and result.item and meta:get_int("src_time") >= result.time then
if internal_EU_buffer>=150 then meta:set_int("src_time", 0)
internal_EU_buffer=internal_EU_buffer-150; -- check if there's room for output in "dst" list
meta:set_float("internal_EU_buffer",internal_EU_buffer) if inv:room_for_item("dst",result) then
meta:set_float("src_time", meta:get_float("src_time") + 1) -- take stuff from "src" list
if dst_index and meta:get_float("src_time") >= 4 then srcstack = inv:get_stack("src", 1)
-- check if there's room for output in "dst" list srcstack:take_item()
dst_stack={} inv:set_stack("src", 1, srcstack)
dst_stack["name"]=alloy_recipes[dst_index].dst_name -- Put result in "dst" list
dst_stack["count"]=alloy_recipes[dst_index].dst_count inv:add_item("dst", result.item)
if inv:room_for_item("dst",dst_stack) then return 1
-- Put result in "dst" list else
inv:add_item("dst",dst_stack) return 0 -- done
-- take stuff from "src" list end
for i=1,alloy_recipes[dst_index].src1_count,1 do end
srcstack = inv:get_stack("src", 1) return 0 -- done
srcstack:take_item() end
inv:set_stack("src", 1, srcstack)
end
for i=1,alloy_recipes[dst_index].src2_count,1 do
srcstack = inv:get_stack("src", 2)
srcstack:take_item()
inv:set_stack("src", 2, srcstack)
end
else minetest.register_abm(
print("Furnace inventory full!") {nodenames = {"technic:mv_alloy_furnace","technic:mv_alloy_furnace_active"},
end interval = 1,
meta:set_string("src_time", 0) chance = 1,
end
end action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local eu_input = meta:get_int("MV_EU_input")
local state = meta:get_int("state")
local next_state = state
-- Machine information
local machine_name = "MV Alloy Furnace"
local machine_node = "technic:mv_alloy_furnace"
local machine_state_demand = { 50, 2000, 1500, 1000 }
-- Setup meta data if it does not exist. state is used as an indicator of this
if state == 0 then
meta:set_int("state", 1)
meta:set_int("MV_EU_demand", machine_state_demand[1])
meta:set_int("MV_EU_input", 0)
return
end end
if dst_index and meta:get_int("furnace_is_cookin")==0 then -- Power off automatically if no longer connected to a switching station
hacky_swap_node(pos,"technic:mv_alloy_furnace_active") technic.switching_station_timeout_count(pos, "MV")
meta:set_string("infotext","MV Alloy Furnace active")
meta:set_int("furnace_is_cookin",1)
meta:set_string("src_time", 0)
return
end
if meta:get_int("furnace_is_cookin")==0 or dst_index==nil then -- Execute always logic
hacky_swap_node(pos,"technic:mv_alloy_furnace") -- CODE HERE --
meta:set_string("infotext","MV Alloy Furnace inactive")
meta:set_int("furnace_is_cookin",0) -- State machine
meta:set_string("src_time", 0) if eu_input == 0 then
-- Unpowered - go idle
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
next_state = 1
elseif eu_input == machine_state_demand[state] then
-- Powered - do the state specific actions
-- Execute always if powered logic
local meta=minetest.env:get_meta(pos)
-- Get the names of the upgrades
local meta=minetest.env:get_meta(pos)
local inv = meta:get_inventory()
local upg_item1
local upg_item1_name=""
local upg_item2
local upg_item2_name=""
local srcstack = inv:get_stack("upgrade1", 1)
if srcstack then upg_item1=srcstack:to_table() end
srcstack = inv:get_stack("upgrade2", 1)
if srcstack then upg_item2=srcstack:to_table() end
if upg_item1 then upg_item1_name=upg_item1.name end
if upg_item2 then upg_item2_name=upg_item2.name end
-- Save some power by installing battery upgrades. Fully upgraded makes this
-- furnace use the same amount of power as the LV version
local EU_saving_upgrade = 0
if upg_item1_name=="technic:battery" then EU_saving_upgrade = EU_saving_upgrade + 1 end
if upg_item2_name=="technic:battery" then EU_saving_upgrade = EU_saving_upgrade + 1 end
-- Tube loading speed can be upgraded using control logic units
local tube_speed_upgrade = 0
if upg_item1_name=="technic:control_logic_unit" then tube_speed_upgrade = tube_speed_upgrade + 1 end
if upg_item2_name=="technic:control_logic_unit" then tube_speed_upgrade = tube_speed_upgrade + 1 end
-- Handle pipeworks (consumes tube_speed_upgrade)
local pos1={x=pos.x, y=pos.y, z=pos.z}
local x_velocity=0
local z_velocity=0
-- Output is on the left side of the furnace
if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end
if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end
if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end
if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end
local output_tube_connected = false
local meta1 = minetest.env:get_meta(pos1)
if meta1:get_int("tubelike") == 1 then
output_tube_connected=true
end
tube_time = meta:get_int("tube_time")
tube_time = tube_time + tube_speed_upgrade
if tube_time > 3 then
tube_time = 0
if output_tube_connected then
send_cooked_items(pos,x_velocity,z_velocity)
end
end
meta:set_int("tube_time", tube_time)
-- The machine shuts down if we have nothing to smelt and no tube is connected
-- or if we have nothing to send with a tube connected.
if (not output_tube_connected and inv:is_empty("src"))
or ( output_tube_connected and inv:is_empty("dst")) then
next_state = 1
end
----------------------
local empty = 1
local recipe = nil
local result = nil
-- Get what to cook if anything
local srcstack = inv:get_stack("src", 1)
local src2stack = inv:get_stack("src", 2)
local src_item1 = nil
local src_item2 = nil
if srcstack and src2stack then
src_item1 = srcstack:to_table()
src_item2 = src2stack:to_table()
empty = 0
end
if src_item1 and src_item2 then
recipe = technic.get_alloy_recipe(src_item1,src_item2)
end
if recipe then
result = { name=recipe.dst_name, count=recipe.dst_count}
end
if state == 1 then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
local meta=minetest.env:get_meta(pos)
local inv = meta:get_inventory()
if not inv:is_empty("src") then
if empty == 0 and recipe and inv:room_for_item("dst", result) then
meta:set_string("infotext", machine_name.." Active")
meta:set_int("src_time", 0)
next_state = 2+EU_saving_upgrade -- Next state is decided by the battery upgrade (state 2= 0 batteries, state 3 = 1 battery, 4 = 2 batteries)
end
end
elseif state == 2 or state == 3 or state == 4 then
hacky_swap_node(pos, machine_node.."_active")
meta:set_int("src_time", meta:get_int("src_time") + 1)
if meta:get_int("src_time") == 4 then -- 4 ticks per output
meta:set_string("src_time", 0)
-- check if there's room for output in "dst" list and that we have the materials
if recipe and inv:room_for_item("dst", result) then
-- Take stuff from "src" list
srcstack:take_item(recipe.src1_count)
inv:set_stack("src", 1, srcstack)
src2stack:take_item(recipe.src2_count)
inv:set_stack("src2", 1, src2stack)
-- Put result in "dst" list
inv:add_item("dst",result)
else
next_state = 1
end
end
end
end
-- Change state?
if next_state ~= state then
meta:set_int("MV_EU_demand", machine_state_demand[next_state])
meta:set_int("state", next_state)
end end
end,
})
function send_cooked_alloys (pos,x_velocity,z_velocity)
local meta=minetest.env:get_meta(pos)
local inv = meta:get_inventory()
local i=0
for _,stack in ipairs(inv:get_list("dst")) do
i=i+1
if stack then
local item0=stack:to_table()
if item0 then
item0["count"]="1"
local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},item0)
item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z}
item1:setvelocity({x=x_velocity, y=0, z=z_velocity})
item1:setacceleration({x=0, y=0, z=0})
stack:take_item(1);
inv:set_stack("dst", i, stack)
return
end
end
end
end
register_MV_machine ("technic:mv_alloy_furnace","RE") ------------------------------------
register_MV_machine ("technic:mv_alloy_furnace_active","RE")
-- local pos1={}
-- pos1.x=pos.x
-- pos1.y=pos.y
-- pos1.z=pos.z
-- local x_velocity=0
-- local z_velocity=0
--
-- -- output is on the left side of the furnace
-- if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end
-- if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end
-- if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end
-- if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end
--
-- local output_tube_connected = false
-- local meta=minetest.env:get_meta(pos1)
-- if meta:get_int("tubelike")==1 then output_tube_connected=true end
-- meta = minetest.env:get_meta(pos)
-- local inv = meta:get_inventory()
-- local upg_item1
-- local upg_item1_name=""
-- local upg_item2
-- local upg_item2_name=""
-- local srcstack = inv:get_stack("upgrade1", 1)
-- if srcstack then upg_item1=srcstack:to_table() end
-- srcstack = inv:get_stack("upgrade2", 1)
-- if srcstack then upg_item2=srcstack:to_table() end
-- if upg_item1 then upg_item1_name=upg_item1.name end
-- if upg_item2 then upg_item2_name=upg_item2.name end
--
-- local speed=0
-- if upg_item1_name=="technic:control_logic_unit" then speed=speed+1 end
-- if upg_item2_name=="technic:control_logic_unit" then speed=speed+1 end
-- tube_time=meta:get_float("tube_time")
-- tube_time=tube_time+speed
-- if tube_time>3 then
-- tube_time=0
-- if output_tube_connected then send_cooked_items(pos,x_velocity,z_velocity) end
-- end
-- meta:set_float("tube_time", tube_time)
--
-- local extra_buffer_size = 0
-- if upg_item1_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end
-- if upg_item2_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end
-- local internal_EU_buffer_size=2000+extra_buffer_size
-- meta:set_float("internal_EU_buffer_size",internal_EU_buffer_size)
--
-- internal_EU_buffer=meta:get_float("internal_EU_buffer")
-- if internal_EU_buffer > internal_EU_buffer_size then internal_EU_buffer = internal_EU_buffer_size end
-- local meta = minetest.env:get_meta(pos)
-- local load = math.floor(internal_EU_buffer/internal_EU_buffer_size * 100)
-- meta:set_string("formspec",
-- MV_alloy_furnace_formspec..
-- "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
-- (load)..":technic_power_meter_fg.png]")
--
-- local inv = meta:get_inventory()
--
-- local furnace_is_cookin = meta:get_int("furnace_is_cookin")
--
-- local srclist = inv:get_list("src")
-- local srclist2 = inv:get_list("src2")
--
-- srcstack = inv:get_stack("src", 1)
-- if srcstack then src_item1=srcstack:to_table() end
-- srcstack = inv:get_stack("src", 2)
-- if srcstack then src_item2=srcstack:to_table() end
-- dst_index=nil
--
-- if src_item1 and src_item2 then
-- dst_index=get_cook_result(src_item1,src_item2)
-- end
--
--
-- if (furnace_is_cookin == 1) then
-- if internal_EU_buffer>=150 then
-- internal_EU_buffer=internal_EU_buffer-150;
-- meta:set_float("internal_EU_buffer",internal_EU_buffer)
-- meta:set_float("src_time", meta:get_float("src_time") + 1)
-- if dst_index and meta:get_float("src_time") >= 4 then
-- -- check if there's room for output in "dst" list
-- dst_stack={}
-- dst_stack["name"]=alloy_recipes[dst_index].dst_name
-- dst_stack["count"]=alloy_recipes[dst_index].dst_count
-- if inv:room_for_item("dst",dst_stack) then
-- -- Put result in "dst" list
-- inv:add_item("dst",dst_stack)
-- -- take stuff from "src" list
-- for i=1,alloy_recipes[dst_index].src1_count,1 do
-- srcstack = inv:get_stack("src", 1)
-- srcstack:take_item()
-- inv:set_stack("src", 1, srcstack)
-- end
-- for i=1,alloy_recipes[dst_index].src2_count,1 do
-- srcstack = inv:get_stack("src", 2)
-- srcstack:take_item()
-- inv:set_stack("src", 2, srcstack)
-- end
--
-- else
-- print("Furnace inventory full!")
-- end
-- meta:set_string("src_time", 0)
-- end
-- end
-- end
--
-- if dst_index and meta:get_int("furnace_is_cookin")==0 then
-- hacky_swap_node(pos,"technic:mv_alloy_furnace_active")
-- meta:set_string("infotext","MV Alloy Furnace active")
-- meta:set_int("furnace_is_cookin",1)
-- meta:set_string("src_time", 0)
-- return
-- end
--
-- if meta:get_int("furnace_is_cookin")==0 or dst_index==nil then
-- hacky_swap_node(pos,"technic:mv_alloy_furnace")
-- meta:set_string("infotext","MV Alloy Furnace inactive")
-- meta:set_int("furnace_is_cookin",0)
-- meta:set_string("src_time", 0)
-- end
--
end,
})
technic.register_MV_machine ("technic:mv_alloy_furnace","RE")
technic.register_MV_machine ("technic:mv_alloy_furnace_active","RE")

View File

@ -1,32 +1,77 @@
alloy_recipes ={} -- Register alloy recipes
technic.alloy_recipes = {}
registered_recipes_count=1 -- Register recipe in a table
technic.register_alloy_recipe = function(metal1, count1, metal2, count2, result, count3)
technic.alloy_recipes[metal1..metal2] = { src1_count = count1, src2_count = count2, dst_name = result, dst_count = count3 }
if unified_inventory then
unified_inventory.register_craft(
{
type = "alloy",
output = result.." "..count3,
items = {metal1.." "..count1,metal2.." "..count2},
width = 2,
})
end
end
-- Retrieve a recipe given the input metals.
-- Input parameters are a table from a StackItem
technic.get_alloy_recipe = function(metal1, metal2)
-- Check for both combinations of metals and for the right amount in both
if technic.alloy_recipes[metal1.name..metal2.name]
and metal1.count >= technic.alloy_recipes[metal1.name..metal2.name].src1_count
and metal2.count >= technic.alloy_recipes[metal1.name..metal2.name].src2_count then
return technic.alloy_recipes[metal1.name..metal2.name]
elseif technic.alloy_recipes[metal2.name..metal1.name]
and metal2.count >= technic.alloy_recipes[metal2.name..metal1.name].src1_count
and metal1.count >= technic.alloy_recipes[metal2.name..metal1.name].src2_count then
return technic.alloy_recipes[metal2.name..metal1.name]
else
return nil
end
end
technic.register_alloy_recipe("technic:copper_dust", 3, "technic:tin_dust", 1, "technic:bronze_dust", 4)
technic.register_alloy_recipe("moreores:copper_ingot",3, "moreores:tin_ingot", 1, "moreores:bronze_ingot", 4)
technic.register_alloy_recipe("technic:iron_dust", 3, "technic:chromium_dust", 1, "technic:stainless_steel_dust", 4)
technic.register_alloy_recipe("default:steel_ingot", 3, "technic:chromium_ingot",1, "technic:stainless_steel_ingot",4)
technic.register_alloy_recipe("technic:copper_dust", 2, "technic:zinc_dust", 1, "technic:brass_dust", 3)
technic.register_alloy_recipe("moreores:copper_ingot",2, "technic:zinc_ingot", 1, "technic:brass_ingot", 3)
technic.register_alloy_recipe("default:sand", 2, "technic:coal_dust", 2, "technic:silicon_wafer", 1)
technic.register_alloy_recipe("technic:silicon_wafer",1, "technic:gold_dust", 1, "technic:doped_silicon_wafer", 1)
--------------------------------------
-- LEGACY CODE - some other mods might depend on this - Register the same recipes as above...
--------------------------------------
alloy_recipes = {}
registered_recipes_count = 1
function register_alloy_recipe (string1,count1, string2,count2, string3,count3) function register_alloy_recipe (string1,count1, string2,count2, string3,count3)
alloy_recipes[registered_recipes_count]={} alloy_recipes[registered_recipes_count]={}
alloy_recipes[registered_recipes_count].src1_name=string1 alloy_recipes[registered_recipes_count].src1_name=string1
alloy_recipes[registered_recipes_count].src1_count=count1 alloy_recipes[registered_recipes_count].src1_count=count1
alloy_recipes[registered_recipes_count].src2_name=string2 alloy_recipes[registered_recipes_count].src2_name=string2
alloy_recipes[registered_recipes_count].src2_count=count2 alloy_recipes[registered_recipes_count].src2_count=count2
alloy_recipes[registered_recipes_count].dst_name=string3 alloy_recipes[registered_recipes_count].dst_name=string3
alloy_recipes[registered_recipes_count].dst_count=count3 alloy_recipes[registered_recipes_count].dst_count=count3
registered_recipes_count=registered_recipes_count+1 registered_recipes_count=registered_recipes_count+1
alloy_recipes[registered_recipes_count]={} alloy_recipes[registered_recipes_count]={}
alloy_recipes[registered_recipes_count].src1_name=string2 alloy_recipes[registered_recipes_count].src1_name=string2
alloy_recipes[registered_recipes_count].src1_count=count2 alloy_recipes[registered_recipes_count].src1_count=count2
alloy_recipes[registered_recipes_count].src2_name=string1 alloy_recipes[registered_recipes_count].src2_name=string1
alloy_recipes[registered_recipes_count].src2_count=count1 alloy_recipes[registered_recipes_count].src2_count=count1
alloy_recipes[registered_recipes_count].dst_name=string3 alloy_recipes[registered_recipes_count].dst_name=string3
alloy_recipes[registered_recipes_count].dst_count=count3 alloy_recipes[registered_recipes_count].dst_count=count3
registered_recipes_count=registered_recipes_count+1 registered_recipes_count=registered_recipes_count+1
if unified_inventory then if unified_inventory then
unified_inventory.register_craft({ unified_inventory.register_craft({
type = "alloy", type = "alloy",
output = string3.." "..count3, output = string3.." "..count3,
items = {string1.." "..count1,string2.." "..count2}, items = {string1.." "..count1,string2.." "..count2},
width = 2, width = 2,
}) })
end end
end end
register_alloy_recipe ("technic:copper_dust",3, "technic:tin_dust",1, "technic:bronze_dust",4) register_alloy_recipe ("technic:copper_dust",3, "technic:tin_dust",1, "technic:bronze_dust",4)

View File

@ -1,23 +1,8 @@
-- register LV machines here -- LV Battery box and some other nodes...
local LV_machines = {} technic.register_LV_power_tool("technic:battery",10000)
function register_LV_machine(string1,string2) technic.register_MV_power_tool("technic:red_energy_crystal",100000)
LV_machines[string1] = string2 technic.register_HV_power_tool("technic:green_energy_crystal",250000)
end technic.register_HV_power_tool("technic:blue_energy_crystal",500000)
power_tools ={}
registered_power_tools_count=0
function register_power_tool (string1,max_charge)
registered_power_tools_count=registered_power_tools_count+1
power_tools[registered_power_tools_count]={}
power_tools[registered_power_tools_count].tool_name=string1
power_tools[registered_power_tools_count].max_charge=max_charge
end
register_power_tool ("technic:battery",10000)
register_power_tool ("technic:red_energy_crystal",100000)
register_power_tool ("technic:green_energy_crystal",250000)
register_power_tool ("technic:blue_energy_crystal",500000)
minetest.register_craft({ minetest.register_craft({
output = 'technic:battery 1', output = 'technic:battery 1',
@ -28,29 +13,32 @@ minetest.register_craft({
} }
}) })
minetest.register_craft({
output = 'technic:battery_box 1',
recipe = {
{'technic:battery', 'default:wood', 'technic:battery'},
{'technic:battery', 'moreores:copper_ingot', 'technic:battery'},
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
}
})
minetest.register_tool("technic:battery", minetest.register_tool("technic:battery",
{description = "RE Battery", {description = "RE Battery",
inventory_image = "technic_battery.png", inventory_image = "technic_battery.png",
tool_capabilities = {load=0,max_drop_level=0, groupcaps={fleshy={times={}, uses=10000, maxlevel=0}}}}) tool_capabilities = {load=0,max_drop_level=0, groupcaps={fleshy={times={}, uses=10000, maxlevel=0}}}})
minetest.register_craftitem("technic:battery_box", { --------------------------------------------
description = "Battery box", -- The Battery box
stack_max = 99, --------------------------------------------
}) minetest.register_craftitem(
"technic:battery_box",
{
description = "Battery box",
stack_max = 99,
})
minetest.register_craft(
{
output = 'technic:battery_box 1',
recipe = {
{'technic:battery', 'default:wood', 'technic:battery'},
{'technic:battery', 'moreores:copper_ingot', 'technic:battery'},
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
}
})
local battery_box_formspec =
battery_box_formspec =
"invsize[8,9;]".. "invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]".. "list[current_name;src;3,1;1,1;]"..
@ -71,28 +59,28 @@ minetest.register_node(
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
drop="technic:battery_box", drop="technic:battery_box",
on_construct = function(pos) on_construct = function(pos)
if pos == nil then return end
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
meta:set_string("infotext", "Battery box") meta:set_string("infotext", "Battery box")
meta:set_float("technic_power_machine", 1) meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", battery_box_formspec) meta:set_string("formspec", battery_box_formspec)
meta:set_float("internal_EU_buffer", 0) meta:set_int("LV_EU_demand", 0) -- How much can this node charge
meta:set_float("internal_EU_buffer_size", 60000) meta:set_int("LV_EU_supply", 0) -- How much can this node discharge
meta:set_int("LV_EU_input", 0) -- How much power is this machine getting.
meta:set_float("internal_EU_charge", 0)
inv:set_size("src", 1) inv:set_size("src", 1)
inv:set_size("dst", 1) inv:set_size("dst", 1)
end, end,
can_dig = function(pos,player) can_dig = function(pos,player)
if pos == nil then return end local meta = minetest.env:get_meta(pos);
local meta = minetest.env:get_meta(pos); local inv = meta:get_inventory()
local inv = meta:get_inventory() if not inv:is_empty("src") or not inv:is_empty("dst") then
if not inv:is_empty("dst") then minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
return false return false
elseif not inv:is_empty("src") then else
return false return true
end end
return true end,
end,
}) })
@ -105,51 +93,101 @@ for i=1,8,1 do
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
drop="technic:battery_box", drop="technic:battery_box",
on_construct = function(pos)
if pos == nil then return end
local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
meta:set_string("infotext", "Battery box")
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", battery_box_formspec)
meta:set_float("internal_EU_buffer", 0)
meta:set_float("internal_EU_buffer_size", 60000)
inv:set_size("src", 1)
inv:set_size("dst", 1)
end,
can_dig = function(pos,player) can_dig = function(pos,player)
if pos == nil then return end local meta = minetest.env:get_meta(pos);
local meta = minetest.env:get_meta(pos); local inv = meta:get_inventory()
local inv = meta:get_inventory() if not inv:is_empty("src") or not inv:is_empty("dst") then
if not inv:is_empty("dst") then minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
return false return false
elseif not inv:is_empty("src") then else
return false return true
end end
return true end,
end,
}) })
end end
function get_RE_item_load (load1,max_load) local power_tools = technic.LV_power_tools
if load1==0 then load1=65535 end
local temp = 65536-load1
temp= temp/65535*max_load
return math.floor(temp + 0.5)
end
function set_RE_item_load (load1,max_load) local charge_LV_tools = function(meta, charge)
if load1 == 0 then return 65535 end --charge registered power tools
local temp=load1/max_load*65535 local inv = meta:get_inventory()
temp=65536-temp if inv:is_empty("src")==false then
return math.floor(temp) local srcstack = inv:get_stack("src", 1)
end local src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
function set_RE_wear (item_stack,load1,max_load) local toolname = src_item["name"]
local temp=65536-math.floor(load1/max_load*65535) if power_tools[toolname] ~= nil then
item_stack["wear"]=tostring(temp) -- Set meta data for the tool if it didn't do it itself :-(
return item_stack src_meta=get_item_meta(src_item["metadata"])
end if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_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
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
local discharge_LV_tools = function(meta, charge, max_charge)
-- discharging registered power tools
local inv = meta:get_inventory()
if inv:is_empty("dst") == false then
srcstack = inv:get_stack("dst", 1)
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_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
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)
inv:set_stack("dst", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
minetest.register_abm( minetest.register_abm(
{nodenames = {"technic:battery_box","technic:battery_box1","technic:battery_box2","technic:battery_box3","technic:battery_box4", {nodenames = {"technic:battery_box","technic:battery_box1","technic:battery_box2","technic:battery_box3","technic:battery_box4",
@ -157,12 +195,39 @@ minetest.register_abm(
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.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
local max_charge = 60000 -- Set maximum charge for the device here local max_charge = 60000 -- Set maximum charge for the device here
local charge = meta:get_int("internal_EU_buffer") local max_charge_rate = 1000 -- Set maximum rate of charging
local max_discharge_rate = 2000 -- Set maximum rate of discharging
local eu_input = meta:get_int("LV_EU_input")
local current_charge = meta:get_int("internal_EU_charge") -- Battery charge right now
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
-- 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
current_charge = charge_LV_tools(meta, current_charge)
current_charge = discharge_LV_tools(meta, current_charge, max_charge)
-- Set a demand (we allow batteries to charge on less than the demand though)
meta:set_int("LV_EU_demand", math.min(max_charge_rate, max_charge-current_charge))
--print("BA:"..max_charge_rate.."|"..max_charge-current_charge.."|"..math.min(max_charge_rate, max_charge-current_charge))
-- Set how much we can supply
meta:set_int("LV_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("LV_EU_supply").." demand="..meta:get_int("LV_EU_demand").." current:"..current_charge)
-- Select node textures -- Select node textures
local i=math.ceil((charge/max_charge)*8) local i=math.ceil((current_charge/max_charge)*8)
if i > 8 then i = 8 end if i > 8 then i = 8 end
local j = meta:get_float("last_side_shown") local j = meta:get_float("last_side_shown")
if i~=j then if i~=j then
@ -171,223 +236,25 @@ minetest.register_abm(
meta:set_float("last_side_shown",i) meta:set_float("last_side_shown",i)
end end
--charge registered power tools local load = math.floor(current_charge/max_charge * 100)
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
local srcstack = inv:get_stack("src", 1)
local src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
local item_max_charge=nil
for i=1,registered_power_tools_count,1 do
if power_tools[i].tool_name==src_item["name"] then
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
-- Do the charging
local item_max_charge = power_tools[i].max_charge
local load1 = src_meta["charge"]
local load_step = 1000 -- how much to charge per tick
if load1<item_max_charge and charge>0 then
if charge-load_step<0 then load_step=charge end
if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
load1=load1+load_step
charge=charge-load_step
set_RE_wear(src_item,load1,item_max_charge)
src_meta["charge"]=load1
src_item["metadata"]=set_item_meta(src_meta)
inv:set_stack("src", 1, src_item)
end
meta:set_int("internal_EU_buffer",charge)
break
end
end
end
-- discharging registered power tools
if inv:is_empty("dst") == false then
srcstack = inv:get_stack("dst", 1)
src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
local item_max_charge=nil
for i=1,registered_power_tools_count,1 do
if power_tools[i].tool_name==src_item["name"] then
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
local item_max_charge = power_tools[i].max_charge
local load1 = src_meta["charge"]
local load_step = 4000 -- how much to discharge per tick
if load1>0 and charge<max_charge then
if charge+load_step>max_charge then load_step=max_charge-charge end
if load1-load_step<0 then load_step=load1 end
load1=load1-load_step
charge=charge+load_step
set_RE_wear(src_item,load1,item_max_charge)
src_meta["charge"]=load1
src_item["metadata"]=set_item_meta(src_meta)
inv:set_stack("dst", 1, src_item)
end
meta:set_int("internal_EU_buffer",charge)
break
end
end
end
local load = math.floor(charge/60000 * 100)
meta:set_string("formspec", meta:set_string("formspec",
battery_box_formspec.. battery_box_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]" (load)..":technic_power_meter_fg.png]"
) )
-- Next index the surrounding network the get the producers and receivers on the power grid if eu_input == 0 then
local pos1={} meta:set_string("infotext", "LV Battery box: "..current_charge.."/"..max_charge.." (idle)")
pos1.y=pos.y-1 else
pos1.x=pos.x meta:set_string("infotext", "LV Battery box: "..current_charge.."/"..max_charge)
pos1.z=pos.z
meta1 = minetest.env:get_meta(pos1)
if meta1:get_float("cablelike")~=1 then return end
local LV_nodes = {}
local PR_nodes = {}
local RE_nodes = {}
local BA_nodes = {}
LV_nodes[1]={}
LV_nodes[1].x=pos1.x
LV_nodes[1].y=pos1.y
LV_nodes[1].z=pos1.z
LV_nodes[1].visited=false
local table_index=1
repeat
check_LV_node(PR_nodes,RE_nodes,BA_nodes,LV_nodes,table_index)
table_index=table_index+1
if LV_nodes[table_index]==nil then break end
until false
-- Get power from all connected producers
local pr_pos
for _,pr_pos in ipairs(PR_nodes) do
local meta1 = minetest.env:get_meta(pr_pos)
local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
local charge_to_take = 200
if charge<max_charge then
if internal_EU_buffer-charge_to_take<=0 then
charge_to_take=internal_EU_buffer
end
if charge_to_take>0 then
charge=charge+charge_to_take
internal_EU_buffer=internal_EU_buffer-charge_to_take
meta1:set_float("internal_EU_buffer",internal_EU_buffer)
end
end
end end
if charge>max_charge then charge=max_charge end
-- Provide power to all connected receivers
local re_pos
for _,re_pos in ipairs(RE_nodes) do
local meta1 = minetest.env:get_meta(re_pos)
local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size")
local charge_to_give = math.min(200, charge/table.getn(RE_nodes))
if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
charge_to_give=internal_EU_buffer_size-internal_EU_buffer
end
if charge-charge_to_give<0 then charge_to_give=charge end
internal_EU_buffer=internal_EU_buffer+charge_to_give
meta1:set_float("internal_EU_buffer",internal_EU_buffer)
charge=charge-charge_to_give;
end
charge=math.floor(charge)
meta:set_string("infotext", "LV Battery box: "..charge.."/"..max_charge);
meta:set_int("internal_EU_buffer",charge)
end end
}) })
-- Register as a battery type -- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power -- Battery type machines function as power reservoirs and can both receive and give back power
register_LV_machine("technic:battery_box","BA") technic.register_LV_machine("technic:battery_box","BA")
for i=1,8,1 do for i=1,8,1 do
register_LV_machine("technic:battery_box"..i,"BA") technic.register_LV_machine("technic:battery_box"..i,"BA")
end
function add_new_cable_node (LV_nodes,pos1)
if LV_nodes == nil then return true end
local i=1
repeat
if LV_nodes[i]==nil then break end
if pos1.x==LV_nodes[i].x and pos1.y==LV_nodes[i].y and pos1.z==LV_nodes[i].z then return false end
i=i+1
until false
LV_nodes[i]={}
LV_nodes[i].x=pos1.x
LV_nodes[i].y=pos1.y
LV_nodes[i].z=pos1.z
return true
end
function check_LV_node(PR_nodes,RE_nodes,BA_nodes,LV_nodes,i)
local pos1={}
pos1.x=LV_nodes[i].x
pos1.y=LV_nodes[i].y
pos1.z=LV_nodes[i].z
pos1.x=pos1.x+1
check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
pos1.x=pos1.x-2
check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
pos1.x=pos1.x+1
pos1.y=pos1.y+1
check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
pos1.y=pos1.y-2
check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
pos1.y=pos1.y+1
pos1.z=pos1.z+1
check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
pos1.z=pos1.z-2
check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
pos1.z=pos1.z+1
return new_node_added
end
function check_LV_node_subp (PR_nodes,RE_nodes,BA_nodes,LV_nodes,pos1)
local meta = minetest.env:get_meta(pos1)
local name = minetest.env:get_node(pos1).name
if meta:get_float("cablelike")==1 then
add_new_cable_node(LV_nodes,pos1)
elseif LV_machines[name] then
--print(name.." is a "..LV_machines[name])
if LV_machines[name] == "PR" then
add_new_cable_node(PR_nodes,pos1)
elseif LV_machines[name] == "RE" then
add_new_cable_node(RE_nodes,pos1)
elseif LV_machines[name] == "BA" then
add_new_cable_node(BA_nodes,pos1)
end
end
end end

View File

@ -1,10 +1,4 @@
-- register MV machines here -- HV battery box
technic.HV_machines = {}
local HV_machines = technic.HV_machines
function register_HV_machine(string1,string2)
technic.HV_machines[string1] = string2
end
minetest.register_craft({ minetest.register_craft({
output = 'technic:hv_battery_box 1', output = 'technic:hv_battery_box 1',
recipe = { recipe = {
@ -14,7 +8,7 @@ minetest.register_craft({
} }
}) })
hv_battery_box_formspec = local battery_box_formspec =
"invsize[8,9;]".. "invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]".. "list[current_name;src;3,1;1,1;]"..
@ -35,74 +29,176 @@ minetest.register_node(
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
drop="technic:hv_battery_box", drop="technic:hv_battery_box",
on_construct = function(pos) on_construct = function(pos)
if pos==nil then return end
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
meta:set_string("infotext", "HV Battery Box") meta:set_string("infotext", "HV Battery Box")
meta:set_float("technic_hv_power_machine", 1) meta:set_float("technic_hv_power_machine", 1)
meta:set_string("formspec", battery_box_formspec) 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_float("internal_EU_charge", 0)
inv:set_size("src", 1) inv:set_size("src", 1)
inv:set_size("dst", 1) inv:set_size("dst", 1)
end, end,
can_dig = function(pos,player) can_dig = function(pos,player)
if pos==nil then return end
local meta = minetest.env:get_meta(pos); local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory() local inv = meta:get_inventory()
if not inv:is_empty("dst") then if not inv:is_empty("src") or not inv:is_empty("dst") then
return false minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
elseif not inv:is_empty("src") then
return false return false
else
return true
end end
return true
end, end,
}) })
for i=1,8,1 do for i=1,8,1 do
minetest.register_node( minetest.register_node(
"technic:hv_battery_box"..i, { "technic:hv_battery_box"..i,
description = "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_power_meter"..i..".png", 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"}, "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}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
paramtype="light", paramtype="light",
light_source=9, light_source=9,
drop="technic:hv_battery_box", drop="technic:hv_battery_box",
on_construct = function(pos) can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory() local inv = meta:get_inventory()
meta:set_string("infotext", "HV Battery box") if not inv:is_empty("src") or not inv:is_empty("dst") then
meta:set_float("technic_hv_power_machine", 1) minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
meta:set_string("formspec", battery_box_formspec) return false
inv:set_size("src", 1) else
inv:set_size("dst", 1) return true
end, end
can_dig = function(pos,player) end,
local meta = minetest.env:get_meta(pos); })
local inv = meta:get_inventory()
if not inv:is_empty("dst") then
return false
elseif not inv:is_empty("src") then
return false
end
return true
end,
})
end end
local power_tools = technic.HV_power_tools
local charge_HV_tools = function(meta, charge)
--charge registered power tools
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
local srcstack = inv:get_stack("src", 1)
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"])
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
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
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
local discharge_HV_tools = function(meta, charge, max_charge)
-- discharging registered power tools
local inv = meta:get_inventory()
if inv:is_empty("dst") == false then
srcstack = inv:get_stack("dst", 1)
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
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)
inv:set_stack("dst", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
minetest.register_abm( minetest.register_abm(
{nodenames = {"technic:hv_battery_box","technic:hv_battery_box1","technic:hv_battery_box2","technic:hv_battery_box3","technic:hv_battery_box4", {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" "technic:hv_battery_box5","technic:hv_battery_box6","technic:hv_battery_box7","technic:hv_battery_box8"
}, },
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.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
local max_charge = 1500000 local max_charge = 1500000 -- Set maximum charge for the device here
local charge = meta:get_int("internal_EU_buffer") 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
-- Power off automatically if no longer connected to a switching station
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)
else
current_charge = math.max(current_charge+eu_input, 0)
end
-- Charging/discharging tools here
current_charge = charge_HV_tools(meta, current_charge)
current_charge = discharge_HV_tools(meta, current_charge, max_charge)
-- Set a demand (we allow batteries to charge on less than the demand though)
meta:set_int("HV_EU_demand", math.min(max_charge_rate, max_charge-current_charge))
-- Set how much we can supply
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 -- Select node textures
local i = math.ceil((charge/max_charge)*8) local i=math.ceil((current_charge/max_charge)*8)
if i > 8 then i = 8 end if i > 8 then i = 8 end
local j = meta:get_float("last_side_shown") local j = meta:get_float("last_side_shown")
if i~=j then if i~=j then
@ -111,221 +207,24 @@ minetest.register_abm(
meta:set_float("last_side_shown",i) meta:set_float("last_side_shown",i)
end end
--charge registered power tools local load = math.floor(current_charge/max_charge * 100)
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
local srcstack = inv:get_stack("src", 1)
local src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
for i=1,registered_power_tools_count,1 do
if power_tools[i].tool_name==src_item["name"] then
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
-- Do the charging
local item_max_charge = power_tools[i].max_charge
local load1 = src_meta["charge"]
local load_step = 16000 -- how much to charge per tick
if load1<item_max_charge and charge>0 then
if charge-load_step<0 then load_step=charge end
if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
load1=load1+load_step
charge=charge-load_step
set_RE_wear(src_item,load1,item_max_charge)
src_meta["charge"]=load1
src_item["metadata"]=set_item_meta(src_meta)
inv:set_stack("src", 1, src_item)
end
meta:set_int("internal_EU_buffer",charge)
break
end
end
end
-- discharging registered power tools
if inv:is_empty("dst") == false then
srcstack = inv:get_stack("dst", 1)
src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
local item_max_charge=nil
for i=1,registered_power_tools_count,1 do
if power_tools[i].tool_name==src_item["name"] then
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
local item_max_charge = power_tools[i].max_charge
local load1 = src_meta["charge"]
local load_step = 16000 -- how much to discharge per tick
if load1>0 and charge<max_charge then
if charge+load_step>max_charge then load_step=max_charge-charge end
if load1-load_step<0 then load_step=load1 end
load1=load1-load_step
charge=charge+load_step
set_RE_wear(src_item,load1,item_max_charge)
src_meta["charge"]=load1
src_item["metadata"]=set_item_meta(src_meta)
inv:set_stack("dst", 1, src_item)
end
meta:set_int("internal_EU_buffer",charge)
break
end
end
end
local load = math.floor((charge/1500000) * 100)
meta:set_string("formspec", meta:set_string("formspec",
hv_battery_box_formspec.. battery_box_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]" (load)..":technic_power_meter_fg.png]"
) )
-- Next index the surrounding network the get the producers and receivers on the if eu_input == 0 then
local pos1={} meta:set_string("infotext", "HV Battery box: "..current_charge.."/"..max_charge.." (idle)")
pos1.y=pos.y-1 else
pos1.x=pos.x meta:set_string("infotext", "HV Battery box: "..current_charge.."/"..max_charge)
pos1.z=pos.z
meta1 = minetest.env:get_meta(pos1)
if meta1:get_float("hv_cablelike")~=1 then return end
local HV_nodes = {}
local PR_nodes = {}
local RE_nodes = {}
local BA_nodes = {}
HV_nodes[1]={}
HV_nodes[1].x=pos1.x
HV_nodes[1].y=pos1.y
HV_nodes[1].z=pos1.z
HV_nodes[1].visited=false
local table_index=1
repeat
check_HV_node (PR_nodes,RE_nodes,BA_nodes,HV_nodes,table_index)
table_index=table_index+1
if HV_nodes[table_index]==nil then break end
until false
-- Get power from all connected producers
local pr_pos
for _,pr_pos in ipairs(PR_nodes) do
local meta1 = minetest.env:get_meta(pr_pos)
local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
local charge_to_take = 4000
if charge<max_charge then
if internal_EU_buffer-charge_to_take<=0 then
charge_to_take=internal_EU_buffer
end
if charge_to_take>0 then
charge=charge+charge_to_take
internal_EU_buffer=internal_EU_buffer-charge_to_take
meta1:set_float("internal_EU_buffer",internal_EU_buffer)
end
end
end end
if charge>max_charge then charge=max_charge end
-- Provide power to all connected receivers
local re_pos
for _,re_pos in ipairs(RE_nodes) do
local meta1 = minetest.env:get_meta(re_pos)
local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size")
local charge_to_give = math.min(4000, charge/table.getn(RE_nodes))
if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
charge_to_give=internal_EU_buffer_size-internal_EU_buffer
end
if charge-charge_to_give<0 then charge_to_give=charge end
internal_EU_buffer=internal_EU_buffer+charge_to_give
meta1:set_float("internal_EU_buffer",internal_EU_buffer)
charge=charge-charge_to_give;
end
charge=math.floor(charge)
meta:set_string("infotext", "MV Battery box: "..charge.."/"..max_charge);
meta:set_int("internal_EU_buffer",charge)
end end
}) })
-- Register as a battery type -- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power -- Battery type machines function as power reservoirs and can both receive and give back power
register_HV_machine("technic:hv_battery_box","BA") technic.register_HV_machine("technic:hv_battery_box","BA")
for i=1,8,1 do for i=1,8,1 do
register_HV_machine("technic:hv_battery_box"..i,"BA") technic.register_HV_machine("technic:hv_battery_box"..i,"BA")
end
function add_new_HVcable_node (HV_nodes,pos1)
if HV_nodes == nil then return true end
local i=1
repeat
if HV_nodes[i]==nil then break end
if pos1.x==HV_nodes[i].x and pos1.y==HV_nodes[i].y and pos1.z==HV_nodes[i].z then return false end
i=i+1
until false
HV_nodes[i]={}
HV_nodes[i].x=pos1.x
HV_nodes[i].y=pos1.y
HV_nodes[i].z=pos1.z
return true
end
function check_HV_node(PR_nodes,RE_nodes,BA_nodes,HV_nodes,i)
local pos1={}
pos1.x=HV_nodes[i].x
pos1.y=HV_nodes[i].y
pos1.z=HV_nodes[i].z
pos1.x=pos1.x+1
check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
pos1.x=pos1.x-2
check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
pos1.x=pos1.x+1
pos1.y=pos1.y+1
check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
pos1.y=pos1.y-2
check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
pos1.y=pos1.y+1
pos1.z=pos1.z+1
check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
pos1.z=pos1.z-2
check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
pos1.z=pos1.z+1
end
function check_HV_node_subp (PR_nodes,RE_nodes,BA_nodes,HV_nodes,pos1)
local meta = minetest.env:get_meta(pos1)
local name = minetest.env:get_node(pos1).name
if meta:get_float("hv_cablelike")==1 then
add_new_HVcable_node(HV_nodes,pos1)
elseif HV_machines[name] then
--print(name.." is a "..HV_machines[name])
if HV_machines[name] == "PR" then
add_new_HVcable_node(PR_nodes,pos1)
elseif HV_machines[name] == "RE" then
add_new_HVcable_node(RE_nodes,pos1)
elseif HV_machines[name] == "BA" then
add_new_HVcable_node(BA_nodes,pos1)
end
end
end end

View File

@ -1,11 +1,4 @@
-- register MV machines here -- MV Battery box
technic.MV_machines = {}
--local MV_machines = {}
local MV_machines = technic.MV_machines
function register_MV_machine(string1,string2)
technic.MV_machines[string1] = string2
end
minetest.register_craft( minetest.register_craft(
{ {
output = 'technic:mv_battery_box 1', output = 'technic:mv_battery_box 1',
@ -16,7 +9,7 @@ minetest.register_craft(
} }
}) })
mv_battery_box_formspec = local battery_box_formspec =
"invsize[8,9;]".. "invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]".. "list[current_name;src;3,1;1,1;]"..
@ -43,73 +36,172 @@ minetest.register_node(
meta:set_string("infotext", "MV Battery box") meta:set_string("infotext", "MV Battery box")
meta:set_float("technic_mv_power_machine", 1) meta:set_float("technic_mv_power_machine", 1)
meta:set_string("formspec", battery_box_formspec) meta:set_string("formspec", battery_box_formspec)
meta:set_float("internal_EU_buffer", 0) meta:set_int("MV_EU_demand", 0) -- How much can this node charge
meta:set_float("internal_EU_buffer_size", 300000) meta:set_int("MV_EU_supply", 0) -- How much can this node discharge
meta:set_int("MV_EU_input", 0) -- How much power is this machine getting.
meta:set_float("internal_EU_charge", 0)
inv:set_size("src", 1) inv:set_size("src", 1)
inv:set_size("dst", 1) inv:set_size("dst", 1)
end, end,
can_dig = function(pos,player) can_dig = function(pos,player)
if pos==nil then return end
local meta = minetest.env:get_meta(pos); local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory() local inv = meta:get_inventory()
if not inv:is_empty("dst") then if not inv:is_empty("src") or not inv:is_empty("dst") then
return false minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
elseif not inv:is_empty("src") then
return false return false
else
return true
end end
return true end,
end
}) })
for i=1,8,1 do for i=1,8,1 do
minetest.register_node( minetest.register_node(
"technic:mv_battery_box"..i, { "technic:mv_battery_box"..i,
{
description = "MV Battery Box", description = "MV Battery Box",
tiles = {"technic_mv_battery_box_top.png", "technic_mv_battery_box_bottom.png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", tiles = {"technic_mv_battery_box_top.png", "technic_mv_battery_box_bottom.png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png"}, "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png", "technic_mv_battery_box_side0.png^technic_power_meter"..i..".png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
drop = "technic:mv_battery_box", drop = "technic:mv_battery_box",
on_construct = function(pos)
if pos==nil then return end
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
meta:set_string("infotext", "MV Battery box")
meta:set_float("technic_mv_power_machine", 1)
meta:set_string("formspec", battery_box_formspec)
meta:set_float("internal_EU_buffer", 0)
meta:set_float("internal_EU_buffer_size", 300000)
inv:set_size("src", 1)
inv:set_size("dst", 1)
end,
can_dig = function(pos,player) can_dig = function(pos,player)
if pos==nil then return end
local meta = minetest.env:get_meta(pos); local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory() local inv = meta:get_inventory()
if not inv:is_empty("dst") then if not inv:is_empty("src") or not inv:is_empty("dst") then
return false minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
elseif not inv:is_empty("src") then
return false return false
else
return true
end end
return true end,
end
}) })
end end
local power_tools = technic.MV_power_tools
local charge_MV_tools = function(meta, charge)
--charge registered power tools
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
local srcstack = inv:get_stack("src", 1)
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"])
if src_meta==nil then
src_meta={}
src_meta["technic_mv_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_mv_power_tool"]==nil then
src_meta["technic_mv_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
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
local discharge_MV_tools = function(meta, charge, max_charge)
-- discharging registered power tools
local inv = meta:get_inventory()
if inv:is_empty("dst") == false then
srcstack = inv:get_stack("dst", 1)
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_mv_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_mv_power_tool"]==nil then
src_meta["technic_mv_power_tool"]=true
src_meta["charge"]=0
end
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)
inv:set_stack("dst", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
minetest.register_abm( minetest.register_abm(
{nodenames = {"technic:mv_battery_box","technic:mv_battery_box1","technic:mv_battery_box2","technic:mv_battery_box3","technic:mv_battery_box4", {
"technic:mv_battery_box5","technic:mv_battery_box6","technic:mv_battery_box7","technic:mv_battery_box8" nodenames = {"technic:mv_battery_box","technic:mv_battery_box1","technic:mv_battery_box2","technic:mv_battery_box3","technic:mv_battery_box4",
}, "technic:mv_battery_box5","technic:mv_battery_box6","technic:mv_battery_box7","technic:mv_battery_box8"
interval = 1, },
chance = 1, interval = 1,
action = function(pos, node, active_object_count, active_object_count_wider) chance = 1,
local meta = minetest.env:get_meta(pos) action = function(pos, node, active_object_count, active_object_count_wider)
local max_charge = 300000 -- Set maximum charge for the device here local meta = minetest.env:get_meta(pos)
local charge = meta:get_int("internal_EU_buffer") local max_charge = 300000 -- Set maximum charge for the device here
local max_charge_rate = 2000 -- Set maximum rate of charging (4000)
local max_discharge_rate = 3000 -- Set maximum rate of discharging
local eu_input = meta:get_int("MV_EU_input")
local current_charge = meta:get_int("internal_EU_charge") -- Battery charge right now
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "MV")
-- 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
current_charge = charge_MV_tools(meta, current_charge)
current_charge = discharge_MV_tools(meta, current_charge, max_charge)
-- Set a demand (we allow batteries to charge on less than the demand though)
meta:set_int("MV_EU_demand", math.min(max_charge_rate, max_charge-current_charge))
-- Set how much we can supply
meta:set_int("MV_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("MV_EU_supply").." demand="..meta:get_int("MV_EU_demand").." current:"..current_charge)
-- Select node textures -- Select node textures
local i = math.ceil((charge/max_charge)*8) local i=math.ceil((current_charge/max_charge)*8)
if i > 8 then i = 8 end if i > 8 then i = 8 end
local j = meta:get_float("last_side_shown") local j = meta:get_float("last_side_shown")
if i~=j then if i~=j then
@ -118,221 +210,24 @@ minetest.register_abm(
meta:set_float("last_side_shown",i) meta:set_float("last_side_shown",i)
end end
--charge registered power tools local load = math.floor(current_charge/max_charge * 100)
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
local srcstack = inv:get_stack("src", 1)
local src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
-- Power tools should really be made into a hash table to avoid linear search. But the list is short so okay...
for i=1,registered_power_tools_count,1 do
if power_tools[i].tool_name==src_item["name"] then
-- What is this code doing? Setting tool properties if not set already????
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
-- Do the charging
local item_max_charge = power_tools[i].max_charge
local load1 = src_meta["charge"]
local load_step = 4000 -- how much to charge per tick
if load1<item_max_charge and charge>0 then
if charge-load_step<0 then load_step=charge end
if load1+load_step>item_max_charge then load_step=item_max_charge-load1 end
load1=load1+load_step
charge=charge-load_step
set_RE_wear(src_item,load1,item_max_charge)
src_meta["charge"] = load1
src_item["metadata"] = set_item_meta(src_meta)
inv:set_stack("src", 1, src_item)
end
meta:set_int("internal_EU_buffer",charge)
break
end
end
end
-- discharging registered power tools
if inv:is_empty("dst") == false then
srcstack = inv:get_stack("dst", 1)
src_item=srcstack:to_table()
local src_meta=get_item_meta(src_item["metadata"])
local item_max_charge=nil
for i=1,registered_power_tools_count,1 do
if power_tools[i].tool_name==src_item["name"] then
src_meta=get_item_meta(src_item["metadata"])
if src_meta==nil then
src_meta={}
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
else
if src_meta["technic_power_tool"]==nil then
src_meta["technic_power_tool"]=true
src_meta["charge"]=0
end
end
local item_max_charge = power_tools[i].max_charge
local load1 = src_meta["charge"]
local load_step = 4000 -- how much to discharge per tick
if load1>0 and charge<max_charge then
if charge+load_step>max_charge then load_step=max_charge-charge end
if load1-load_step<0 then load_step=load1 end
load1=load1-load_step
charge=charge+load_step
set_RE_wear(src_item,load1,item_max_charge)
src_meta["charge"]=load1
src_item["metadata"]=set_item_meta(src_meta)
inv:set_stack("dst", 1, src_item)
end
meta:set_int("internal_EU_buffer",charge)
break
end
end
end
local load = math.floor((charge/300000) * 100)
meta:set_string("formspec", meta:set_string("formspec",
mv_battery_box_formspec.. battery_box_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]" (load)..":technic_power_meter_fg.png]"
) )
-- Next index the surrounding network the get the producers and receivers on the power grid if eu_input == 0 then
local pos1 = {} meta:set_string("infotext", "MV Battery box: "..current_charge.."/"..max_charge.." (idle)")
pos1.y = pos.y-1 else
pos1.x = pos.x meta:set_string("infotext", "MV Battery box: "..current_charge.."/"..max_charge)
pos1.z = pos.z
meta1 = minetest.env:get_meta(pos1)
if meta1:get_float("mv_cablelike")~=1 then return end
local MV_nodes = {}
local PR_nodes = {}
local RE_nodes = {}
local BA_nodes = {}
MV_nodes[1] = {}
MV_nodes[1].x = pos1.x
MV_nodes[1].y = pos1.y
MV_nodes[1].z = pos1.z
local table_index=1
repeat
check_MV_node(PR_nodes,RE_nodes,BA_nodes,MV_nodes,table_index)
table_index=table_index+1
if MV_nodes[table_index]==nil then break end
until false
-- Get power from all connected producers
local pr_pos
for _,pr_pos in ipairs(PR_nodes) do
local meta1 = minetest.env:get_meta(pr_pos)
local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
local charge_to_take = 1000
if charge<max_charge then
if internal_EU_buffer-charge_to_take<=0 then
charge_to_take=internal_EU_buffer
end
if charge_to_take>0 then
charge=charge+charge_to_take
internal_EU_buffer=internal_EU_buffer-charge_to_take
meta1:set_float("internal_EU_buffer",internal_EU_buffer)
end
end
end end
if charge>max_charge then charge=max_charge end
-- Provide power to all connected receivers
local re_pos
for _,re_pos in ipairs(RE_nodes) do
local meta1 = minetest.env:get_meta(re_pos)
local internal_EU_buffer = meta1:get_float("internal_EU_buffer")
local internal_EU_buffer_size = meta1:get_float("internal_EU_buffer_size")
local charge_to_give = math.min(1000, charge/table.getn(RE_nodes))
if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
charge_to_give=internal_EU_buffer_size-internal_EU_buffer
end
if charge-charge_to_give<0 then charge_to_give=charge end
internal_EU_buffer=internal_EU_buffer+charge_to_give
meta1:set_float("internal_EU_buffer",internal_EU_buffer)
charge=charge-charge_to_give;
end
charge=math.floor(charge)
meta:set_string("infotext", "MV Battery box: "..charge.."/"..max_charge);
meta:set_int("internal_EU_buffer",charge)
end end
}) })
-- Register as a battery type -- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power -- Battery type machines function as power reservoirs and can both receive and give back power
register_MV_machine("technic:mv_battery_box","BA") technic.register_MV_machine("technic:mv_battery_box","BA")
for i=1,8,1 do for i=1,8,1 do
register_MV_machine("technic:mv_battery_box"..i,"BA") technic.register_MV_machine("technic:mv_battery_box"..i,"BA")
end
function add_new_MVcable_node (MV_nodes,pos1)
if MV_nodes == nil then return true end
local i=1
repeat
if MV_nodes[i]==nil then break end
if pos1.x==MV_nodes[i].x and pos1.y==MV_nodes[i].y and pos1.z==MV_nodes[i].z then return false end
i=i+1
until false
MV_nodes[i]={}
MV_nodes[i].x=pos1.x
MV_nodes[i].y=pos1.y
MV_nodes[i].z=pos1.z
return true
end
function check_MV_node(PR_nodes,RE_nodes,BA_nodes,MV_nodes,i)
local pos1={}
pos1.x=MV_nodes[i].x
pos1.y=MV_nodes[i].y
pos1.z=MV_nodes[i].z
pos1.x=pos1.x+1
check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
pos1.x=pos1.x-2
check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
pos1.x=pos1.x+1
pos1.y=pos1.y+1
check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
pos1.y=pos1.y-2
check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
pos1.y=pos1.y+1
pos1.z=pos1.z+1
check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
pos1.z=pos1.z-2
check_MV_node_subp(PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
pos1.z=pos1.z+1
end
function check_MV_node_subp (PR_nodes,RE_nodes,BA_nodes,MV_nodes,pos1)
local meta = minetest.env:get_meta(pos1)
local name = minetest.env:get_node(pos1).name
if meta:get_float("mv_cablelike")==1 then
add_new_MVcable_node(MV_nodes,pos1)
elseif MV_machines[name] then
--print(name.." is a "..MV_machines[name])
if MV_machines[name] == "PR" then
add_new_MVcable_node(PR_nodes,pos1)
elseif MV_machines[name] == "RE" then
add_new_MVcable_node(RE_nodes,pos1)
elseif MV_machines[name] == "BA" then
add_new_MVcable_node(BA_nodes,pos1)
end
end
end end

View File

@ -1,5 +1,5 @@
water_can_max_load = 16 local water_can_max_load = 16
lava_can_max_load = 8 local lava_can_max_load = 8
minetest.register_craft({ minetest.register_craft({
output = 'technic:water_can 1', output = 'technic:water_can 1',
@ -42,7 +42,7 @@ minetest.register_tool("technic:water_can", {
minetest.env:add_node(pointed_thing.under, {name="air"}) minetest.env:add_node(pointed_thing.under, {name="air"})
load=load+1; load=load+1;
item["metadata"]=tostring(load) item["metadata"]=tostring(load)
set_RE_wear(item,load,water_can_max_load) technic.set_RE_wear(item,load,water_can_max_load)
itemstack:replace(item) itemstack:replace(item)
end end
return itemstack return itemstack
@ -54,7 +54,7 @@ minetest.register_tool("technic:water_can", {
minetest.env:add_node(pointed_thing.under, {name="default:water_source"}) minetest.env:add_node(pointed_thing.under, {name="default:water_source"})
load=load-1; load=load-1;
item["metadata"]=tostring(load) item["metadata"]=tostring(load)
set_RE_wear(item,load,water_can_max_load) technic.set_RE_wear(item,load,water_can_max_load)
itemstack:replace(item) itemstack:replace(item)
return itemstack return itemstack
end end
@ -64,7 +64,7 @@ minetest.register_tool("technic:water_can", {
minetest.env:add_node(pointed_thing.above, {name="default:water_source"}) minetest.env:add_node(pointed_thing.above, {name="default:water_source"})
load=load-1; load=load-1;
item["metadata"]=tostring(load) item["metadata"]=tostring(load)
set_RE_wear(item,load,water_can_max_load) technic.set_RE_wear(item,load,water_can_max_load)
itemstack:replace(item) itemstack:replace(item)
return itemstack return itemstack
end end
@ -90,7 +90,7 @@ minetest.register_tool("technic:lava_can", {
minetest.env:add_node(pointed_thing.under, {name="air"}) minetest.env:add_node(pointed_thing.under, {name="air"})
load=load+1; load=load+1;
item["metadata"]=tostring(load) item["metadata"]=tostring(load)
set_RE_wear(item,load,lava_can_max_load) technic.set_RE_wear(item,load,lava_can_max_load)
itemstack:replace(item) itemstack:replace(item)
end end
return itemstack return itemstack
@ -102,7 +102,7 @@ minetest.register_tool("technic:lava_can", {
minetest.env:add_node(pointed_thing.under, {name="default:lava_source"}) minetest.env:add_node(pointed_thing.under, {name="default:lava_source"})
load=load-1; load=load-1;
item["metadata"]=tostring(load) item["metadata"]=tostring(load)
set_RE_wear(item,load,lava_can_max_load) technic.set_RE_wear(item,load,lava_can_max_load)
itemstack:replace(item) itemstack:replace(item)
return itemstack return itemstack
end end
@ -112,7 +112,7 @@ minetest.register_tool("technic:lava_can", {
minetest.env:add_node(pointed_thing.above, {name="default:lava_source"}) minetest.env:add_node(pointed_thing.above, {name="default:lava_source"})
load=load-1; load=load-1;
item["metadata"]=tostring(load) item["metadata"]=tostring(load)
set_RE_wear(item,load,lava_can_max_load) technic.set_RE_wear(item,load,lava_can_max_load)
itemstack:replace(item) itemstack:replace(item)
return itemstack return itemstack
end end

View File

@ -3,7 +3,7 @@ local chainsaw_max_charge = 30000 -- 30000 - Maximum charge of the saw
local chainsaw_charge_per_node = 12 -- 12 - Gives 2500 nodes on a single charge (about 50 complete normal trees) local chainsaw_charge_per_node = 12 -- 12 - Gives 2500 nodes on a single charge (about 50 complete normal trees)
local chainsaw_leaves = true -- true - Cut down entire trees, leaves and all local chainsaw_leaves = true -- true - Cut down entire trees, leaves and all
register_power_tool ("technic:chainsaw",chainsaw_max_charge) technic.register_LV_power_tool ("technic:chainsaw",chainsaw_max_charge)
minetest.register_tool("technic:chainsaw", { minetest.register_tool("technic:chainsaw", {
description = "Chainsaw", description = "Chainsaw",
@ -20,7 +20,7 @@ minetest.register_tool("technic:chainsaw", {
if charge < chainsaw_charge_per_node then return end -- only cut if charged if charge < chainsaw_charge_per_node then return end -- only cut if charged
charge=chainsaw_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,charge) charge=chainsaw_dig_it(minetest.get_pointed_thing_position(pointed_thing, above),user,charge)
set_RE_wear(item,charge,chainsaw_max_charge) technic.set_RE_wear(item,charge,chainsaw_max_charge)
meta["charge"]=charge meta["charge"]=charge
item["metadata"]=set_item_meta(meta) item["metadata"]=set_item_meta(meta)
itemstack:replace(item) itemstack:replace(item)

View File

@ -1,8 +1,8 @@
-- Technic CNC v1.0 by kpo -- Technic CNC v1.0 by kpoppel
-- Based on the NonCubic Blocks MOD v1.4 by yves_de_beck -- Based on the NonCubic Blocks MOD v1.4 by yves_de_beck
-- Idea: -- Idea:
-- Somehw have a tabbed/paged panel if the number of shapes should expand -- Somehow have a tabbed/paged panel if the number of shapes should expand
-- beyond what is available in the panel today. -- beyond what is available in the panel today.
-- I could imagine some form of API allowing modders to come with their own node -- I could imagine some form of API allowing modders to come with their own node
-- box definitions and easily stuff it in the this machine for production. -- box definitions and easily stuff it in the this machine for production.
@ -32,24 +32,6 @@ local twosize_products = {
element_edge = 2, element_edge = 2,
} }
--cnc_recipes ={}
--registered_cnc_recipes_count=1
--
--function register_cnc_recipe (string1,string2)
-- cnc_recipes[registered_cnc_recipes_count]={}
-- cnc_recipes[registered_cnc_recipes_count].src_name=string1
-- cnc_recipes[registered_cnc_recipes_count].dst_name=string2
-- registered_cnc_recipes_count=registered_cnc_recipes_count+1
-- if unified_inventory then
-- unified_inventory.register_craft({
-- type = "cnc milling",
-- output = string2,
-- items = {string1},
-- width = 0,
-- })
-- end
--end
local cnc_formspec = local cnc_formspec =
"invsize[9,11;]".. "invsize[9,11;]"..
"label[1,0;Choose Milling Program:]".. "label[1,0;Choose Milling Program:]"..
@ -88,215 +70,212 @@ local cnc_formspec =
"list[current_player;main;0,7;8,4;]" "list[current_player;main;0,7;8,4;]"
local cnc_power_formspec=
"label[0,3;Power]"..
"image[0,1;1,2;technic_power_meter_bg.png]"
local size = 1; local size = 1;
-- The form handler is declared here because we need it in both the inactive and active modes -- The form handler is declared here because we need it in both the inactive and active modes
-- in order to be able to change programs wile it is running. -- in order to be able to change programs wile it is running.
local form_handler = function(pos, formname, fields, sender) local form_handler = function(pos, formname, fields, sender)
-- REGISTER MILLING PROGRAMS AND OUTPUTS: -- REGISTER MILLING PROGRAMS AND OUTPUTS:
------------------------------------------ ------------------------------------------
-- Program for half/full size -- Program for half/full size
if fields["full"] then if fields["full"] then
size = 1 size = 1
return return
end end
if fields["half"] then if fields["half"] then
size = 2 size = 2
return return
end end
-- Resolve the node name and the number of items to make -- Resolve the node name and the number of items to make
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local inputstack = inv:get_stack("src", 1) local inputstack = inv:get_stack("src", 1)
local inputname = inputstack:get_name() local inputname = inputstack:get_name()
local multiplier = 0 local multiplier = 0
for k, _ in pairs(fields) do for k, _ in pairs(fields) do
-- Set a multipier for the half/full size capable blocks -- Set a multipier for the half/full size capable blocks
if twosize_products[k] ~= nil then if twosize_products[k] ~= nil then
multiplier = size*twosize_products[k] multiplier = size*twosize_products[k]
else else
multiplier = onesize_products[k] multiplier = onesize_products[k]
end end
if onesize_products[k] ~= nil or twosize_products[k] ~= nil then if onesize_products[k] ~= nil or twosize_products[k] ~= nil then
meta:set_float( "cnc_multiplier", multiplier) meta:set_float( "cnc_multiplier", multiplier)
meta:set_string("cnc_user", sender:get_player_name()) meta:set_string("cnc_user", sender:get_player_name())
end end
if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then
meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k) meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k)
print(inputname .. "_technic_cnc_" .. k) --print(inputname .. "_technic_cnc_" .. k)
break break
end end
if twosize_products[k] ~= nil and size==1 then if twosize_products[k] ~= nil and size==1 then
meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double") meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double")
print(inputname .. "_technic_cnc_" .. k .. "_double") --print(inputname .. "_technic_cnc_" .. k .. "_double")
break break
end end
end end
return return
end -- callback function end -- callback function
-- The actual block inactive state -- The actual block inactive state
minetest.register_node("technic:cnc", { minetest.register_node(
description = "CNC Milling Machine", "technic:cnc",
tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png", {
"technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front.png"}, description = "CNC Milling Machine",
drawtype = "nodebox", tiles = {"technic_cnc_top.png", "technic_cnc_bottom.png", "technic_cnc_side.png",
paramtype = "light", "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front.png"},
paramtype2 = "facedir", drawtype = "nodebox",
node_box = { paramtype = "light",
type = "fixed", paramtype2 = "facedir",
fixed = { node_box = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
}, },
}, },
selection_box = { selection_box = {
type = "fixed", type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
}, },
groups = {cracky=2}, groups = {cracky=2},
legacy_facedir_simple = true, legacy_facedir_simple = true,
technic_power_machine=1, on_construct = function(pos)
internal_EU_buffer=0; local meta = minetest.env:get_meta(pos)
internal_EU_buffer_size=5000; meta:set_string("infotext", "CNC Machine")
cnc_time = 0; meta:set_float("technic_power_machine", 1)
src_time = 0; -- fixme meta:set_string("formspec", cnc_formspec)
local inv = meta:get_inventory()
on_construct = function(pos) inv:set_size("src", 1)
local meta = minetest.env:get_meta(pos) inv:set_size("dst", 4)
meta:set_string("infotext", "CNC Machine Inactive") end,
meta:set_float("technic_power_machine", 1) can_dig = function(pos,player)
meta:set_float("internal_EU_buffer", 0) local meta = minetest.env:get_meta(pos);
meta:set_float("internal_EU_buffer_size", 5000) local inv = meta:get_inventory()
meta:set_string("formspec", cnc_formspec..cnc_power_formspec) if not inv:is_empty("src") or not inv:is_empty("dst") then
meta:set_float("cnc_time", 0) minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
return false
local inv = meta:get_inventory() else
inv:set_size("src", 1) return true
inv:set_size("dst", 4) end
end, end,
on_receive_fields = form_handler,
can_dig = function(pos,player) })
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") or not inv:is_empty("dst") then
minetest.chat_send_player(player:get_player_name(), "CNC machine cannot be removed because it is not empty");
return false
end
return true
end,
on_receive_fields = form_handler,
})
-- Active state block -- Active state block
minetest.register_node("technic:cnc_active", { minetest.register_node("technic:cnc_active", {
description = "CNC Machine", description = "CNC Machine",
tiles = {"technic_cnc_top_active.png", "technic_cnc_bottom.png", "technic_cnc_side.png", tiles = {"technic_cnc_top_active.png", "technic_cnc_bottom.png", "technic_cnc_side.png",
"technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"}, "technic_cnc_side.png", "technic_cnc_side.png", "technic_cnc_front_active.png"},
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {cracky=2,not_in_creative_inventory=1}, groups = {cracky=2,not_in_creative_inventory=1},
legacy_facedir_simple = true, legacy_facedir_simple = true,
can_dig = function(pos,player) can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos); local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory() local inv = meta:get_inventory()
if not inv:is_empty("src") or not inv:is_empty("dst") then if not inv:is_empty("src") or not inv:is_empty("dst") then
minetest.chat_send_player(player:get_player_name(), "CNC machine cannot be removed because it is not empty"); minetest.chat_send_player(player:get_player_name(), "CNC machine cannot be removed because it is not empty");
return false return false
end end
return true return true
end, end,
on_receive_fields = form_handler, on_receive_fields = form_handler,
}) })
-- Action code performing the transformation -- Action code performing the transformation
minetest.register_abm( minetest.register_abm(
{ { nodenames = {"technic:cnc","technic:cnc_active"},
nodenames = {"technic:cnc","technic:cnc_active"}, 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.env:get_meta(pos)
local meta = minetest.env:get_meta(pos) local eu_input = meta:get_int("LV_EU_input")
local charge= meta:get_float("internal_EU_buffer") local state = meta:get_int("state")
local max_charge= meta:get_float("internal_EU_buffer_size") local next_state = state
local cnc_cost=350
local load = math.floor((charge/max_charge)*100) -- Machine information
meta:set_string("formspec", cnc_formspec.. local machine_name = "CNC"
"image[0,1;1,2;technic_power_meter_bg.png^[lowpart:".. local machine_node = "technic:cnc"
(load)..":technic_power_meter_fg.png]" local machine_state_demand = { 50, 450 }
)
local inv = meta:get_inventory() -- Setup meta data if it does not exist. state is used as an indicator of this
local srclist = inv:get_list("src") if state == 0 then
if inv:is_empty("src") then meta:set_int("state", 1)
meta:set_float("cnc_on",0) meta:set_int("LV_EU_demand", machine_state_demand[1])
meta:set_string("cnc_product", "") -- Reset the program meta:set_int("LV_EU_input", 0)
end return
end
if (meta:get_float("cnc_on") == 1) then -- Power off automatically if no longer connected to a switching station
if charge>=cnc_cost then technic.switching_station_timeout_count(pos, "LV")
charge=charge-cnc_cost;
meta:set_float("internal_EU_buffer",charge)
meta:set_float("src_time", meta:get_float("src_time") + 1)
if meta:get_float("src_time") >= meta:get_float("cnc_time") then
local product = meta:get_string("cnc_product")
if inv:room_for_item("dst",product) then
-- CNC does the transformation
------------------------------
if minetest.registered_nodes[product] ~= nil then
inv:add_item("dst",product .. " " .. meta:get_float("cnc_multiplier"))
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src",1,srcstack)
if inv:is_empty("src") then
meta:set_float("cnc_on",0)
meta:set_string("cnc_product", "") -- Reset the program
-- print("cnc product reset")
end
else
minetest.chat_send_player(meta:get_string("cnc_user"), "CNC machine does not know how to handle this material. Please remove it.");
end
else
minetest.chat_send_player(meta:get_string("cnc_user"), "CNC inventory full!")
end
meta:set_float("src_time", 0)
end
end
end
if (meta:get_float("cnc_on")==0) then -- State machine
if not inv:is_empty("src") then if eu_input == 0 then
local product = meta:get_string("cnc_product") -- Unpowered - go idle
if minetest.registered_nodes[product] ~= nil then hacky_swap_node(pos, machine_node)
meta:set_float("cnc_on",1) meta:set_string("infotext", machine_name.." Unpowered")
hacky_swap_node(pos,"technic:cnc_active") next_state = 1
meta:set_string("infotext", "CNC Machine Active") elseif eu_input == machine_state_demand[state] then
cnc_time=3 -- Powered - do the state specific actions
meta:set_float("cnc_time",cnc_time)
meta:set_float("src_time", 0)
return
end
else
hacky_swap_node(pos,"technic:cnc")
meta:set_string("infotext", "CNC Machine Inactive")
end
end
end
})
register_LV_machine ("technic:cnc","RE") local inv = meta:get_inventory()
register_LV_machine ("technic:cnc_active","RE") local empty = inv:is_empty("src")
if state == 1 then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
local result = meta:get_string("cnc_product")
if not empty and minetest.registered_nodes[result] ~= nil and inv:room_for_item("dst",result) then
next_state = 2
else
meta:set_string("cnc_product", "") -- Reset the program
end
--minetest.chat_send_player(meta:get_string("cnc_user"), "CNC machine does not know how to handle this material. Please remove it.");
elseif state == 2 then
hacky_swap_node(pos, machine_node.."_active")
meta:set_string("infotext", machine_name.." Active")
if empty then
next_state = 1
else
meta:set_int("src_time", meta:get_int("src_time") + 1)
if meta:get_int("src_time") >= 3 then -- 3 ticks per output
local result = meta:get_string("cnc_product")
-- check if there's room for output in "dst" list
if inv:room_for_item("dst",result) then
-- CNC does the transformation
------------------------------
meta:set_int("src_time", 0)
-- take stuff from "src" list
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
-- Put result in "dst" list
inv:add_item("dst",result .. " " .. meta:get_int("cnc_multiplier"))
else
next_state = 1
end
end
end
end
end
-- Change state?
if next_state ~= state then
meta:set_int("LV_EU_demand", machine_state_demand[next_state])
meta:set_int("state", next_state)
end
end
})
technic.register_LV_machine ("technic:cnc","RE")
technic.register_LV_machine ("technic:cnc_active","RE")
------------------------- -------------------------
-- CNC Machine Recipe -- CNC Machine Recipe

View File

@ -1,173 +1,159 @@
minetest.register_craft({ -- LV Electric Furnace
output = 'technic:electric_furnace', -- This is a faster version of the stone furnace which runs on EUs
recipe = {
{'default:cobble', 'default:cobble', 'default:cobble'},
{'default:cobble', '', 'default:cobble'},
{'default:steel_ingot', 'moreores:copper_ingot', 'default:steel_ingot'},
}
})
-- FIXME: kpoppel I'd like to introduce an induction heating element here also
minetest.register_craft(
{output = 'technic:electric_furnace',
recipe = {
{'default:cobble', 'default:cobble', 'default:cobble'},
{'default:cobble', '', 'default:cobble'},
{'default:steel_ingot', 'moreores:copper_ingot', 'default:steel_ingot'},
}
})
electric_furnace_formspec = local electric_furnace_formspec =
"invsize[8,9;]".. "invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "list[current_name;src;3,1;1,1;]"..
"list[current_name;src;3,1;1,1;]".. "list[current_name;dst;5,1;2,2;]"..
"list[current_name;dst;5,1;2,2;]".. "list[current_player;main;0,5;8,4;]"..
"list[current_player;main;0,5;8,4;]".. "label[0,0;Electric Furnace]"..
"label[0,0;Electric Furnace]".. "label[1,3;Power level]"
"label[1,3;Power level]"
minetest.register_node("technic:electric_furnace", { minetest.register_node(
description = "Electric furnace", "technic:electric_furnace",
tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png", {description = "Electric furnace",
"technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front.png"}, tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png",
paramtype2 = "facedir", "technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front.png"},
groups = {cracky=2}, paramtype2 = "facedir",
legacy_facedir_simple = true, groups = {cracky=2},
sounds = default.node_sound_stone_defaults(), legacy_facedir_simple = true,
technic_power_machine=1, sounds = default.node_sound_stone_defaults(),
internal_EU_buffer=0; on_construct = function(pos)
interal_EU_buffer_size=2000; local meta = minetest.env:get_meta(pos)
on_construct = function(pos) meta:set_string("infotext", "Electric Furnace")
local meta = minetest.env:get_meta(pos) meta:set_float("technic_power_machine", 1)
meta:set_float("technic_power_machine", 1) meta:set_string("formspec", electric_furnace_formspec)
meta:set_string("formspec", electric_furnace_formspec) local inv = meta:get_inventory()
meta:set_string("infotext", "Electric furnace") inv:set_size("src", 1)
local inv = meta:get_inventory() inv:set_size("dst", 4)
inv:set_size("src", 1) end,
inv:set_size("dst", 4) can_dig = function(pos,player)
local EU_used = 0 local meta = minetest.env:get_meta(pos);
local furnace_is_cookin = 0 local inv = meta:get_inventory()
local cooked = nil if not inv:is_empty("src") or not inv:is_empty("dst") then
meta:set_float("internal_EU_buffer",0) minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
meta:set_float("internal_EU_buffer_size",2000) return false
else
return true
end
end,
})
end, minetest.register_node(
can_dig = function(pos,player) "technic:electric_furnace_active",
local meta = minetest.env:get_meta(pos); {description = "Electric Furnace",
local inv = meta:get_inventory() tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png",
if not inv:is_empty("dst") then "technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front_active.png"},
return false paramtype2 = "facedir",
elseif not inv:is_empty("src") then light_source = 8,
return false drop = "technic:electric_furnace",
end groups = {cracky=2, not_in_creative_inventory=1},
return true legacy_facedir_simple = true,
end, sounds = default.node_sound_stone_defaults(),
}) can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") or not inv:is_empty("dst") then
minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
return false
else
return true
end
end,
})
minetest.register_node("technic:electric_furnace_active", { minetest.register_abm(
description = "Electric Furnace", { nodenames = {"technic:electric_furnace","technic:electric_furnace_active"},
tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png", interval = 1,
"technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front_active.png"}, chance = 1,
paramtype2 = "facedir", action = function(pos, node, active_object_count, active_object_count_wider)
light_source = 8, local meta = minetest.env:get_meta(pos)
drop = "technic:electric_furnace", local eu_input = meta:get_int("LV_EU_input")
groups = {cracky=2, not_in_creative_inventory=1}, local state = meta:get_int("state")
legacy_facedir_simple = true, local next_state = state
sounds = default.node_sound_stone_defaults(),
internal_EU_buffer=0;
interal_EU_buffer_size=2000;
technic_power_machine=1,
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", electric_furnace_formspec)
meta:set_string("infotext", "Electric furnace");
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
local EU_used = 0
local furnace_is_cookin = 0
local cooked = nil
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("dst") then
return false
elseif not inv:is_empty("src") then
return false
end
return true
end,
})
minetest.register_abm({ -- Machine information
nodenames = {"technic:electric_furnace","technic:electric_furnace_active"}, local machine_name = "Electric furnace"
interval = 1, local machine_node = "technic:electric_furnace"
chance = 1, local machine_state_demand = { 50, 1000 }
action = function(pos, node, active_object_count, active_object_count_wider) -- Setup meta data if it does not exist. state is used as an indicator of this
if state == 0 then
meta:set_int("state", 1)
meta:set_int("LV_EU_demand", machine_state_demand[1])
meta:set_int("LV_EU_input", 0)
return
end
local meta = minetest.env:get_meta(pos) -- Power off automatically if no longer connected to a switching station
internal_EU_buffer=meta:get_float("internal_EU_buffer") technic.switching_station_timeout_count(pos, "LV")
internal_EU_buffer_size=meta:get_float("internal_EU_buffer_size")
local load = math.floor(internal_EU_buffer/internal_EU_buffer_size * 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]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"..
"label[0,0;Electric Furnace]"..
"label[1,3;Power level]")
local inv = meta:get_inventory() -- State machine
if eu_input == 0 then
-- Unpowered - go idle
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
next_state = 1
elseif eu_input == machine_state_demand[state] then
-- Powered - do the state specific actions
local furnace_is_cookin = meta:get_float("furnace_is_cookin") -- Execute always if powered logic
local inv = meta:get_inventory()
local empty = inv:is_empty("src")
if state == 1 then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
local srclist = inv:get_list("src") local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")})
local cooked=nil if not empty and result and inv:room_for_item("dst",result) then
next_state = 2
end
if srclist then elseif state == 2 then
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) hacky_swap_node(pos, machine_node.."_active")
end meta:set_string("infotext", machine_name.." Active")
if empty then
next_state = 1
else
meta:set_int("src_time", meta:get_int("src_time") + 3) -- Cooking time 3x
local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")})
if result and result.item and meta:get_int("src_time") >= result.time then
-- check if there's room for output in "dst" list
meta:set_int("src_time", 0)
if inv:room_for_item("dst",result.item) then
-- take stuff from "src" list
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
-- Put result in "dst" list
inv:add_item("dst", result.item)
else
-- all full: go idle
next_state = 1
end
end
end
end
end
-- Change state?
if next_state ~= state then
meta:set_int("LV_EU_demand", machine_state_demand[next_state])
meta:set_int("state", next_state)
end
end,
})
if (furnace_is_cookin == 1) then technic.register_LV_machine ("technic:electric_furnace","RE")
if internal_EU_buffer>=150 then technic.register_LV_machine ("technic:electric_furnace_active","RE")
internal_EU_buffer=internal_EU_buffer-150;
meta:set_float("internal_EU_buffer",internal_EU_buffer)
meta:set_float("src_time", meta:get_float("src_time") + 3)
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
-- check if there's room for output in "dst" list
if inv:room_for_item("dst",cooked.item) then
-- Put result in "dst" list
inv:add_item("dst", cooked.item)
-- take stuff from "src" list
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
else
print("Furnace inventory full!")
end
meta:set_string("src_time", 0)
end
end
end
if srclist then
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
if cooked.time>0 then
hacky_swap_node(pos,"technic:electric_furnace_active")
meta:set_string("infotext","Furnace active")
meta:set_string("furnace_is_cookin",1)
meta:set_string("src_time", 0)
return
end
end
hacky_swap_node(pos,"technic:electric_furnace")
meta:set_string("infotext","Furnace inactive")
meta:set_string("furnace_is_cookin",0)
meta:set_string("src_time", 0)
end,
})
register_LV_machine ("technic:electric_furnace","RE")
register_LV_machine ("technic:electric_furnace_active","RE")

View File

@ -1,279 +1,304 @@
minetest.register_craft({ -- MV Electric Furnace
output = 'technic:mv_electric_furnace', -- This is a faster version of the stone furnace which runs on EUs
recipe = { -- In addition to this it can be upgraded with microcontrollers and batteries
{'technic:stainless_steel_ingot', 'technic:electric_furnace', 'technic:stainless_steel_ingot'}, -- This new version uses the batteries to lower the power consumption of the machine
{'pipeworks:tube_000000', 'technic:mv_transformer', 'pipeworks:tube_000000'}, -- Also in addition this furnace can be attached to the pipe system from the pipeworks mod.
{'technic:stainless_steel_ingot', 'technic:mv_cable', 'technic:stainless_steel_ingot'},
}
})
-- FIXME: kpoppel I'd like to introduce an induction heating element here also
minetest.register_craft(
{output = 'technic:mv_electric_furnace',
recipe = {
{'technic:stainless_steel_ingot', 'technic:electric_furnace', 'technic:stainless_steel_ingot'},
{'pipeworks:tube_000000', 'technic:mv_transformer', 'pipeworks:tube_000000'},
{'technic:stainless_steel_ingot', 'technic:mv_cable', 'technic:stainless_steel_ingot'},
}
})
mv_electric_furnace_formspec = local mv_electric_furnace_formspec =
"invsize[8,10;]".. "invsize[8,10;]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "list[current_name;src;3,1;1,1;]"..
"list[current_name;src;3,1;1,1;]".. "list[current_name;dst;5,1;2,2;]"..
"list[current_name;dst;5,1;2,2;]".. "list[current_player;main;0,6;8,4;]"..
"list[current_player;main;0,6;8,4;]".. "label[0,0;MV Electric Furnace]"..
"label[0,0;MV Electric Furnace]".. "list[current_name;upgrade1;1,4;1,1;]"..
"label[1,2.8;Power level]".. "list[current_name;upgrade2;2,4;1,1;]"..
"list[current_name;upgrade1;1,4;1,1;]".. "label[1,5;Upgrade Slots]"
"list[current_name;upgrade2;2,4;1,1;]"..
"label[1,5;Upgrade Slots]"
minetest.register_node("technic:mv_electric_furnace", { minetest.register_node(
description = "MV Electric furnace", "technic:mv_electric_furnace",
tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png", {description = "MV Electric furnace",
"technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front.png"}, tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png",
paramtype2 = "facedir", "technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front.png"},
groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,}, paramtype2 = "facedir",
tube={insert_object=function(pos,node,stack,direction) groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,},
local meta=minetest.env:get_meta(pos) tube={insert_object=function(pos,node,stack,direction)
local inv=meta:get_inventory() local meta=minetest.env:get_meta(pos)
return inv:add_item("src",stack) local inv=meta:get_inventory()
end, return inv:add_item("src",stack)
can_insert=function(pos,node,stack,direction) end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos) local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory() local inv=meta:get_inventory()
return inv:room_for_item("src",stack) return inv:room_for_item("src",stack)
end, end,
}, },
legacy_facedir_simple = true, legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
technic_power_machine=1, on_construct = function(pos)
internal_EU_buffer=0; local meta = minetest.env:get_meta(pos)
interal_EU_buffer_size=2000; meta:set_string("infotext", "MV Electric furnace")
on_construct = function(pos) meta:set_float("technic_mv_power_machine", 1)
local meta = minetest.env:get_meta(pos) meta:set_int("tube_time", 0)
meta:set_float("technic_mv_power_machine", 1) meta:set_string("formspec", mv_electric_furnace_formspec)
meta:set_string("formspec", mv_electric_furnace_formspec) local inv = meta:get_inventory()
meta:set_string("infotext", "Electric furnace") inv:set_size("src", 1)
local inv = meta:get_inventory() inv:set_size("dst", 4)
inv:set_size("src", 1) inv:set_size("upgrade1", 1)
inv:set_size("dst", 4) inv:set_size("upgrade2", 1)
inv:set_size("upgrade1", 1) end,
inv:set_size("upgrade2", 1) can_dig = function(pos,player)
local EU_used = 0 local meta = minetest.env:get_meta(pos);
local furnace_is_cookin = 0 local inv = meta:get_inventory()
local cooked = nil if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
meta:set_float("internal_EU_buffer",0) minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
meta:set_float("internal_EU_buffer_size",2000) return false
meta:set_float("tube_time", 0) else
end, return true
can_dig = function(pos,player) end
local meta = minetest.env:get_meta(pos); end,
local inv = meta:get_inventory() })
if not inv:is_empty("dst") then
return false
elseif not inv:is_empty("src") then
return false
elseif not inv:is_empty("upgrade1") then
return false
elseif not inv:is_empty("upgrade2") then
return false
end
return true
end,
})
minetest.register_node("technic:mv_electric_furnace_active", { minetest.register_node(
description = "MV Electric Furnace", "technic:mv_electric_furnace_active",
tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png", {description = "MV Electric Furnace",
"technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front_active.png"}, tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png",
paramtype2 = "facedir", "technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front_active.png"},
light_source = 8, paramtype2 = "facedir",
drop = "technic:mv_electric_furnace", light_source = 8,
groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1}, drop = "technic:mv_electric_furnace",
tube={insert_object=function(pos,node,stack,direction) groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1},
local meta=minetest.env:get_meta(pos) tube={insert_object=function(pos,node,stack,direction)
local inv=meta:get_inventory() local meta=minetest.env:get_meta(pos)
return inv:add_item("src",stack) local inv=meta:get_inventory()
end, return inv:add_item("src",stack)
can_insert=function(pos,node,stack,direction) end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos) local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory() local inv=meta:get_inventory()
return inv:room_for_item("src",stack) return inv:room_for_item("src",stack)
end, end,
}, },
legacy_facedir_simple = true, legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(), sounds = default.node_sound_stone_defaults(),
internal_EU_buffer=0; can_dig = function(pos,player)
interal_EU_buffer_size=2000; local meta = minetest.env:get_meta(pos);
technic_power_machine=1, local inv = meta:get_inventory()
on_construct = function(pos) if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") then
local meta = minetest.env:get_meta(pos) minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
meta:set_float("technic_mv_power_machine", 1) return false
meta:set_string("formspec", mv_electric_furnace_formspec) else
meta:set_string("infotext", "Electric furnace"); return true
local inv = meta:get_inventory() end
inv:set_size("src", 1) end,
inv:set_size("dst", 4) -- These three makes sure upgrades are not moved in or out while the furnace is active.
inv:set_size("upgrade1", 1) allow_metadata_inventory_put = function(pos, listname, index, stack, player)
inv:set_size("upgrade2", 1) if listname == "src" or listname == "dst" then
local EU_used = 0 return 99
local furnace_is_cookin = 0 else
local cooked = nil return 0 -- Disallow the move
end, end
can_dig = function(pos,player) end,
local meta = minetest.env:get_meta(pos); allow_metadata_inventory_take = function(pos, listname, index, stack, player)
local inv = meta:get_inventory() if listname == "src" or listname == "dst" then
if not inv:is_empty("dst") then return 99
return false else
elseif not inv:is_empty("src") then return 0 -- Disallow the move
return false end
elseif not inv:is_empty("upgrade1") then end,
return false allow_metadata_inventory_move = function(pos, from_list, to_list, to_list, to_index, count, player)
elseif not inv:is_empty("upgrade2") then return 0
return false end,
end })
return true
end,
})
minetest.register_abm({ local send_cooked_items = function(pos,x_velocity,z_velocity)
nodenames = {"technic:mv_electric_furnace","technic:mv_electric_furnace_active"}, -- Send items on their way in the pipe system.
interval = 1, local meta=minetest.env:get_meta(pos)
chance = 1, local inv = meta:get_inventory()
local i=0
action = function(pos, node, active_object_count, active_object_count_wider) for _,stack in ipairs(inv:get_list("dst")) do
i=i+1
local pos1={} if stack then
pos1.x=pos.x local item0=stack:to_table()
pos1.y=pos.y if item0 then
pos1.z=pos.z item0["count"]="1"
local x_velocity=0 local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},item0)
local z_velocity=0 item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z}
item1:setvelocity({x=x_velocity, y=0, z=z_velocity})
-- output is on the left side of the furnace item1:setacceleration({x=0, y=0, z=0})
if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end stack:take_item(1);
if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end inv:set_stack("dst", i, stack)
if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end return
if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end
local output_tube_connected = false
local meta=minetest.env:get_meta(pos1)
if meta:get_int("tubelike")==1 then output_tube_connected=true end
meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
local upg_item1
local upg_item1_name=""
local upg_item2
local upg_item2_name=""
local srcstack = inv:get_stack("upgrade1", 1)
if srcstack then upg_item1=srcstack:to_table() end
srcstack = inv:get_stack("upgrade2", 1)
if srcstack then upg_item2=srcstack:to_table() end
if upg_item1 then upg_item1_name=upg_item1.name end
if upg_item2 then upg_item2_name=upg_item2.name end
local speed=0
if upg_item1_name=="technic:control_logic_unit" then speed=speed+1 end
if upg_item2_name=="technic:control_logic_unit" then speed=speed+1 end
tube_time=meta:get_float("tube_time")
tube_time=tube_time+speed
if tube_time>3 then
tube_time=0
if output_tube_connected then send_cooked_items(pos,x_velocity,z_velocity) end
end
meta:set_float("tube_time", tube_time)
local extra_buffer_size = 0
if upg_item1_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end
if upg_item2_name=="technic:battery" then extra_buffer_size =extra_buffer_size + 10000 end
local internal_EU_buffer_size=2000+extra_buffer_size
meta:set_float("internal_EU_buffer_size",internal_EU_buffer_size)
internal_EU_buffer=meta:get_float("internal_EU_buffer")
if internal_EU_buffer > internal_EU_buffer_size then internal_EU_buffer = internal_EU_buffer_size end
local load = math.floor(internal_EU_buffer/(internal_EU_buffer_size) * 100)
meta:set_string("formspec",
"invsize[8,10;]"..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,6;8,4;]"..
"label[0,0;MV Electric Furnace]"..
"label[1,2.8;Power level]"..
"list[current_name;upgrade1;1,4;1,1;]"..
"list[current_name;upgrade2;2,4;1,1;]"..
"label[1,5;Upgrade Slots]")
local furnace_is_cookin = meta:get_float("furnace_is_cookin")
local srclist = inv:get_list("src")
local cooked=nil
if srclist then
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
end
if (furnace_is_cookin == 1) then
if internal_EU_buffer>=150 then
internal_EU_buffer=internal_EU_buffer-150;
meta:set_float("internal_EU_buffer",internal_EU_buffer)
meta:set_float("src_time", meta:get_float("src_time") + 3)
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
-- check if there's room for output in "dst" list
if inv:room_for_item("dst",cooked.item) then
-- Put result in "dst" list
inv:add_item("dst", cooked.item)
-- take stuff from "src" list
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
else
print("Furnace inventory full!")
end end
meta:set_string("src_time", 0) end
end end
end end
local smelt_item = function(pos)
local meta=minetest.env:get_meta(pos)
local inv = meta:get_inventory()
meta:set_int("src_time", meta:get_int("src_time") + 3) -- Cooking time 3x faster
local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")})
if result and result.item and meta:get_int("src_time") >= result.time then
meta:set_int("src_time", 0)
-- check if there's room for output in "dst" list
if inv:room_for_item("dst",result) then
-- take stuff from "src" list
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
-- Put result in "dst" list
inv:add_item("dst", result.item)
return 1
else
return 0 -- done
end
end
return 0 -- done
end
minetest.register_abm(
{nodenames = {"technic:mv_electric_furnace","technic:mv_electric_furnace_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local eu_input = meta:get_int("MV_EU_input")
local state = meta:get_int("state")
local next_state = state
-- Machine information
local machine_name = "MV Electric Furnace"
local machine_node = "technic:mv_electric_furnace"
local machine_state_demand = { 50, 2000, 1500, 1000 }
-- Setup meta data if it does not exist. state is used as an indicator of this
if state == 0 then
meta:set_int("state", 1)
meta:set_int("MV_EU_demand", machine_state_demand[1])
meta:set_int("MV_EU_input", 0)
return
end end
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "MV")
-- Execute always logic
-- CODE HERE --
if srclist then -- State machine
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist}) if eu_input == 0 then
if cooked.time>0 then -- Unpowered - go idle
hacky_swap_node(pos,"technic:mv_electric_furnace_active") hacky_swap_node(pos, machine_node)
meta:set_string("infotext","Furnace active") meta:set_string("infotext", machine_name.." Unpowered")
meta:set_string("furnace_is_cookin",1) next_state = 1
meta:set_string("src_time", 0) elseif eu_input == machine_state_demand[state] then
return -- Powered - do the state specific actions
end
-- Execute always if powered logic
local meta=minetest.env:get_meta(pos)
-- Get the names of the upgrades
local meta=minetest.env:get_meta(pos)
local inv = meta:get_inventory()
local upg_item1
local upg_item1_name=""
local upg_item2
local upg_item2_name=""
local srcstack = inv:get_stack("upgrade1", 1)
if srcstack then upg_item1=srcstack:to_table() end
srcstack = inv:get_stack("upgrade2", 1)
if srcstack then upg_item2=srcstack:to_table() end
if upg_item1 then upg_item1_name=upg_item1.name end
if upg_item2 then upg_item2_name=upg_item2.name end
-- Save some power by installing battery upgrades. Fully upgraded makes this
-- furnace use the same amount of power as the LV version
local EU_saving_upgrade = 0
if upg_item1_name=="technic:battery" then EU_saving_upgrade = EU_saving_upgrade + 1 end
if upg_item2_name=="technic:battery" then EU_saving_upgrade = EU_saving_upgrade + 1 end
-- Tube loading speed can be upgraded using control logic units
local tube_speed_upgrade = 0
if upg_item1_name=="technic:control_logic_unit" then tube_speed_upgrade = tube_speed_upgrade + 1 end
if upg_item2_name=="technic:control_logic_unit" then tube_speed_upgrade = tube_speed_upgrade + 1 end
-- Handle pipeworks (consumes tube_speed_upgrade)
local pos1={x=pos.x, y=pos.y, z=pos.z}
local x_velocity=0
local z_velocity=0
-- Output is on the left side of the furnace
if node.param2==3 then pos1.z=pos1.z-1 z_velocity =-1 end
if node.param2==2 then pos1.x=pos1.x-1 x_velocity =-1 end
if node.param2==1 then pos1.z=pos1.z+1 z_velocity = 1 end
if node.param2==0 then pos1.x=pos1.x+1 x_velocity = 1 end
local output_tube_connected = false
local meta1 = minetest.env:get_meta(pos1)
if meta1:get_int("tubelike") == 1 then
output_tube_connected=true
end
tube_time = meta:get_int("tube_time")
tube_time = tube_time + tube_speed_upgrade
if tube_time > 3 then
tube_time = 0
if output_tube_connected then
send_cooked_items(pos,x_velocity,z_velocity)
end
end
meta:set_int("tube_time", tube_time)
-- The machine shuts down if we have nothing to smelt and no tube is connected
-- or if we have nothing to send with a tube connected.
if (not output_tube_connected and inv:is_empty("src"))
or ( output_tube_connected and inv:is_empty("dst")) then
next_state = 1
end end
----------------------
hacky_swap_node(pos,"technic:mv_electric_furnace") if state == 1 then
meta:set_string("infotext","Furnace inactive") hacky_swap_node(pos, machine_node)
meta:set_string("furnace_is_cookin",0) meta:set_string("infotext", machine_name.." Idle")
meta:set_string("src_time", 0)
end, local meta=minetest.env:get_meta(pos)
}) local inv = meta:get_inventory()
if not inv:is_empty("src") then
local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")})
if result then
meta:set_string("infotext", machine_name.." Active")
meta:set_int("src_time", 0)
next_state = 2+EU_saving_upgrade -- Next state is decided by the battery upgrade (state 2= 0 batteries, state 3 = 1 battery, 4 = 2 batteries)
end
else
meta:set_string("infotext", "Electric Furnace Idle")
end
function send_cooked_items (pos,x_velocity,z_velocity) elseif state == 2 or state == 3 or state == 4 then
local meta=minetest.env:get_meta(pos) hacky_swap_node(pos, machine_node.."_active")
local inv = meta:get_inventory() meta:set_string("infotext", machine_name.." Active")
local i=0 result = smelt_item(pos, data)
for _,stack in ipairs(inv:get_list("dst")) do if result == 0 then
i=i+1 next_state = 1
if stack then end
local item0=stack:to_table()
if item0 then
item0["count"]="1"
local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},item0)
item1:get_luaentity().start_pos = {x=pos.x,y=pos.y,z=pos.z}
item1:setvelocity({x=x_velocity, y=0, z=z_velocity})
item1:setacceleration({x=0, y=0, z=0})
stack:take_item(1);
inv:set_stack("dst", i, stack)
return
end
end
end end
end end
-- Change state?
if next_state ~= state then
meta:set_int("MV_EU_demand", machine_state_demand[next_state])
meta:set_int("state", next_state)
end
end,
})
register_MV_machine ("technic:mv_electric_furnace","RE") technic.register_MV_machine ("technic:mv_electric_furnace","RE")
register_MV_machine ("technic:mv_electric_furnace_active","RE") technic.register_MV_machine ("technic:mv_electric_furnace_active","RE")

View File

@ -1,7 +1,7 @@
-- original code comes from walkin_light mod by Echo http://minetest.net/forum/viewtopic.php?id=2621 -- original code comes from walkin_light mod by Echo http://minetest.net/forum/viewtopic.php?id=2621
flashlight_max_charge=30000 local flashlight_max_charge=30000
register_power_tool ("technic:flashlight",flashlight_max_charge) technic.register_LV_power_tool ("technic:flashlight",flashlight_max_charge)
minetest.register_tool("technic:flashlight", { minetest.register_tool("technic:flashlight", {
description = "Flashlight", description = "Flashlight",

View File

@ -66,7 +66,7 @@ local function remove_forcefield(p, range)
end end
end end
forcefield_receive_fields = function(pos, formname, fields, sender) local forcefield_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
local range = meta:get_int("range") local range = meta:get_int("range")
if fields.add then range = range + 1 end if fields.add then range = range + 1 end
@ -88,7 +88,7 @@ forcefield_receive_fields = function(pos, formname, fields, sender)
end end
end end
function get_forcefield_formspec(range, load) local get_forcefield_formspec = function(range, load)
if not load then load = 0 end if not load then load = 0 end
return "invsize[8,9;]".. return "invsize[8,9;]"..
"label[0,0;Forcefield emitter]".. "label[0,0;Forcefield emitter]"..
@ -103,7 +103,7 @@ function get_forcefield_formspec(range, load)
"list[current_player;main;0,5;8,4;]" "list[current_player;main;0,5;8,4;]"
end end
local function forcefield_check(pos) local forcefield_check = function(pos)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
local internal_EU_buffer=meta:get_float("internal_EU_buffer") local internal_EU_buffer=meta:get_float("internal_EU_buffer")
@ -145,7 +145,6 @@ minetest.register_node("technic:forcefield_emitter_off", {
tiles = {"technic_forcefield_emitter_off.png"}, tiles = {"technic_forcefield_emitter_off.png"},
is_ground_content = true, is_ground_content = true,
groups = {cracky = 1}, groups = {cracky = 1},
technic_power_machine=1,
on_timer = forcefield_check, on_timer = forcefield_check,
on_receive_fields = forcefield_receive_fields, on_receive_fields = forcefield_receive_fields,
on_construct = function(pos) on_construct = function(pos)
@ -206,9 +205,5 @@ minetest.register_node("technic:forcefield", {
}, },
}) })
register_MV_machine ("technic:forcefield_emitter_on","RE") technic.register_MV_machine("technic:forcefield_emitter_on","RE")
register_MV_machine ("technic:forcefield_emitter_off","RE") technic.register_MV_machine("technic:forcefield_emitter_off","RE")

View File

@ -1,3 +1,7 @@
-- Th coal driven EU generator.
-- A simple device to get started on the electric machines.
-- Inefficient and expensive in coal (200EU 16 ticks)
-- Also only allows for LV machinery to run.
minetest.register_alias("generator", "technic:generator") minetest.register_alias("generator", "technic:generator")
minetest.register_alias("generator", "technic:generator_active") minetest.register_alias("generator", "technic:generator_active")
@ -15,7 +19,7 @@ minetest.register_craftitem("technic:generator", {
stack_max = 99, stack_max = 99,
}) })
generator_formspec = local generator_formspec =
"invsize[8,9;]".. "invsize[8,9;]"..
"image[0,0;5,5;technic_generator_menu.png]".. "image[0,0;5,5;technic_generator_menu.png]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "image[1,1;1,2;technic_power_meter_bg.png]"..
@ -26,124 +30,118 @@ generator_formspec =
"list[current_player;main;0,5;8,4;]" "list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:generator", { minetest.register_node(
description = "Coal Driven Generator", "technic: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"}, description = "Coal Driven Generator",
paramtype2 = "facedir", tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, "technic_generator_side.png", "technic_generator_side.png", "technic_generator_front.png"},
legacy_facedir_simple = true, paramtype2 = "facedir",
sounds = default.node_sound_wood_defaults(), groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
technic_power_machine=1, legacy_facedir_simple = true,
internal_EU_buffer=0; sounds = default.node_sound_wood_defaults(),
internal_EU_buffer_size=5000; on_construct = function(pos)
burn_time=0; local meta = minetest.env:get_meta(pos)
on_construct = function(pos) meta:set_string("infotext", "Coal Electric Generator")
local meta = minetest.env:get_meta(pos) meta:set_float("technic_power_machine", 1)
meta:set_string("infotext", "Generator") meta:set_int("LV_EU_supply", 0)
meta:set_float("technic_power_machine", 1) meta:set_int("LV_EU_from_fuel", 1) -- Signal to the switching station that this device burns some sort of fuel and needs special handling
meta:set_float("internal_EU_buffer", 0) meta:set_int("burn_time", 0)
meta:set_float("internal_EU_buffer_size", 5000) meta:set_string("formspec", generator_formspec)
meta:set_string("formspec", generator_formspec) local inv = meta:get_inventory()
meta:set_float("burn_time", 0) inv:set_size("src", 1)
local inv = meta:get_inventory()
inv:set_size("src", 1)
end, end,
can_dig = function(pos,player) can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos); local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory() local inv = meta:get_inventory()
if not inv:is_empty("src") then if not inv:is_empty("src") then
return false minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
end return false
return true else
return true
end
end, end,
})
}) minetest.register_node(
"technic:generator_active",
minetest.register_node("technic:generator_active", { {
description = "Coal Driven Generator", description = "Coal Driven Generator",
tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png", 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"}, "technic_generator_side.png", "technic_generator_side.png", "technic_generator_front_active.png"},
paramtype2 = "facedir", paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
legacy_facedir_simple = true, legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
drop="technic:generator", drop="technic:generator",
technic_power_machine=1, can_dig = function(pos,player)
internal_EU_buffer=0; local meta = minetest.env:get_meta(pos);
internal_EU_buffer_size=0; local inv = meta:get_inventory()
burn_time=0; if not inv:is_empty("src") then
can_dig = function(pos,player) minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
local meta = minetest.env:get_meta(pos); return false
local inv = meta:get_inventory() else
if not inv:is_empty("src") then return true
return false end
end
return true
end, end,
})
}) minetest.register_abm(
minetest.register_abm({ {
nodenames = {"technic:generator","technic:generator_active"}, nodenames = {"technic:generator","technic:generator_active"},
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.env:get_meta(pos)
local burn_time= meta:get_int("burn_time")
local meta = minetest.env:get_meta(pos) -- If more to burn and the energy produced was used: produce some more
local burn_time= meta:get_float("burn_time") if burn_time>0 then
local charge= meta:get_float("internal_EU_buffer") if meta:get_int("LV_EU_supply") == 0 then
local max_charge= meta:get_float("internal_EU_buffer_size") -- We did not use the power
local burn_charge=200 meta:set_int("LV_EU_supply", 200) -- Give 200EUs
else
burn_time = burn_time - 1
meta:set_int("burn_time",burn_time)
end
end
if burn_time>0 then -- Burn another piece of coal
if charge+burn_charge>max_charge then if burn_time==0 then
burn_charge=max_charge-charge local inv = meta:get_inventory()
end if inv:is_empty("src") == false then
if burn_charge>0 then local srcstack = inv:get_stack("src", 1)
burn_time=burn_time-1 src_item=srcstack:to_table()
meta:set_float("burn_time",burn_time) if src_item["name"] == "default:coal_lump" then
charge=charge+burn_charge srcstack:take_item()
meta:set_float("internal_EU_buffer",charge) inv:set_stack("src", 1, srcstack)
end burn_time=16
meta:set_int("burn_time",burn_time)
hacky_swap_node (pos,"technic:generator_active")
meta:set_int("LV_EU_supply", 200) -- Give 200EUs
end
end
end
end local load = 8 -- math.floor((charge/max_charge)*100)
if burn_time==0 then local percent = math.floor((burn_time/16)*100)
local inv = meta:get_inventory() meta:set_string("formspec",
if inv:is_empty("src")==false then "invsize[8,9;]"..
local srcstack = inv:get_stack("src", 1) "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
src_item=srcstack:to_table() (load)..":technic_power_meter_fg.png]"..
if src_item["name"]== "default:coal_lump" then "label[0,0;Generator]"..
srcstack:take_item() "label[1,3;Power level]"..
inv:set_stack("src", 1, srcstack) "list[current_name;src;3,1;1,1;]"..
burn_time=16 "image[4,1;1,1;default_furnace_fire_bg.png^[lowpart:"..
meta:set_float("burn_time",burn_time) (percent)..":default_furnace_fire_fg.png]"..
hacky_swap_node (pos,"technic:generator_active") "list[current_player;main;0,5;8,4;]"
end )
end
end
local load = math.floor((charge/max_charge)*100) if burn_time==0 then
local percent = math.floor((burn_time/16)*100) hacky_swap_node (pos,"technic:generator")
meta:set_string("formspec", end
"invsize[8,9;]".. end
"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 technic.register_LV_machine ("technic:generator","PR")
hacky_swap_node (pos,"technic:generator") technic.register_LV_machine ("technic:generator_active","PR")
end
end
})
register_LV_machine ("technic:generator","PR")
register_LV_machine ("technic:generator_active","PR")

View File

@ -1,3 +1,7 @@
-- A geothermal EU generator
-- Using hot lava and water this device can create energy from steam
-- The machine is only producing LV EUs and can thus not drive more advanced equipment
-- The output is a little more than the coal burning generator (max 300EUs)
minetest.register_alias("geothermal", "technic:geothermal") minetest.register_alias("geothermal", "technic:geothermal")
minetest.register_craft({ minetest.register_craft({
@ -14,7 +18,7 @@ minetest.register_craftitem("technic:geothermal", {
stack_max = 99, stack_max = 99,
}) })
geothermal_formspec = local geothermal_formspec =
"invsize[8,4;]".. "invsize[8,4;]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "image[1,1;1,2;technic_power_meter_bg.png]"..
"label[0,0;Geothermal Generator]".. "label[0,0;Geothermal Generator]"..
@ -22,117 +26,131 @@ geothermal_formspec =
"list[current_player;main;0,5;8,4;]" "list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:geothermal", { minetest.register_node(
description = "Geothermal Generator", "technic:geothermal",
tiles = {"technic_geothermal_top.png", "technic_machine_bottom.png", "technic_geothermal_side.png", {
"technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"}, description = "Geothermal Generator",
paramtype2 = "facedir", tiles = {"technic_geothermal_top.png", "technic_machine_bottom.png", "technic_geothermal_side.png",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, "technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"},
legacy_facedir_simple = true, paramtype2 = "facedir",
sounds = default.node_sound_wood_defaults(), groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
technic_power_machine=1, legacy_facedir_simple = true,
internal_EU_buffer=0; sounds = default.node_sound_wood_defaults(),
internal_EU_buffer_size=5000; on_construct = function(pos)
burn_time=0; local meta = minetest.env:get_meta(pos)
on_construct = function(pos) meta:set_string("infotext", "Geothermal Generator")
local meta = minetest.env:get_meta(pos) meta:set_float("technic_power_machine", 1)
meta:set_string("infotext", "Geothermal Generator") meta:set_int("LV_EU_supply", 0)
meta:set_float("technic_power_machine", 1) meta:set_string("formspec", geothermal_formspec)
meta:set_float("internal_EU_buffer", 0) end,
meta:set_float("internal_EU_buffer_size", 2000) })
meta:set_string("formspec", geothermal_formspec)
end,
}) minetest.register_node(
"technic:geothermal_active",
{
description = "Geothermal Generator",
tiles = {"technic_geothermal_top_active.png", "technic_machine_bottom.png", "technic_geothermal_side.png",
"technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.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:geothermal",
})
minetest.register_node("technic:geothermal_active", { local check_node_around = function(pos)
description = "Geothermal Generator", local node=minetest.env:get_node(pos)
tiles = {"technic_geothermal_top_active.png", "technic_machine_bottom.png", "technic_geothermal_side.png", if node.name=="default:water_source" or node.name=="default:water_flowing" then return 1 end
"technic_geothermal_side.png", "technic_geothermal_side.png", "technic_geothermal_side.png"}, if node.name=="default:lava_source" or node.name=="default:lava_flowing" then return 2 end
paramtype2 = "facedir", return 0
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1}, end
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
drop="technic:geothermal",
technic_power_machine=1,
internal_EU_buffer=0;
internal_EU_buffer_size=0;
})
minetest.register_abm({ minetest.register_abm(
nodenames = {"technic:geothermal","technic:geothermal_active"}, {
interval = 1, nodenames = {"technic:geothermal","technic:geothermal_active"},
chance = 1, interval = 1,
action = function(pos, node, active_object_count, active_object_count_wider) chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local water_nodes = 0
local lava_nodes = 0
local production_level = 0
local eu_supply = 0
local meta = minetest.env:get_meta(pos) -- Correct positioning is water on one side and lava on the other.
local charge= meta:get_float("internal_EU_buffer") -- The two cannot be adjacent because the lava the turns into obsidian or rock.
local max_charge= meta:get_float("internal_EU_buffer_size") -- To get to 100% production stack the water and lava one extra block down as well:
local water_nodes = 0 -- WGL (W=Water, L=Lava, G=the generator, |=an LV cable)
local lava_nodes = 0 -- W|L
local production_level=0 pos.x=pos.x+1
local load_step=0 local check=check_node_around(pos)
if check==1 then water_nodes=water_nodes+1 end
if check==2 then lava_nodes=lava_nodes+1 end
pos.y=pos.y-1
local check=check_node_around(pos)
if check==1 then water_nodes=water_nodes+1 end
if check==2 then lava_nodes=lava_nodes+1 end
pos.x=pos.x+1 pos.x=pos.x-2
local check=check_node_around (pos) check=check_node_around(pos)
if check==1 then water_nodes=water_nodes+1 end if check==1 then water_nodes=water_nodes+1 end
if check==2 then lava_nodes=lava_nodes+1 end if check==2 then lava_nodes=lava_nodes+1 end
pos.x=pos.x-2 pos.y=pos.y+1
check=check_node_around (pos) check=check_node_around(pos)
if check==1 then water_nodes=water_nodes+1 end if check==1 then water_nodes=water_nodes+1 end
if check==2 then lava_nodes=lava_nodes+1 end if check==2 then lava_nodes=lava_nodes+1 end
pos.x=pos.x+1
pos.z=pos.z+1
check=check_node_around (pos)
if check==1 then water_nodes=water_nodes+1 end
if check==2 then lava_nodes=lava_nodes+1 end
pos.z=pos.z-2
check=check_node_around (pos)
if check==1 then water_nodes=water_nodes+1 end
if check==2 then lava_nodes=lava_nodes+1 end
pos.z=pos.z+1
if water_nodes==1 and lava_nodes==1 then production_level=50 load_step=30 end pos.x=pos.x+1
if water_nodes==2 and lava_nodes==1 then production_level=75 load_step=45 end pos.z=pos.z+1
if water_nodes==1 and lava_nodes==2 then production_level=75 load_step=45 end check=check_node_around(pos)
if water_nodes==2 and lava_nodes==2 then production_level=100 load_step=60 end if check==1 then water_nodes=water_nodes+1 end
if water_nodes==3 and lava_nodes==1 then production_level=25 load_step=15 end if check==2 then lava_nodes=lava_nodes+1 end
if water_nodes==1 and lava_nodes==3 then production_level=25 load_step=15 end pos.y=pos.y-1
check=check_node_around(pos)
if check==1 then water_nodes=water_nodes+1 end
if check==2 then lava_nodes=lava_nodes+1 end
if production_level>0 then pos.z=pos.z-2
if charge+load_step>max_charge then check=check_node_around(pos)
load_step=max_charge-charge if check==1 then water_nodes=water_nodes+1 end
end if check==2 then lava_nodes=lava_nodes+1 end
if load_step>0 then pos.y=pos.y+1
charge=charge+load_step check=check_node_around(pos)
meta:set_float("internal_EU_buffer",charge) if check==1 then water_nodes=water_nodes+1 end
end if check==2 then lava_nodes=lava_nodes+1 end
end
local load = math.floor((charge/max_charge)*100) -- Back to (0,0,0)
meta:set_string("formspec", pos.z=pos.z+1
"invsize[8,4;]"..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"..
"label[0,0;Geothermal Generator]"..
"label[1,3;Power level]"..
"label[4,0;Production at "..tostring(production_level).."%]"
)
if production_level>0 and minetest.env:get_node(pos).name=="technic:geothermal" then if water_nodes==1 and lava_nodes==1 then production_level = 25; eu_supply = 50 end
hacky_swap_node (pos,"technic:geothermal_active") if water_nodes==2 and lava_nodes==1 then production_level = 50; eu_supply = 100 end
return if water_nodes==1 and lava_nodes==2 then production_level = 75; eu_supply = 200 end
end if water_nodes==2 and lava_nodes==2 then production_level = 100; eu_supply = 300 end
if production_level==0 then hacky_swap_node (pos,"technic:geothermal") end
end
})
function check_node_around (pos) if production_level>0 then
local node=minetest.env:get_node(pos) meta:set_int("LV_EU_supply", eu_supply)
if node.name=="default:water_source" or node.name=="default:water_flowing" then return 1 end end
if node.name=="default:lava_source" or node.name=="default:lava_flowing" then return 2 end
return 0
end
register_LV_machine ("technic:geothermal","PR") local load = 1 -- math.floor((charge/max_charge)*100)
register_LV_machine ("technic:geothermal_active","PR") meta:set_string("formspec",
"invsize[8,4;]"..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"..
"label[0,0;Geothermal Generator]"..
"label[1,3;Power level]"..
"label[4,0;Production at "..tostring(production_level).."%]"
)
if production_level>0 and minetest.env:get_node(pos).name=="technic:geothermal" then
hacky_swap_node (pos,"technic:geothermal_active")
return
end
if production_level==0 then
hacky_swap_node (pos,"technic:geothermal")
meta:set_int("LV_EU_supply", 0)
end
end
})
technic.register_LV_machine ("technic:geothermal","PR")
technic.register_LV_machine ("technic:geothermal_active","PR")

View File

@ -1,352 +1,360 @@
grinder_recipes ={} technic.grinder_recipes ={}
registered_grinder_recipes_count=1 technic.register_grinder_recipe = function(src, dst)
technic.grinder_recipes[src] = dst
if unified_inventory then
unified_inventory.register_craft(
{
type = "grinding",
output = dst,
items = {src},
width = 0,
})
end
end
function register_grinder_recipe (string1,string2) -- Receive an ItemStack of result by an ItemStack input
grinder_recipes[registered_grinder_recipes_count]={} technic.get_grinder_recipe = function(itemstack)
grinder_recipes[registered_grinder_recipes_count].src_name=string1 local src_item = itemstack:to_table()
grinder_recipes[registered_grinder_recipes_count].dst_name=string2 if src_item == nil then
registered_grinder_recipes_count=registered_grinder_recipes_count+1 return nil
if unified_inventory then end
unified_inventory.register_craft({ local item_name = src_item["name"]
type = "grinding", if technic.grinder_recipes[item_name] then
output = string2, return ItemStack(technic.grinder_recipes[item_name])
items = {string1}, else
width = 0, return nil
}) end
end end
end
register_grinder_recipe("default:stone","default:sand")
register_grinder_recipe("default:cobble","default:gravel") technic.register_grinder_recipe("default:stone","default:sand")
register_grinder_recipe("default:gravel","default:dirt") technic.register_grinder_recipe("default:cobble","default:gravel")
register_grinder_recipe("default:desert_stone","default:desert_sand") technic.register_grinder_recipe("default:gravel","default:dirt")
register_grinder_recipe("default:iron_lump","technic:iron_dust 2") technic.register_grinder_recipe("default:desert_stone","default:desert_sand")
register_grinder_recipe("default:steel_ingot","technic:iron_dust 1") technic.register_grinder_recipe("default:iron_lump","technic:iron_dust 2")
register_grinder_recipe("default:coal_lump","technic:coal_dust 2") technic.register_grinder_recipe("default:steel_ingot","technic:iron_dust 1")
register_grinder_recipe("default:copper_lump","technic:copper_dust 2") technic.register_grinder_recipe("default:coal_lump","technic:coal_dust 2")
register_grinder_recipe("default:copper_ingot","technic:copper_dust 1") technic.register_grinder_recipe("default:copper_lump","technic:copper_dust 2")
register_grinder_recipe("default:gold_lump","technic:gold_dust 2") technic.register_grinder_recipe("default:copper_ingot","technic:copper_dust 1")
register_grinder_recipe("default:gold_ingot","technic:gold_dust 1") technic.register_grinder_recipe("default:gold_lump","technic:gold_dust 2")
--register_grinder_recipe("default:bronze_ingot","technic:bronze_dust 1") -- Dust does not exist yet technic.register_grinder_recipe("default:gold_ingot","technic:gold_dust 1")
--register_grinder_recipe("home_decor:brass_ingot","technic:brass_dust 1") -- needs check for the mod --technic.register_grinder_recipe("default:bronze_ingot","technic:bronze_dust 1") -- Dust does not exist yet
register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2") --technic.register_grinder_recipe("home_decor:brass_ingot","technic:brass_dust 1") -- needs check for the mod
register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 1") technic.register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2")
register_grinder_recipe("moreores:silver_lump","technic:silver_dust 2") technic.register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 1")
register_grinder_recipe("moreores:silver_ingot","technic:silver_dust 1") technic.register_grinder_recipe("moreores:silver_lump","technic:silver_dust 2")
register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2") technic.register_grinder_recipe("moreores:silver_ingot","technic:silver_dust 1")
register_grinder_recipe("moreores:mithril_ingot","technic:mithril_dust 1") technic.register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2")
register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2") technic.register_grinder_recipe("moreores:mithril_ingot","technic:mithril_dust 1")
register_grinder_recipe("technic:chromium_ingot","technic:chromium_dust 1") technic.register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2")
register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 1") technic.register_grinder_recipe("technic:chromium_ingot","technic:chromium_dust 1")
register_grinder_recipe("technic:brass_ingot","technic:brass_dust 1") technic.register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 1")
register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2") technic.register_grinder_recipe("technic:brass_ingot","technic:brass_dust 1")
register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 1") technic.register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2")
register_grinder_recipe("technic:coal_dust","dye:black 2") technic.register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 1")
register_grinder_recipe("default:cactus","dye:green 2") technic.register_grinder_recipe("technic:coal_dust","dye:black 2")
register_grinder_recipe("default:dry_shrub","dye:brown 2") technic.register_grinder_recipe("default:cactus","dye:green 2")
register_grinder_recipe("flowers:flower_geranium","dye:blue 2") technic.register_grinder_recipe("default:dry_shrub","dye:brown 2")
register_grinder_recipe("flowers:flower_dandelion_white","dye:white 2") technic.register_grinder_recipe("flowers:flower_geranium","dye:blue 2")
register_grinder_recipe("flowers:flower_dandelion_yellow","dye:yellow 2") technic.register_grinder_recipe("flowers:flower_dandelion_white","dye:white 2")
register_grinder_recipe("flowers:flower_tulip","dye:orange 2") technic.register_grinder_recipe("flowers:flower_dandelion_yellow","dye:yellow 2")
register_grinder_recipe("flowers:flower_rose","dye:red 2") technic.register_grinder_recipe("flowers:flower_tulip","dye:orange 2")
register_grinder_recipe("flowers:flower_viola","dye:violet 2") technic.register_grinder_recipe("flowers:flower_rose","dye:red 2")
technic.register_grinder_recipe("flowers:flower_viola","dye:violet 2")
minetest.register_craftitem( "technic:coal_dust", { minetest.register_craftitem( "technic:coal_dust", {
description = "Coal Dust", description = "Coal Dust",
inventory_image = "technic_coal_dust.png", inventory_image = "technic_coal_dust.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craftitem( "technic:iron_dust", { minetest.register_craftitem( "technic:iron_dust", {
description = "Iron Dust", description = "Iron Dust",
inventory_image = "technic_iron_dust.png", inventory_image = "technic_iron_dust.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craft({ minetest.register_craft({
type = "cooking", type = "cooking",
output = "default:steel_ingot", output = "default:steel_ingot",
recipe = "technic:iron_dust", recipe = "technic:iron_dust",
}) })
minetest.register_craftitem( "technic:copper_dust", { minetest.register_craftitem( "technic:copper_dust", {
description = "Copper Dust", description = "Copper Dust",
inventory_image = "technic_copper_dust.png", inventory_image = "technic_copper_dust.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craft({ minetest.register_craft({
type = "cooking", type = "cooking",
output = "moreores:copper_ingot", output = "moreores:copper_ingot",
recipe = "technic:copper_dust", recipe = "technic:copper_dust",
}) })
minetest.register_craftitem( "technic:tin_dust", { minetest.register_craftitem( "technic:tin_dust", {
description = "Tin Dust", description = "Tin Dust",
inventory_image = "technic_tin_dust.png", inventory_image = "technic_tin_dust.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craft({ minetest.register_craft({
type = "cooking", type = "cooking",
output = "moreores:tin_ingot", output = "moreores:tin_ingot",
recipe = "technic:tin_dust", recipe = "technic:tin_dust",
}) })
minetest.register_craftitem( "technic:silver_dust", { minetest.register_craftitem( "technic:silver_dust", {
description = "Silver Dust", description = "Silver Dust",
inventory_image = "technic_silver_dust.png", inventory_image = "technic_silver_dust.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craft({ minetest.register_craft({
type = "cooking", type = "cooking",
output = "moreores:silver_ingot", output = "moreores:silver_ingot",
recipe = "technic:silver_dust", recipe = "technic:silver_dust",
}) })
minetest.register_craftitem( "technic:gold_dust", { minetest.register_craftitem( "technic:gold_dust", {
description = "Gold Dust", description = "Gold Dust",
inventory_image = "technic_gold_dust.png", inventory_image = "technic_gold_dust.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craft({ minetest.register_craft({
type = "cooking", type = "cooking",
output = "moreores:gold_ingot", output = "moreores:gold_ingot",
recipe = "technic:gold_dust", recipe = "technic:gold_dust",
}) })
minetest.register_craftitem( "technic:mithril_dust", { minetest.register_craftitem( "technic:mithril_dust", {
description = "Mithril Dust", description = "Mithril Dust",
inventory_image = "technic_mithril_dust.png", inventory_image = "technic_mithril_dust.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craft({ minetest.register_craft({
type = "cooking", type = "cooking",
output = "moreores:mithril_ingot", output = "moreores:mithril_ingot",
recipe = "technic:mithril_dust", recipe = "technic:mithril_dust",
}) })
minetest.register_craftitem( "technic:chromium_dust", { minetest.register_craftitem( "technic:chromium_dust", {
description = "Chromium Dust", description = "Chromium Dust",
inventory_image = "technic_chromium_dust.png", inventory_image = "technic_chromium_dust.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craft({ minetest.register_craft({
type = "cooking", type = "cooking",
output = "technic:chromium_ingot", output = "technic:chromium_ingot",
recipe = "technic:chromium_dust", recipe = "technic:chromium_dust",
}) })
minetest.register_craftitem( "technic:bronze_dust", { minetest.register_craftitem( "technic:bronze_dust", {
description = "Bronze Dust", description = "Bronze Dust",
inventory_image = "technic_bronze_dust.png", inventory_image = "technic_bronze_dust.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craft({ minetest.register_craft({
type = "cooking", type = "cooking",
output = "moreores:bronze_ingot", output = "moreores:bronze_ingot",
recipe = "technic:bronze_dust", recipe = "technic:bronze_dust",
}) })
minetest.register_craftitem( "technic:brass_dust", { minetest.register_craftitem( "technic:brass_dust", {
description = "Brass Dust", description = "Brass Dust",
inventory_image = "technic_brass_dust.png", inventory_image = "technic_brass_dust.png",
on_place_on_ground = minetest.craftitem_place_item, on_place_on_ground = minetest.craftitem_place_item,
}) })
minetest.register_craft({ minetest.register_craft({
type = "cooking", type = "cooking",
output = "technic:brass_ingot", output = "technic:brass_ingot",
recipe = "technic:brass_dust", recipe = "technic:brass_dust",
}) })
minetest.register_craftitem( "technic:stainless_steel_dust", { minetest.register_craftitem( "technic:stainless_steel_dust", {
description = "Stainless Steel Dust", description = "Stainless Steel Dust",
inventory_image = "technic_stainless_steel_dust.png", inventory_image = "technic_stainless_steel_dust.png",
}) })
minetest.register_craft({ minetest.register_craft({
type = "cooking", type = "cooking",
output = "technic:stainless_steel_ingot", output = "technic:stainless_steel_ingot",
recipe = "technic:stainless_steel_dust", recipe = "technic:stainless_steel_dust",
}) })
minetest.register_craftitem( "technic:zinc_dust", { minetest.register_craftitem( "technic:zinc_dust", {
description = "Zinc Dust", description = "Zinc Dust",
inventory_image = "technic_zinc_dust.png", inventory_image = "technic_zinc_dust.png",
}) })
minetest.register_craft({ minetest.register_craft({
type = "cooking", type = "cooking",
output = "technic:zinc_ingot", output = "technic:zinc_ingot",
recipe = "technic:zinc_dust", recipe = "technic:zinc_dust",
}) })
minetest.register_alias("grinder", "technic:grinder") minetest.register_alias("grinder", "technic:grinder")
minetest.register_craft({ minetest.register_craft({
output = 'technic:grinder', output = 'technic:grinder',
recipe = { recipe = {
{'default:desert_stone', 'default:desert_stone', 'default:desert_stone'}, {'default:desert_stone', 'default:desert_stone', 'default:desert_stone'},
{'default:desert_stone', 'default:diamond', 'default:desert_stone'}, {'default:desert_stone', 'default:diamond', 'default:desert_stone'},
{'default:stone', 'moreores:copper_ingot', 'default:stone'}, {'default:stone', 'moreores:copper_ingot', 'default:stone'},
} }
}) })
minetest.register_craftitem("technic:grinder", { minetest.register_craftitem("technic:grinder", {
description = "Grinder", description = "Grinder",
stack_max = 99, stack_max = 99,
}) })
grinder_formspec = local grinder_formspec =
"invsize[8,9;]".. "invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "label[0,0;Grinder]"..
"label[0,0;Grinder]".. "list[current_name;src;3,1;1,1;]"..
"label[1,3;Power level]".. "list[current_name;dst;5,1;2,2;]"..
"list[current_name;src;3,1;1,1;]".. "list[current_player;main;0,5;8,4;]"
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node(
minetest.register_node("technic:grinder", { "technic:grinder",
description = "Grinder", {
tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png", description = "Grinder",
"technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front.png"}, tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png",
paramtype2 = "facedir", "technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front.png"},
groups = {cracky=2}, paramtype2 = "facedir",
legacy_facedir_simple = true, groups = {cracky=2},
sounds = default.node_sound_wood_defaults(), legacy_facedir_simple = true,
technic_power_machine=1, sounds = default.node_sound_wood_defaults(),
internal_EU_buffer=0; on_construct = function(pos)
internal_EU_buffer_size=5000; local meta = minetest.env:get_meta(pos)
grind_time=0; meta:set_string("infotext", "Grinder")
grinded = nil; meta:set_float("technic_power_machine", 1)
src_time = 0; meta:set_string("formspec", grinder_formspec)
on_construct = function(pos) local inv = meta:get_inventory()
local meta = minetest.env:get_meta(pos) inv:set_size("src", 1)
meta:set_string("infotext", "Grinder") inv:set_size("dst", 4)
meta:set_float("technic_power_machine", 1) end,
meta:set_float("internal_EU_buffer", 0) can_dig = function(pos,player)
meta:set_float("internal_EU_buffer_size", 5000) local meta = minetest.env:get_meta(pos);
meta:set_string("formspec", grinder_formspec) local inv = meta:get_inventory()
meta:set_float("grind_time", 0) if not inv:is_empty("src") or not inv:is_empty("dst") then
local inv = meta:get_inventory() minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
inv:set_size("src", 1) return false
inv:set_size("dst", 4) else
return true
end
end, end,
can_dig = function(pos,player) })
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory() minetest.register_node(
if not inv:is_empty("src") then "technic:grinder_active",
return false {
end description = "Grinder",
if not inv:is_empty("dst") then tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png",
return false "technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front_active.png"},
end paramtype2 = "facedir",
return true groups = {cracky=2,not_in_creative_inventory=1},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") or not inv:is_empty("dst") then
minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
return false
else
return true
end
end, end,
}) })
minetest.register_node("technic:grinder_active", { minetest.register_abm(
description = "Grinder", { nodenames = {"technic:grinder","technic:grinder_active"},
tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png", interval = 1,
"technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front_active.png"}, chance = 1,
paramtype2 = "facedir", action = function(pos, node, active_object_count, active_object_count_wider)
groups = {cracky=2,not_in_creative_inventory=1}, -- Run a machine through its states. Takes the same arguments as the ABM action
legacy_facedir_simple = true, -- and adds the machine's states and any extra data which is needed by the machine.
sounds = default.node_sound_wood_defaults(), -- A machine is characterized by running through a set number of states (usually 2:
can_dig = function(pos,player) -- Idle and active) in some order. A state decides when to move to the next one
local meta = minetest.env:get_meta(pos); -- and the machine only changes state if it is powered correctly.
local inv = meta:get_inventory() -- The machine will automatically shut down if disconnected from power in some fashion.
if not inv:is_empty("src") then local meta = minetest.env:get_meta(pos)
return false local eu_input = meta:get_int("LV_EU_input")
end local state = meta:get_int("state")
if not inv:is_empty("dst") then local next_state = state
return false
end
return true
end,
})
minetest.register_abm({ -- Machine information
nodenames = {"technic:grinder","technic:grinder_active"}, local machine_name = "Grinder"
interval = 1, local machine_node = "technic:grinder"
chance = 1, local machine_state_demand = { 50, 300 }
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos) -- Setup meta data if it does not exist. state is used as an indicator of this
local charge= meta:get_float("internal_EU_buffer") if state == 0 then
local max_charge= meta:get_float("internal_EU_buffer_size") meta:set_int("state", 1)
local grind_cost=200 meta:set_int("LV_EU_demand", machine_state_demand[1])
meta:set_int("LV_EU_input", 0)
return
end
local load = math.floor((charge/max_charge)*100) -- Power off automatically if no longer connected to a switching station
meta:set_string("formspec", technic.switching_station_timeout_count(pos, "LV")
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"..
"label[0,0;Grinder]"..
"label[1,3;Power level]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"
)
local inv = meta:get_inventory() -- State machine
local srclist = inv:get_list("src") if eu_input == 0 then
if inv:is_empty("src") then meta:set_float("grinder_on",0) end -- unpowered - go idle
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
next_state = 1
elseif eu_input == machine_state_demand[state] then
-- Powered - do the state specific actions
if (meta:get_float("grinder_on") == 1) then local inv = meta:get_inventory()
if charge>=grind_cost then local empty = inv:is_empty("src")
charge=charge-grind_cost;
meta:set_float("internal_EU_buffer",charge)
meta:set_float("src_time", meta:get_float("src_time") + 1)
if meta:get_float("src_time") >= meta:get_float("grind_time") then
-- check if there's room for output in "dst" list
grinded = get_grinded_item (inv:get_stack("src", 1))
if inv:room_for_item("dst",grinded) then
-- Put result in "dst" list
inv:add_item("dst", grinded)
-- take stuff from "src" list
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
if inv:is_empty("src") then meta:set_float("grinder_on",0) end
else
print("Grinder inventory full!")
end
meta:set_float("src_time", 0)
end
end
end
if (meta:get_float("grinder_on")==0) then
local grinded=nil
if not inv:is_empty("src") then
grinded = get_grinded_item (inv:get_stack("src", 1))
if grinded then
meta:set_float("grinder_on",1)
hacky_swap_node(pos,"technic:grinder_active")
meta:set_string("infotext", "Grinder Active")
grind_time=4
meta:set_float("grind_time",grind_time)
meta:set_float("src_time", 0)
return
end
else
hacky_swap_node(pos,"technic:grinder")
meta:set_string("infotext", "Grinder Inactive")
end
end
end
})
function get_grinded_item (items) if state == 1 then
new_item =nil hacky_swap_node(pos, machine_node)
src_item=items:to_table() meta:set_string("infotext", machine_name.." Idle")
item_name=src_item["name"]
local counter=registered_grinder_recipes_count-1 local result = technic.get_grinder_recipe(inv:get_stack("src", 1))
for i=1, counter,1 do if not empty and result and inv:room_for_item("dst",result) then
if grinder_recipes[i].src_name==item_name then return ItemStack(grinder_recipes[i].dst_name) end meta:set_int("src_time", 0)
end next_state = 2
return nil end
end
register_LV_machine ("technic:grinder","RE") elseif state == 2 then
register_LV_machine ("technic:grinder_active","RE") hacky_swap_node(pos, machine_node.."_active")
meta:set_string("infotext", machine_name.." Active")
if empty then
next_state = 1
else
meta:set_int("src_time", meta:get_int("src_time") + 1)
if meta:get_int("src_time") == 4 then -- 4 ticks per output
-- check if there's room for output in "dst" list
local result = technic.get_grinder_recipe(inv:get_stack("src", 1))
meta:set_int("src_time", 0)
if inv:room_for_item("dst",result) then
-- take stuff from "src" list
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
-- Put result in "dst" list
inv:add_item("dst", result)
else
-- all full: go idle
next_state = 1
end
end
end
end
end
-- Change state?
if next_state ~= state then
meta:set_int("LV_EU_demand", machine_state_demand[next_state])
meta:set_int("state", next_state)
end
end
})
technic.register_LV_machine ("technic:grinder","RE")
technic.register_LV_machine ("technic:grinder_active","RE")

View File

@ -1,8 +1,8 @@
register_grinder_recipe("gloopores:alatro_lump","technic:alatro_dust 2") technic.register_grinder_recipe("gloopores:alatro_lump","technic:alatro_dust 2")
register_grinder_recipe("gloopores:kalite_lump","technic:kalite_dust 2") technic.register_grinder_recipe("gloopores:kalite_lump","technic:kalite_dust 2")
register_grinder_recipe("gloopores:arol_lump","technic:arol_dust 2") technic.register_grinder_recipe("gloopores:arol_lump","technic:arol_dust 2")
register_grinder_recipe("gloopores:talinite_lump","technic:talinite_dust 2") technic.register_grinder_recipe("gloopores:talinite_lump","technic:talinite_dust 2")
register_grinder_recipe("gloopores:akalin_lump","technic:akalin_dust 2") technic.register_grinder_recipe("gloopores:akalin_lump","technic:akalin_dust 2")
   
minetest.register_craftitem("technic:alatro_dust", { minetest.register_craftitem("technic:alatro_dust", {
        description = "Alatro Dust",         description = "Alatro Dust",

View File

@ -4,7 +4,13 @@
technic = {} technic = {}
modpath=minetest.get_modpath("technic") technic.dprint = function(string)
if technic.DBG == 1 then
print(string)
end
end
local modpath=minetest.get_modpath("technic")
--Read technic config file --Read technic config file
dofile(modpath.."/config.lua") dofile(modpath.."/config.lua")
@ -14,19 +20,26 @@ dofile(modpath.."/helpers.lua")
--items --items
dofile(modpath.."/items.lua") dofile(modpath.."/items.lua")
-- Register functions
dofile(modpath.."/register_machine_and_tool.lua")
dofile(modpath.."/alloy_furnaces_commons.lua") -- Idea: Let the LV, MV, HV version of the furnace support different alloys
-- Switching station LV,MV,HV
dofile(modpath.."/switching_station.lua")
dofile(modpath.."/supply_converter.lua")
--LV machines --LV machines
dofile(modpath.."/wires.lua") dofile(modpath.."/wires.lua")
dofile(modpath.."/battery_box.lua") dofile(modpath.."/battery_box.lua")
dofile(modpath.."/alloy_furnaces_commons.lua")
dofile(modpath.."/alloy_furnace.lua") dofile(modpath.."/alloy_furnace.lua")
dofile(modpath.."/solar_panel.lua") dofile(modpath.."/solar_panel.lua")
dofile(modpath.."/solar_array_lv.lua") dofile(modpath.."/solar_array_lv.lua")
dofile(modpath.."/geothermal.lua") dofile(modpath.."/geothermal.lua")
dofile(modpath.."/water_mill.lua") dofile(modpath.."/water_mill.lua")
dofile(modpath.."/generator.lua")
dofile(modpath.."/electric_furnace.lua") dofile(modpath.."/electric_furnace.lua")
dofile(modpath.."/tool_workshop.lua") dofile(modpath.."/tool_workshop.lua")
dofile(modpath.."/music_player.lua") dofile(modpath.."/music_player.lua")
dofile(modpath.."/generator.lua")
dofile(modpath.."/grinder.lua") dofile(modpath.."/grinder.lua")
dofile(modpath.."/cnc.lua") dofile(modpath.."/cnc.lua")
dofile(modpath.."/cnc_api.lua") dofile(modpath.."/cnc_api.lua")
@ -36,16 +49,18 @@ dofile(modpath.."/cnc_nodes.lua")
dofile(modpath.."/wires_mv.lua") dofile(modpath.."/wires_mv.lua")
dofile(modpath.."/battery_box_mv.lua") dofile(modpath.."/battery_box_mv.lua")
dofile(modpath.."/solar_array_mv.lua") dofile(modpath.."/solar_array_mv.lua")
dofile(modpath.."/down_converter_mv.lua")
dofile(modpath.."/electric_furnace_mv.lua") dofile(modpath.."/electric_furnace_mv.lua")
dofile(modpath.."/alloy_furnace_mv.lua") dofile(modpath.."/alloy_furnace_mv.lua")
dofile(modpath.."/forcefield.lua") --dofile(modpath.."/forcefield.lua")
---- The power radiator supplies appliances with inductive coupled power:
--HV machines ---- lighting and associated textures is taken directly from VanessaE's homedecor and made electric.
dofile(modpath.."/power_radiator.lua")
dofile(modpath.."/lighting.lua")
--
----HV machines
dofile(modpath.."/wires_hv.lua") dofile(modpath.."/wires_hv.lua")
dofile(modpath.."/battery_box_hv.lua") dofile(modpath.."/battery_box_hv.lua")
dofile(modpath.."/solar_array_hv.lua") dofile(modpath.."/solar_array_hv.lua")
dofile(modpath.."/down_converter_hv.lua")
--Tools --Tools
if technic.config:getBool("enable_mining_drill") then dofile(modpath.."/mining_drill.lua") end if technic.config:getBool("enable_mining_drill") then dofile(modpath.."/mining_drill.lua") end
@ -55,8 +70,8 @@ dofile(modpath.."/cans.lua")
dofile(modpath.."/chainsaw.lua") dofile(modpath.."/chainsaw.lua")
dofile(modpath.."/tree_tap.lua") dofile(modpath.."/tree_tap.lua")
dofile(modpath.."/sonic_screwdriver.lua") dofile(modpath.."/sonic_screwdriver.lua")
--
-- mesecons and tubes related ---- mesecons and tubes related
dofile(modpath.."/injector.lua") dofile(modpath.."/injector.lua")
dofile(modpath.."/node_breaker.lua") dofile(modpath.."/node_breaker.lua")
dofile(modpath.."/deployer.lua") dofile(modpath.."/deployer.lua")
@ -64,24 +79,23 @@ dofile(modpath.."/constructor.lua")
dofile(modpath.."/frames.lua") dofile(modpath.."/frames.lua")
function has_locked_chest_privilege(meta, player) function has_locked_chest_privilege(meta, player)
if player:get_player_name() ~= meta:get_string("owner") then if player:get_player_name() ~= meta:get_string("owner") then
return false return false
end end
return true return true
end end
-- Swap nodes out. Return the node name.
function hacky_swap_node(pos,name) function hacky_swap_node(pos,name)
local node = minetest.env:get_node(pos) local node = minetest.env:get_node(pos)
local meta = minetest.env:get_meta(pos) if node.name ~= name then
local meta0 = meta:to_table() local meta = minetest.env:get_meta(pos)
if node.name == name then local meta0 = meta:to_table()
return nil node.name = name
end minetest.env:set_node(pos,node)
node.name = name meta = minetest.env:get_meta(pos)
local meta0 = meta:to_table() meta:from_table(meta0)
minetest.env:set_node(pos,node) end
meta = minetest.env:get_meta(pos) return node.name
meta:from_table(meta0)
return 1
end end

590
technic/lighting.lua Normal file
View File

@ -0,0 +1,590 @@
-- NOTE: The code is takes directly from VanessaE's homedecor mod.
-- I just made it the lights into indictive appliances for this mod.
-- This file supplies electric powered glowlights
-- Boilerplate to support localized strings if intllib mod is installed.
local S
if (minetest.get_modpath("intllib")) then
dofile(minetest.get_modpath("intllib").."/intllib.lua")
S = intllib.Getter(minetest.get_current_modname())
else
S = function ( s ) return s end
end
function technic_homedecor_node_is_owned(pos, placer)
local ownername = false
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
if HasOwner(pos, placer) then -- returns true if the node is owned
if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
if type(getLastOwner) == "function" then -- ...is an old version
ownername = getLastOwner(pos)
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
ownername = GetNodeOwnerName(pos)
else
ownername = S("someone")
end
end
end
elseif type(isprotect)=="function" then -- glomie's protection mod
if not isprotect(5, pos, placer) then
ownername = S("someone")
end
elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod
if not protector.can_dig(5, pos, placer) then
ownername = S("someone")
end
end
if ownername ~= false then
minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
return true
else
return false
end
end
local dirs1 = { 20, 23, 22, 21 }
local dirs2 = { 9, 18, 7, 12 }
local technic_homedecor_rotate_and_place = function(itemstack, placer, pointed_thing)
if not technic_homedecor_node_is_owned(pointed_thing.under, placer)
and not technic_homedecor_node_is_owned(pointed_thing.above, placer) then
local node = minetest.env:get_node(pointed_thing.under)
if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].on_rightclick then
local above = pointed_thing.above
local under = pointed_thing.under
local pitch = placer:get_look_pitch()
local pname = minetest.env:get_node(under).name
local node = minetest.env:get_node(above)
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
local wield_name = itemstack:get_name()
if not minetest.registered_nodes[pname]
or not minetest.registered_nodes[pname].on_rightclick then
local iswall = (above.x ~= under.x) or (above.z ~= under.z)
local isceiling = (above.x == under.x) and (above.z == under.z) and (pitch > 0)
local pos1 = above
if minetest.registered_nodes[pname]["buildable_to"] then
pos1 = under
iswall = false
end
if not minetest.registered_nodes[minetest.env:get_node(pos1).name]["buildable_to"] then return end
if iswall then
minetest.env:add_node(pos1, {name = wield_name, param2 = dirs2[fdir+1] }) -- place wall variant
elseif isceiling then
minetest.env:add_node(pos1, {name = wield_name, param2 = 20 }) -- place upside down variant
else
minetest.env:add_node(pos1, {name = wield_name, param2 = 0 }) -- place right side up
end
if not homedecor_expect_infinite_stacks then
itemstack:take_item()
return itemstack
end
end
else
minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack)
end
end
end
-- Yellow -- Half node
minetest.register_node('technic:homedecor_glowlight_half_yellow', {
description = S("Yellow Glowlight (thick)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_yellow_tb.png',
'technic_homedecor_glowlight_yellow_tb.png',
'technic_homedecor_glowlight_thick_yellow_sides.png',
'technic_homedecor_glowlight_thick_yellow_sides.png',
'technic_homedecor_glowlight_thick_yellow_sides.png',
'technic_homedecor_glowlight_thick_yellow_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
},
node_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3 },
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thick)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_yellow_active")
end
})
minetest.register_node('technic:homedecor_glowlight_half_yellow_active', {
description = S("Yellow Glowlight (thick)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_yellow_tb.png',
'technic_homedecor_glowlight_yellow_tb.png',
'technic_homedecor_glowlight_thick_yellow_sides.png',
'technic_homedecor_glowlight_thick_yellow_sides.png',
'technic_homedecor_glowlight_thick_yellow_sides.png',
'technic_homedecor_glowlight_thick_yellow_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
},
node_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
light_source = LIGHT_MAX,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3, not_in_creative_inventory=1},
drop="technic:homedecor_glowlight_half_yellow",
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thick)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_yellow")
end
})
-- Yellow -- Quarter node
minetest.register_node('technic:homedecor_glowlight_quarter_yellow', {
description = S("Yellow Glowlight (thin)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_yellow_tb.png',
'technic_homedecor_glowlight_yellow_tb.png',
'technic_homedecor_glowlight_thin_yellow_sides.png',
'technic_homedecor_glowlight_thin_yellow_sides.png',
'technic_homedecor_glowlight_thin_yellow_sides.png',
'technic_homedecor_glowlight_thin_yellow_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
},
node_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3 },
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thin)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_yellow_active")
end
})
minetest.register_node('technic:homedecor_glowlight_quarter_yellow_active', {
description = S("Yellow Glowlight (thin)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_yellow_tb.png',
'technic_homedecor_glowlight_yellow_tb.png',
'technic_homedecor_glowlight_thin_yellow_sides.png',
'technic_homedecor_glowlight_thin_yellow_sides.png',
'technic_homedecor_glowlight_thin_yellow_sides.png',
'technic_homedecor_glowlight_thin_yellow_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
},
node_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3, not_in_creative_inventory=1},
drop="technic:homedecor_glowlight_quarter_yellow",
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thin)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_yellow")
end
})
-- White -- half node
minetest.register_node('technic:homedecor_glowlight_half_white', {
description = S("White Glowlight (thick)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_white_tb.png',
'technic_homedecor_glowlight_white_tb.png',
'technic_homedecor_glowlight_thick_white_sides.png',
'technic_homedecor_glowlight_thick_white_sides.png',
'technic_homedecor_glowlight_thick_white_sides.png',
'technic_homedecor_glowlight_thick_white_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
},
node_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3 },
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 100, "White Glowlight (thick)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_white_active")
end
})
minetest.register_node('technic:homedecor_glowlight_half_white_active', {
description = S("White Glowlight (thick)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_white_tb.png',
'technic_homedecor_glowlight_white_tb.png',
'technic_homedecor_glowlight_thick_white_sides.png',
'technic_homedecor_glowlight_thick_white_sides.png',
'technic_homedecor_glowlight_thick_white_sides.png',
'technic_homedecor_glowlight_thick_white_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
},
node_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
light_source = LIGHT_MAX,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3, not_in_creative_inventory=1},
drop="technic:homedecor_glowlight_half_white",
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 100, "White Glowlight (thick)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_white")
end
})
-- White -- Quarter node
minetest.register_node('technic:homedecor_glowlight_quarter_white', {
description = S("White Glowlight (thin)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_white_tb.png',
'technic_homedecor_glowlight_white_tb.png',
'technic_homedecor_glowlight_thin_white_sides.png',
'technic_homedecor_glowlight_thin_white_sides.png',
'technic_homedecor_glowlight_thin_white_sides.png',
'technic_homedecor_glowlight_thin_white_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
},
node_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3 },
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 100, "White Glowlight (thin)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_white_active")
end
})
minetest.register_node('technic:homedecor_glowlight_quarter_white_active', {
description = S("White Glowlight (thin)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_white_tb.png',
'technic_homedecor_glowlight_white_tb.png',
'technic_homedecor_glowlight_thin_white_sides.png',
'technic_homedecor_glowlight_thin_white_sides.png',
'technic_homedecor_glowlight_thin_white_sides.png',
'technic_homedecor_glowlight_thin_white_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
},
node_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3, not_in_creative_inventory=1},
drop="technic:homedecor_glowlight_quarter_white",
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 100, "White Glowlight (thin)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_white")
end
})
-- Glowlight "cubes" - yellow
minetest.register_node('technic:homedecor_glowlight_small_cube_yellow', {
description = S("Yellow Glowlight (small cube)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_cube_yellow_tb.png',
'technic_homedecor_glowlight_cube_yellow_tb.png',
'technic_homedecor_glowlight_cube_yellow_sides.png',
'technic_homedecor_glowlight_cube_yellow_sides.png',
'technic_homedecor_glowlight_cube_yellow_sides.png',
'technic_homedecor_glowlight_cube_yellow_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
},
node_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3 },
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_yellow_active")
end
})
minetest.register_node('technic:homedecor_glowlight_small_cube_yellow_active', {
description = S("Yellow Glowlight (small cube)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_cube_yellow_tb.png',
'technic_homedecor_glowlight_cube_yellow_tb.png',
'technic_homedecor_glowlight_cube_yellow_sides.png',
'technic_homedecor_glowlight_cube_yellow_sides.png',
'technic_homedecor_glowlight_cube_yellow_sides.png',
'technic_homedecor_glowlight_cube_yellow_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
},
node_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3, not_in_creative_inventory=1},
drop="technic:homedecor_glowlight_cube_yellow",
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_yellow")
end
})
-- Glowlight "cubes" - white
minetest.register_node('technic:homedecor_glowlight_small_cube_white', {
description = S("White Glowlight (small cube)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_cube_white_tb.png',
'technic_homedecor_glowlight_cube_white_tb.png',
'technic_homedecor_glowlight_cube_white_sides.png',
'technic_homedecor_glowlight_cube_white_sides.png',
'technic_homedecor_glowlight_cube_white_sides.png',
'technic_homedecor_glowlight_cube_white_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
},
node_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3 },
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 50, "White Glowlight (small cube)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_white_active")
end
})
minetest.register_node('technic:homedecor_glowlight_small_cube_white_active', {
description = S("White Glowlight (small cube)"),
drawtype = "nodebox",
tiles = {
'technic_homedecor_glowlight_cube_white_tb.png',
'technic_homedecor_glowlight_cube_white_tb.png',
'technic_homedecor_glowlight_cube_white_sides.png',
'technic_homedecor_glowlight_cube_white_sides.png',
'technic_homedecor_glowlight_cube_white_sides.png',
'technic_homedecor_glowlight_cube_white_sides.png'
},
selection_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
},
node_box = {
type = "fixed",
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
},
sunlight_propagates = false,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
light_source = LIGHT_MAX-1,
sounds = default.node_sound_wood_defaults(),
groups = { snappy = 3, not_in_creative_inventory=1},
drop="technic:homedecor_glowlight_cube_white",
on_place = function(itemstack, placer, pointed_thing)
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
return itemstack
end,
on_construct = function(pos)
technic.inductive_on_construct(pos, 50, "White Glowlight (small cube)")
end,
on_punch = function(pos, node, puncher)
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_white")
end
})
technic.register_inductive_machine("technic:homedecor_glowlight_half_yellow")
technic.register_inductive_machine("technic:homedecor_glowlight_half_white")
technic.register_inductive_machine("technic:homedecor_glowlight_quarter_yellow")
technic.register_inductive_machine("technic:homedecor_glowlight_quarter_white")
technic.register_inductive_machine("technic:homedecor_glowlight_small_cube_yellow")
technic.register_inductive_machine("technic:homedecor_glowlight_small_cube_white")

View File

@ -1,9 +1,9 @@
mining_drill_max_charge=60000 local mining_drill_max_charge=60000
mining_drill_mk2_max_charge=240000 local mining_drill_mk2_max_charge=240000
mining_drill_mk3_max_charge=960000 local mining_drill_mk3_max_charge=960000
mining_drill_power_usage=200 local mining_drill_power_usage=200
mining_drill_mk2_power_usage=600 local mining_drill_mk2_power_usage=600
mining_drill_mk3_power_usage=1800 local mining_drill_mk3_power_usage=1800
minetest.register_craft({ minetest.register_craft({
output = 'technic:mining_drill', output = 'technic:mining_drill',
@ -210,7 +210,7 @@ function drill_dig_it4 (pos,player)
drill_dig_it0 (pos,player) drill_dig_it0 (pos,player)
end end
register_power_tool ("technic:mining_drill",mining_drill_max_charge) technic.register_MV_power_tool ("technic:mining_drill",mining_drill_max_charge)
minetest.register_tool("technic:mining_drill", { minetest.register_tool("technic:mining_drill", {
description = "Mining Drill Mk1", description = "Mining Drill Mk1",
inventory_image = "technic_mining_drill.png", inventory_image = "technic_mining_drill.png",
@ -227,7 +227,7 @@ minetest.register_tool("technic:mining_drill", {
charge =charge-mining_drill_power_usage; charge =charge-mining_drill_power_usage;
meta["charge"]=charge meta["charge"]=charge
item["metadata"]=set_item_meta(meta) item["metadata"]=set_item_meta(meta)
set_RE_wear(item,charge,mining_drill_max_charge) technic.set_RE_wear(item,charge,mining_drill_max_charge)
itemstack:replace(item) itemstack:replace(item)
end end
return itemstack return itemstack
@ -243,10 +243,10 @@ minetest.register_tool("technic:mining_drill_mk2", {
return itemstack return itemstack
end, end,
}) })
register_power_tool ("technic:mining_drill_mk2",mining_drill_mk2_max_charge) technic.register_HV_power_tool ("technic:mining_drill_mk2",mining_drill_mk2_max_charge)
for i=1,4,1 do for i=1,4,1 do
register_power_tool ("technic:mining_drill_mk2_"..i,mining_drill_mk2_max_charge) technic.register_HV_power_tool ("technic:mining_drill_mk2_"..i,mining_drill_mk2_max_charge)
minetest.register_tool("technic:mining_drill_mk2_"..i, { minetest.register_tool("technic:mining_drill_mk2_"..i, {
description = "Mining Drill Mk2 in Mode "..i, description = "Mining Drill Mk2 in Mode "..i,
inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png", inventory_image = "technic_mining_drill_mk2.png^technic_tool_mode"..i..".png",
@ -267,10 +267,10 @@ minetest.register_tool("technic:mining_drill_mk3", {
return itemstack return itemstack
end, end,
}) })
register_power_tool ("technic:mining_drill_mk3",mining_drill_mk3_max_charge) technic.register_HV_power_tool ("technic:mining_drill_mk3",mining_drill_mk3_max_charge)
for i=1,5,1 do for i=1,5,1 do
register_power_tool ("technic:mining_drill_mk3_"..i,mining_drill_mk3_max_charge) technic.register_HV_power_tool ("technic:mining_drill_mk3_"..i,mining_drill_mk3_max_charge)
minetest.register_tool("technic:mining_drill_mk3_"..i, { minetest.register_tool("technic:mining_drill_mk3_"..i, {
description = "Mining Drill Mk3 in Mode "..i, description = "Mining Drill Mk3 in Mode "..i,
inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png", inventory_image = "technic_mining_drill_mk3.png^technic_tool_mode"..i..".png",
@ -299,7 +299,7 @@ function mining_drill_mk2_handler (itemstack,user,pointed_thing)
if charge<0 then charge=0 end if charge<0 then charge=0 end
meta["charge"]=charge meta["charge"]=charge
item["metadata"]=set_item_meta(meta) item["metadata"]=set_item_meta(meta)
set_RE_wear(item,charge,mining_drill_mk2_max_charge) technic.set_RE_wear(item,charge,mining_drill_mk2_max_charge)
itemstack:replace(item) itemstack:replace(item)
end end
return itemstack return itemstack
@ -321,7 +321,7 @@ function mining_drill_mk3_handler (itemstack,user,pointed_thing)
if charge<0 then charge=0 end if charge<0 then charge=0 end
meta["charge"]=charge meta["charge"]=charge
item["metadata"]=set_item_meta(meta) item["metadata"]=set_item_meta(meta)
set_RE_wear(item,charge,mining_drill_mk3_max_charge) technic.set_RE_wear(item,charge,mining_drill_mk3_max_charge)
itemstack:replace(item) itemstack:replace(item)
end end
return itemstack return itemstack

View File

@ -1,5 +1,5 @@
laser_mk1_max_charge=40000 local laser_mk1_max_charge=40000
register_power_tool ("technic:laser_mk1",laser_mk1_max_charge) technic.register_LV_power_tool ("technic:laser_mk1",laser_mk1_max_charge)
local laser_shoot = function(itemstack, player, pointed_thing) local laser_shoot = function(itemstack, player, pointed_thing)
local laser_straight_mode=0 local laser_straight_mode=0
@ -62,8 +62,8 @@ minetest.register_tool("technic:laser_mk1", {
charge=meta["charge"] charge=meta["charge"]
if charge-400>0 then if charge-400>0 then
laser_shoot(item, user, pointed_thing) laser_shoot(item, user, pointed_thing)
charge =charge-400; charge = charge-400;
set_RE_wear(item,charge,laser_mk1_max_charge) technic.set_RE_wear(item,charge,laser_mk1_max_charge)
meta["charge"]=charge meta["charge"]=charge
item["metadata"]=set_item_meta(meta) item["metadata"]=set_item_meta(meta)
itemstack:replace(item) itemstack:replace(item)

View File

@ -1,3 +1,5 @@
-- LV Music player.
-- The playe can play music. But it is high ampage!
minetest.register_alias("music_player", "technic:music_player") minetest.register_alias("music_player", "technic:music_player")
minetest.register_craft({ minetest.register_craft({
output = 'technic:music_player', output = 'technic:music_player',
@ -13,110 +15,142 @@ minetest.register_craftitem("technic:music_player", {
stack_max = 99, stack_max = 99,
}) })
music_player_formspec = local music_player_formspec =
"invsize[8,9;]".. "invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "label[0,0;Music Player]"..
"label[0,0;Music Player]".. "button[4,1;1,1;track1;1]"..
"label[1,3;Power level]".. "button[5,1;1,1;track2;2]"..
"button[5,2;1,1;track1;1]".. "button[6,1;1,1;track3;3]"..
"button[6,2;1,1;track2;2]" "button[4,2;1,1;track4;4]"..
"button[5,2;1,1;track5;5]"..
"button[6,2;1,1;track6;6]"..
"button[4,3;1,1;track7;7]"..
"button[5,3;1,1;track8;8]"..
"button[6,3;1,1;track9;9]"..
"button[4,4;1,2;play;Play]"..
"button[6,4;1,2;stop;Stop]"..
"label[4,0;Current track --]"
minetest.register_node(
"technic:music_player",
{
description = "Music Player",
tiles = {"technic_music_player_top.png", "technic_machine_bottom.png", "technic_music_player_side.png",
"technic_music_player_side.png", "technic_music_player_side.png", "technic_music_player_side.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Music Player")
meta:set_float("technic_power_machine", 1)
meta:set_int("active", 0) -- Is the device on?
meta:set_int("music_player_current_track", 1)
meta:set_string("formspec", music_player_formspec)
end,
on_receive_fields = function(pos, formanme, fields, sender)
local meta = minetest.env:get_meta(pos)
music_handle = meta:get_int("music_handle")
music_player_current_track = meta:get_int("music_player_current_track")
if fields.track1 then music_player_current_track = 1 end
if fields.track2 then music_player_current_track = 2 end
if fields.track3 then music_player_current_track = 3 end
if fields.track4 then music_player_current_track = 4 end
if fields.track5 then music_player_current_track = 5 end
if fields.track6 then music_player_current_track = 6 end
if fields.track7 then music_player_current_track = 7 end
if fields.track8 then music_player_current_track = 8 end
if fields.track9 then music_player_current_track = 9 end
meta:set_int("music_player_current_track",music_player_current_track)
if fields.play and meta:get_int("active") == 0 then
if music_handle then minetest.sound_stop(music_handle) end
music_handle = minetest.sound_play("technic_track"..music_player_current_track, {pos = pos, gain = 1.0,loop = true, max_hear_distance = 72,})
meta:set_int("active",1)
end
if fields.stop then
meta:set_int("active",0)
if music_handle then minetest.sound_stop(music_handle) end
end
meta:set_int("music_handle",music_handle)
end,
})
minetest.register_node("technic:music_player", { minetest.register_abm(
description = "Music Player", { nodenames = {"technic:music_player"},
tiles = {"technic_music_player_top.png", "technic_machine_bottom.png", "technic_music_player_side.png", interval = 1,
"technic_music_player_side.png", "technic_music_player_side.png", "technic_music_player_side.png"}, chance = 1,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, action = function(pos, node, active_object_count, active_object_count_wider)
sounds = default.node_sound_wood_defaults(), local meta = minetest.env:get_meta(pos)
technic_power_machine=1, local eu_input = meta:get_int("LV_EU_input")
internal_EU_buffer=0, local state = meta:get_int("state")
internal_EU_buffer_size=5000, local next_state = state
music_player_on=0,
music_playing =0,
music_handle = 0,
music_player_current_track =1,
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Music Player")
meta:set_float("technic_power_machine", 1)
meta:set_float("internal_EU_buffer", 1)
meta:set_float("internal_EU_buffer_size", 5000)
meta:set_string("formspec", music_player_formspec)
meta:set_float("music_player_on", 0)
meta:set_float("music_player_current_track", 1)
end,
on_receive_fields = function(pos, formanme, fields, sender) -- Machine information
local machine_name = "Music Player"
local machine_node = "technic:music_player"
local machine_state_demand = { 10, 150 }
local meta = minetest.env:get_meta(pos) local music_handle = meta:get_int("music_handle")
player_on=meta:get_float("music_player_on")
music_handle=meta:get_float("music_handle")
music_player_current_track=meta:get_float("music_player_current_track")
if fields.track1 then music_player_current_track=1 end
if fields.track2 then music_player_current_track=2 end
if fields.track3 then music_player_current_track=3 end
if fields.track4 then music_player_current_track=4 end
if fields.track5 then music_player_current_track=5 end
if fields.track6 then music_player_current_track=6 end
if fields.track7 then music_player_current_track=7 end
if fields.track8 then music_player_current_track=8 end
if fields.track9 then music_player_current_track=9 end
meta:set_float("music_player_current_track",music_player_current_track)
if fields.play and player_on==1 then
if music_handle then minetest.sound_stop(music_handle) end
music_handle=minetest.sound_play("technic_track"..music_player_current_track, {pos = pos, gain = 1.0,loop = true, max_hear_distance = 72,})
meta:set_float("music_playing",1)
end
if fields.stop then
meta:set_float("music_playing",0)
if music_handle then minetest.sound_stop(music_handle) end
end
meta:set_float("music_handle",music_handle)
end,
})
minetest.register_abm({ -- Setup meta data if it does not exist. state is used as an indicator of this
nodenames = {"technic:music_player"}, if state == 0 then
interval = 1, meta:set_int("state", 1)
chance = 1, meta:set_int("LV_EU_demand", machine_state_demand[1])
action = function(pos, node, active_object_count, active_object_count_wider) meta:set_int("LV_EU_input", 0)
local meta = minetest.env:get_meta(pos) return
local charge= meta:get_float("internal_EU_buffer") end
local max_charge= meta:get_float("internal_EU_buffer_size")
player_on=meta:get_float("music_player_on")
music_player_current_track=meta:get_float("music_player_current_track")
local play_cost=80
if charge>play_cost then -- Power off automatically if no longer connected to a switching station
if meta:get_float("music_playing")==1 then charge=charge-play_cost end technic.switching_station_timeout_count(pos, "LV")
meta:set_float("internal_EU_buffer",charge)
meta:set_float("music_player_on",1)
else
meta:set_float("music_playing",0)
meta:set_float("music_player_on",0)
if music_handle then minetest.sound_stop(music_handle) end
end
local load = math.floor((charge/max_charge)*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;Music Player]"..
"label[1,3;Power level]"..
"button[4,1;1,1;track1;1]"..
"button[5,1;1,1;track2;2]"..
"button[6,1;1,1;track3;3]"..
"button[4,2;1,1;track4;4]"..
"button[5,2;1,1;track5;5]"..
"button[6,2;1,1;track6;6]"..
"button[4,3;1,1;track7;7]"..
"button[5,3;1,1;track8;8]"..
"button[6,3;1,1;track9;9]"..
"button[4,4;1,2;play;Play]"..
"button[6,4;1,2;stop;Stop]"..
"label[4,0;Current track "..tostring(music_player_current_track).."]"
)
end
})
register_LV_machine ("technic:music_player","RE") -- State machine
if eu_input == 0 then
-- unpowered - go idle
-- hacky_swap_node(pos, machine_node) -- if someday two nodes for this
meta:set_string("infotext", machine_name.." Unpowered")
next_state = 1
elseif eu_input == machine_state_demand[state] then
-- Powered - do the state specific actions
if state == 1 then
-- hacky_swap_node(pos, machine_node) -- if someday two nodes for this
meta:set_string("infotext", machine_name.." Idle")
if meta:get_int("active") == 1 then
next_state = 2
end
elseif state == 2 then
-- hacky_swap_node(pos, machine_node.."_active") -- if someday two nodes for this
meta:set_string("infotext", machine_name.." Active")
music_player_current_track=meta:get_int("music_player_current_track")
meta:set_string("formspec",
"invsize[8,9;]"..
"label[0,0;Music Player]"..
"button[4,1;1,1;track1;1]"..
"button[5,1;1,1;track2;2]"..
"button[6,1;1,1;track3;3]"..
"button[4,2;1,1;track4;4]"..
"button[5,2;1,1;track5;5]"..
"button[6,2;1,1;track6;6]"..
"button[4,3;1,1;track7;7]"..
"button[5,3;1,1;track8;8]"..
"button[6,3;1,1;track9;9]"..
"button[4,4;1,2;play;Play]"..
"button[6,4;1,2;stop;Stop]"..
"label[4,0;Current track "..tostring(music_player_current_track).."]"
)
if meta:get_int("active") == 0 then
if music_handle then minetest.sound_stop(music_handle) end
next_state = 1
end
end
end
-- Change state?
if next_state ~= state then
meta:set_int("LV_EU_demand", machine_state_demand[next_state])
meta:set_int("state", next_state)
end
end
})
technic.register_LV_machine ("technic:music_player","RE")

205
technic/power_radiator.lua Normal file
View File

@ -0,0 +1,205 @@
-- The power radiator fuctions like an inductive charger
-- only better in the game setting.
-- The purpose is to allow small appliances to receive power
-- without the overhead of the wiring needed for larger machines.
--
-- The power radiator will consume power corresponding to the
-- sum(power rating of the attached appliances)/0.6
-- Using inductive power transfer is very inefficient so this is
-- set to the factor 0.6.
------------------------------------------------------------------
-- API for inductive powered nodes:
-- Use the functions below to set the corresponding callbacks
-- Also two nodes are needed: The inactive and the active one. The active must be called <name>_active .
------------------------------------------------------------------
-- Register a new appliance using this function
technic.inductive_nodes = {}
technic.register_inductive_machine = function(name)
table.insert(technic.inductive_nodes, name)
table.insert(technic.inductive_nodes, name.."_active")
end
-- Appliances:
-- has_supply: pos of supply node if the appliance has a power radiator near with sufficient power for the demand else ""
-- EU_demand: The power demand of the device.
-- EU_charge: Actual use. set to EU_demand if active==1
-- active: set to 1 if the device is on
technic.inductive_on_construct = function(pos, eu_demand, infotext)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", infotext)
meta:set_int("technic_inductive_power_machine", 1)
meta:set_int("MV_EU_demand",eu_demand) -- The power demand of this appliance
meta:set_int("EU_charge",0) -- The actual power draw of this appliance
meta:set_string("has_supply","") -- Register whether we are powered or not. For use with several radiators.
meta:set_int("active", 0) -- If the appliance can be turned on and off by using it use this.
end
technic.inductive_on_punch_off = function(pos, eu_charge, swapnode)
local meta = minetest.env:get_meta(pos)
if meta:get_string("has_supply") ~= "" then
hacky_swap_node(pos, swapnode)
meta:set_int("active", 1)
meta:set_int("EU_charge",eu_charge)
--print("-----------")
--print("Turn on:")
--print("EUcha:"..meta:get_int("EU_charge"))
--print("has_supply:"..meta:get_string("has_supply"))
--print("<----------->")
end
end
technic.inductive_on_punch_on = function(pos, eu_charge, swapnode)
local meta = minetest.env:get_meta(pos)
hacky_swap_node(pos, swapnode)
meta:set_int("active", 0)
meta:set_int("EU_charge",eu_charge)
--print("-----------")
--print("Turn off:")
--print("EUcha:"..meta:get_int("EU_charge"))
--print("has_supply:"..meta:get_string("has_supply"))
--print("<---------->")
end
local shutdown_inductive_appliances = function(pos)
-- The supply radius
local rad = 4
-- If the radiator is removed. turn off all appliances in region
-- If another radiator is near it will turn on the appliances again
local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic.inductive_nodes)
for _,pos1 in ipairs(positions) do
local meta1 = minetest.env:get_meta(pos1)
-- If the appliance is belonging to this node
if meta1:get_string("has_supply") == pos.x..pos.y..pos.z then
local nodename = minetest.env:get_node(pos1).name
-- Swap the node and make sure it is off and unpowered
if string.sub(nodename, -7) == "_active" then
hacky_swap_node(pos1, string.sub(nodename, 1, -8))
meta1:set_int("active", 0)
meta1:set_int("EU_charge", 0)
end
meta1:set_string("has_supply", "")
end
end
end
minetest.register_node(
"technic:power_radiator", {
description = "Power Radiator",
tiles = {"technic_hv_down_converter_top.png", "technic_hv_down_converter_bottom.png", "technic_hv_down_converter_side.png",
"technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png", "technic_hv_down_converter_side.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
drawtype = "nodebox",
paramtype = "light",
is_ground_content = true,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_int("technic_mv_power_machine", 1) -- MV machine
meta:set_int("MV_EU_demand",1) -- Demand on the primary side when idle
meta:set_int("connected_EU_demand",0) -- Potential demand of connected appliances
meta:set_string("infotext", "Power Radiator")
-- meta:set_int("active", 0)
end,
on_dig = function(pos, node, digger)
shutdown_inductive_appliances(pos)
return minetest.node_dig(pos, node, digger)
end,
})
minetest.register_craft(
{
output = 'technic:power_radiator 1',
recipe = {
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
{'technic:copper_coil', 'technic:mv_transformer', 'technic:copper_coil'},
{'technic:rubber', 'technic:mv_cable', 'technic:rubber'},
}
})
minetest.register_abm(
{nodenames = {"technic:power_radiator"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local eu_input = meta:get_int("MV_EU_input")
local eu_demand = meta:get_int("MV_EU_demand")
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "MV")
if eu_input == 0 then
-- No power
meta:set_string("infotext", "Power Radiator is unpowered");
-- meta:set_int("active",1) -- used for setting textures someday maybe
shutdown_inductive_appliances(pos)
connected_EU_demand = 0
elseif eu_input == eu_demand then
-- Powered and ready
-- The maximum EU sourcing a single radiator can provide.
local max_charge = 3000 -- == the max EU demand of the radiator
local connected_EU_demand = meta:get_int("connected_EU_demand")
-- Efficiency factor
local eff_factor = 0.6
-- The supply radius
local rad = 6
local meta1 = nil
local pos1 = {}
local used_charge = 0
-- Index all nodes within supply range
local positions = minetest.env:find_nodes_in_area({x=pos.x-rad,y=pos.y-rad,z=pos.z-rad},{x=pos.x+rad,y=pos.y+rad,z=pos.z+rad}, technic.inductive_nodes)
for _,pos1 in ipairs(positions) do
local meta1 = minetest.env:get_meta(pos1)
-- If not supplied see if this node can handle it.
if meta1:get_string("has_supply") == "" then
-- if demand surpasses the capacity of this node, don't bother adding it.
local app_eu_demand = meta1:get_int("EU_demand")/eff_factor
if connected_EU_demand + app_eu_demand <= max_charge then
-- We can power the appliance. Register, and spend power if it is on.
connected_EU_demand = connected_EU_demand + app_eu_demand
meta1:set_string("has_supply", pos.x..pos.y..pos.z)
used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor)
end
elseif meta1:get_string("has_supply") == pos.x..pos.y..pos.z then
-- The appliance has power from this node. Spend power if it is on.
used_charge = math.floor(used_charge+meta1:get_int("EU_charge")/eff_factor)
print("My Lamp ("..pos.x..","..pos.y..","..pos.z..") Used:"..used_charge)
end
meta:set_string("infotext", "Power Radiator is powered ("..math.floor(used_charge/max_charge*100).."% of maximum power)");
if used_charge == 0 then
meta:set_int("MV_EU_demand", 1) -- Still idle
else
meta:set_int("MV_EU_demand", used_charge)
end
-- meta:set_int("active",1) -- used for setting textures someday maybe
end
-- Save state
meta:set_int("connected_EU_demand",connected_EU_demand)
else
-- This is the case where input ~= demand. Overloaded or underpowered!
-- --If demand surpasses actual supply turn off everything - we are out of power
-- if used_charge>eu_input then
-- meta:set_string("infotext", "Power Radiator is overloaded ("..math.floor(used_charge/eu_input*100).."% of available power)");
---- meta:set_int("active",1) -- used for setting textures someday maybe
-- shutdown_inductive_appliances(pos)
-- connected_EU_demand = 0
end
end,
})
technic.register_MV_machine ("technic:power_radiator","RE")

View File

@ -0,0 +1,70 @@
-- This file includes the functions and data structures for registering machines and tools for LV, MV, HV types.
-- We use the technioc namespace for these functions and data to avoid eventual conflict.
-- register LV machines here
technic.LV_machines = {}
technic.LV_power_tools = {}
technic.register_LV_machine = function(nodename,type)
technic.LV_machines[nodename] = type
end
technic.unregister_LV_machine = function(nodename,type)
technic.LV_machines[nodename] = nil
end
technic.register_LV_power_tool = function(craftitem,max_charge)
technic.LV_power_tools[craftitem] = max_charge
end
-- register MV machines here
technic.MV_machines = {}
technic.MV_power_tools = {}
technic.register_MV_machine = function(nodename,type)
technic.MV_machines[nodename] = type
end
technic.unregister_MV_machine = function(nodename)
technic.MV_machines[nodename] = nil
end
technic.register_MV_power_tool = function(craftitem,max_charge)
technic.MV_power_tools[craftitem] = max_charge
end
-- register HV machines here
technic.HV_machines = {}
technic.HV_power_tools = {}
technic.register_HV_machine = function(nodename,type)
technic.HV_machines[nodename] = type
end
technic.unregister_HV_machine = function(nodename)
technic.HV_machines[nodename] = nil
end
technic.register_HV_power_tool = function(craftitem,max_charge)
technic.HV_power_tools[craftitem] = max_charge
end
-- Utility functions. Not sure exactly what they do.. water.lua uses the two first.
function technic.get_RE_item_load (load1,max_load)
if load1==0 then load1=65535 end
local temp = 65536-load1
temp= temp/65535*max_load
return math.floor(temp + 0.5)
end
function technic.set_RE_item_load (load1,max_load)
if load1 == 0 then return 65535 end
local temp=load1/max_load*65535
temp=65536-temp
return math.floor(temp)
end
-- Wear down a tool depending on the remaining charge.
function technic.set_RE_wear (item_stack,load,max_load)
local temp=65536-math.floor(load/max_load*65535)
item_stack["wear"]=tostring(temp)
return item_stack
end

View File

@ -10,9 +10,6 @@ minetest.register_node("technic:solar_array_hv", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
description="HV Solar Array", description="HV Solar Array",
active = false, active = false,
technic_hv_power_machine=1,
internal_EU_buffer=0;
internal_EU_buffer_size=3000;
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
is_ground_content = true, is_ground_content = true,
@ -27,29 +24,25 @@ minetest.register_node("technic:solar_array_hv", {
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_float("technic_hv_power_machine", 1) meta:set_float("technic_hv_power_machine", 1)
meta:set_float("internal_EU_buffer", 0) meta:set_int("HV_EU_supply", 0)
meta:set_float("internal_EU_buffer_size", 3000)
meta:set_string("infotext", "HV Solar Array") meta:set_string("infotext", "HV Solar Array")
meta:set_float("active", false)
end, end,
}) })
minetest.register_craft({ minetest.register_craft(
output = 'technic:solar_array_hv 1', {output = 'technic:solar_array_hv 1',
recipe = { recipe = {
{'technic:solar_array_mv', 'technic:solar_array_mv','technic:solar_array_mv'}, {'technic:solar_array_mv', 'technic:solar_array_mv','technic:solar_array_mv'},
{'technic:solar_array_mv', 'technic:hv_transformer','technic:solar_array_mv'}, {'technic:solar_array_mv', 'technic:hv_transformer','technic:solar_array_mv'},
{'default:steel_ingot', 'technic:hv_cable', 'default:steel_ingot'}, {'default:steel_ingot', 'technic:hv_cable', 'default:steel_ingot'},
}
} })
})
minetest.register_abm( minetest.register_abm(
{nodenames = {"technic:solar_array_hv"}, {nodenames = {"technic:solar_array_hv"},
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)
-- The action here is to make the solar array produce power -- The action here is to make the solar array produce power
-- Power is dependent on the light level and the height above ground -- Power is dependent on the light level and the height above ground
-- 130m and above is optimal as it would be above cloud level. -- 130m and above is optimal as it would be above cloud level.
@ -70,24 +63,16 @@ minetest.register_abm(
-- turn on array only during day time and if sufficient light -- turn on array only during day time and if sufficient light
-- I know this is counter intuitive when cheating by using other light sources. -- I know this is counter intuitive when cheating by using other light sources.
if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
local internal_EU_buffer = meta:get_float("internal_EU_buffer") local charge_to_give = math.floor(light*(light*9.6+pos1.y/130*48))
local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size") if charge_to_give<0 then charge_to_give=0 end
local charge_to_give = math.floor(light*(light*9.6+pos1.y/130*48)) if charge_to_give>160 then charge_to_give=160 end
if charge_to_give<0 then charge_to_give=0 end meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
if charge_to_give>2880 then charge_to_give=2880 end meta:set_int("HV_EU_supply", charge_to_give)
if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
charge_to_give=internal_EU_buffer_size-internal_EU_buffer
end
meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
meta:set_float("active",1)
internal_EU_buffer=internal_EU_buffer+charge_to_give
meta:set_float("internal_EU_buffer",internal_EU_buffer)
else else
meta:set_string("infotext", "Solar Array is inactive"); meta:set_string("infotext", "Solar Array is inactive");
meta:set_float("active",0) meta:set_int("HV_EU_supply", 0)
end end
end, end,
}) })
register_HV_machine ("technic:solar_array_hv","PR") technic.register_HV_machine ("technic:solar_array_hv","PR")

View File

@ -10,10 +10,6 @@ minetest.register_node("technic:solar_array_lv", {
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
description="LV Solar Array", description="LV Solar Array",
active = false,
technic_power_machine=1,
internal_EU_buffer=0;
internal_EU_buffer_size=1000;
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
is_ground_content = true, is_ground_content = true,
@ -27,38 +23,34 @@ minetest.register_node("technic:solar_array_lv", {
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_float("technic_power_machine", 1) meta:set_int("technic_power_machine", 1)
meta:set_float("internal_EU_buffer", 0) meta:set_int("LV_EU_supply", 0)
meta:set_float("internal_EU_buffer_size", 1000)
meta:set_string("infotext", "LV Solar Array") meta:set_string("infotext", "LV Solar Array")
meta:set_float("active", false)
end, end,
}) })
minetest.register_craft({ minetest.register_craft(
output = 'technic:solar_array_lv 1', {output = 'technic:solar_array_lv 1',
recipe = { recipe = {
{'technic:solar_panel', 'technic:solar_panel', 'technic:solar_panel'}, {'technic:solar_panel', 'technic:solar_panel', 'technic:solar_panel'},
{'technic:solar_panel', 'technic:lv_transformer', 'technic:solar_panel'}, {'technic:solar_panel', 'technic:lv_transformer', 'technic:solar_panel'},
{'default:steel_ingot', 'technic:lv_cable', 'default:steel_ingot'}, {'default:steel_ingot', 'technic:lv_cable', 'default:steel_ingot'},
}
} })
})
minetest.register_abm( minetest.register_abm(
{nodenames = {"technic:solar_array_lv"}, {nodenames = {"technic:solar_array_lv"},
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)
-- The action here is to make the solar array produce power -- The action here is to make the solar array produce power
-- Power is dependent on the light level and the height above ground -- Power is dependent on the light level and the height above ground
-- 130m and above is optimal as it would be above cloud level. -- 130m and above is optimal as it would be above cloud level.
-- Height gives 1/4 of the effect, light 3/4. Max. effect is 160EU for the array. -- Height gives 1/4 of the effect, light 3/4. Max. effect is 160EU for the array.
-- There are many ways to cheat by using other light sources like lamps. -- There are many ways to cheat by using other light sources like lamps.
-- As there is no way to determine if light is sunlight that is just a shame. -- As there is no way to determine if light is sunlight that is just a shame.
-- To take care of some of it solar arrays do not work outside daylight hours or if -- To take care of some of it solar arrays do not work outside daylight hours or if
-- built below -10m -- built below -10m
local pos1={} local pos1={}
pos1.y=pos.y+1 pos1.y=pos.y+1
pos1.x=pos.x pos1.x=pos.x
@ -69,26 +61,18 @@ minetest.register_abm(
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
if light == nil then light = 0 end if light == nil then light = 0 end
-- turn on array only during day time and if sufficient light -- turn on array only during day time and if sufficient light
-- I know this is counter intuitive when cheating by using other light sources. -- I know this is counter intuitive when cheating by using other light sources.
if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
local internal_EU_buffer = meta:get_float("internal_EU_buffer") local charge_to_give = math.floor(light*(light*0.5333+pos1.y/130*2.6667))
local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size") if charge_to_give<0 then charge_to_give=0 end
local charge_to_give = math.floor(light*(light*0.5333+pos1.y/130*2.6667)) if charge_to_give>160 then charge_to_give=160 end
if charge_to_give<0 then charge_to_give=0 end meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
if charge_to_give>160 then charge_to_give=160 end meta:set_int("LV_EU_supply", charge_to_give)
if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
charge_to_give=internal_EU_buffer_size-internal_EU_buffer
end
meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
meta:set_float("active",1)
internal_EU_buffer=internal_EU_buffer+charge_to_give
meta:set_float("internal_EU_buffer",internal_EU_buffer)
else else
meta:set_string("infotext", "Solar Array is inactive"); meta:set_string("infotext", "Solar Array is inactive");
meta:set_float("active",0) meta:set_int("LV_EU_supply", 0)
end end
end, end,
}) })
register_LV_machine ("technic:solar_array_lv","PR") technic.register_LV_machine ("technic:solar_array_lv","PR")

View File

@ -11,9 +11,6 @@ minetest.register_node("technic:solar_array_mv", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
description="MV Solar Array", description="MV Solar Array",
active = false, active = false,
technic_mv_power_machine=1,
internal_EU_buffer=0;
internal_EU_buffer_size=1000;
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
is_ground_content = true, is_ground_content = true,
@ -28,37 +25,34 @@ minetest.register_node("technic:solar_array_mv", {
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_float("technic_mv_power_machine", 1) meta:set_float("technic_mv_power_machine", 1)
meta:set_float("internal_EU_buffer", 0) meta:set_int("MV_EU_supply", 0)
meta:set_float("internal_EU_buffer_size", 1000)
meta:set_string("infotext", "MV Solar Array") meta:set_string("infotext", "MV Solar Array")
meta:set_float("active", false)
end, end,
}) })
minetest.register_craft({ minetest.register_craft(
output = 'technic:solar_array_mv 1', {
recipe = { output = 'technic:solar_array_mv 1',
{'technic:solar_array_lv', 'technic:solar_array_lv','technic:solar_array_lv'}, recipe = {
{'technic:solar_array_lv', 'technic:mv_transformer','technic:solar_array_lv'}, {'technic:solar_array_lv', 'technic:solar_array_lv','technic:solar_array_lv'},
{'default:steel_ingot', 'technic:mv_cable', 'default:steel_ingot'}, {'technic:solar_array_lv', 'technic:mv_transformer','technic:solar_array_lv'},
{'default:steel_ingot', 'technic:mv_cable', 'default:steel_ingot'},
} }
}) })
minetest.register_abm( minetest.register_abm(
{nodenames = {"technic:solar_array_mv"}, {nodenames = {"technic:solar_array_mv"},
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)
-- The action here is to make the solar array produce power -- The action here is to make the solar array produce power
-- Power is dependent on the light level and the height above ground -- Power is dependent on the light level and the height above ground
-- 130m and above is optimal as it would be above cloud level. -- 130m and above is optimal as it would be above cloud level.
-- Height gives 1/4 of the effect, light 3/4. Max. effect is 720EU for the array. -- Height gives 1/4 of the effect, light 3/4. Max. effect is 720EU for the array.
-- There are many ways to cheat by using other light sources like lamps. -- There are many ways to cheat by using other light sources like lamps.
-- As there is no way to determine if light is sunlight that is just a shame. -- As there is no way to determine if light is sunlight that is just a shame.
-- To take care of some of it solar panels do not work outside daylight hours or if -- To take care of some of it solar panels do not work outside daylight hours or if
-- built below -10m -- built below -10m
local pos1={} local pos1={}
pos1.y=pos.y+1 pos1.y=pos.y+1
pos1.x=pos.x pos1.x=pos.x
@ -69,27 +63,19 @@ minetest.register_abm(
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
if light == nil then light = 0 end if light == nil then light = 0 end
-- turn on array only during day time and if sufficient light -- turn on array only during day time and if sufficient light
-- I know this is counter intuitive when cheating by using other light sources. -- I know this is counter intuitive when cheating by using other light sources.
if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
local internal_EU_buffer = meta:get_float("internal_EU_buffer") local charge_to_give = math.floor(light*(light*2.4+pos1.y/130*12))
local internal_EU_buffer_size = meta:get_float("internal_EU_buffer_size") if charge_to_give<0 then charge_to_give=0 end
local charge_to_give = math.floor(light*(light*2.4+pos1.y/130*12)) if charge_to_give>160 then charge_to_give=160 end
if charge_to_give<0 then charge_to_give=0 end meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
if charge_to_give>720 then charge_to_give=720 end -- meta:set_float("active",1)
if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then meta:set_int("MV_EU_supply", charge_to_give)
charge_to_give=internal_EU_buffer_size-internal_EU_buffer
end
meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
meta:set_float("active",1)
internal_EU_buffer=internal_EU_buffer+charge_to_give
meta:set_float("internal_EU_buffer",internal_EU_buffer)
-- Idea: How about letting solar panels provide power without battery boxes?
-- This could provide an even distribution to all receivers.
else else
meta:set_string("infotext", "Solar Array is inactive"); meta:set_string("infotext", "Solar Array is inactive");
meta:set_float("active",0) meta:set_int("MV_EU_supply", 0)
end end
end, end,
}) })
register_MV_machine ("technic:solar_array_mv","PR") technic.register_MV_machine ("technic:solar_array_mv","PR")

View File

@ -8,9 +8,6 @@ minetest.register_node("technic:solar_panel", {
sounds = default.node_sound_wood_defaults(), sounds = default.node_sound_wood_defaults(),
description="Solar Panel", description="Solar Panel",
active = false, active = false,
technic_power_machine=1,
internal_EU_buffer=0;
internal_EU_buffer_size=160;
drawtype = "nodebox", drawtype = "nodebox",
paramtype = "light", paramtype = "light",
is_ground_content = true, is_ground_content = true,
@ -24,12 +21,9 @@ minetest.register_node("technic:solar_panel", {
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
meta:set_float("technic_power_machine", 1) meta:set_int("technic_power_machine", 1)
meta:set_float("internal_EU_buffer", 0) meta:set_int("LV_EU_supply", 0)
meta:set_float("internal_EU_buffer_size", 160) meta:set_string("infotext", "LV Solar Panel")
meta:set_string("infotext", "Solar Panel")
meta:set_float("active", false)
end, end,
}) })
@ -68,24 +62,16 @@ minetest.register_abm(
-- turn on panel only during day time and if sufficient light -- turn on panel only during day time and if sufficient light
-- I know this is counter intuitive when cheating by using other light sources underground. -- I know this is counter intuitive when cheating by using other light sources underground.
if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
local internal_EU_buffer=meta:get_float("internal_EU_buffer")
local internal_EU_buffer_size=meta:get_float("internal_EU_buffer_size")
local charge_to_give=math.floor(light*(light*0.0867+pos1.y/130*0.4333)) local charge_to_give=math.floor(light*(light*0.0867+pos1.y/130*0.4333))
if charge_to_give<0 then charge_to_give=0 end if charge_to_give<0 then charge_to_give=0 end
if charge_to_give>26 then charge_to_give=26 end if charge_to_give>26 then charge_to_give=26 end
if internal_EU_buffer+charge_to_give>internal_EU_buffer_size then
charge_to_give=internal_EU_buffer_size-internal_EU_buffer
end
meta:set_string("infotext", "Solar Panel is active ("..charge_to_give.."EU)") meta:set_string("infotext", "Solar Panel is active ("..charge_to_give.."EU)")
meta:set_float("active",1) meta:set_int("LV_EU_supply", charge_to_give)
internal_EU_buffer=internal_EU_buffer+charge_to_give
meta:set_float("internal_EU_buffer",internal_EU_buffer)
else else
meta:set_string("infotext", "Solar Panel is inactive"); meta:set_string("infotext", "Solar Panel is inactive");
meta:set_float("active",0) meta:set_int("LV_EU_supply", 0)
end end
end, end,
}) })
register_LV_machine ("technic:solar_panel","PR") technic.register_LV_machine ("technic:solar_panel","PR")

View File

@ -1,5 +1,5 @@
sonic_screwdriver_max_charge=15000 local sonic_screwdriver_max_charge=15000
register_power_tool ("technic:sonic_screwdriver",sonic_screwdriver_max_charge) technic.register_HV_power_tool ("technic:sonic_screwdriver",sonic_screwdriver_max_charge)
minetest.register_tool("technic:sonic_screwdriver", { minetest.register_tool("technic:sonic_screwdriver", {
description = "Sonic Screwdriver", description = "Sonic Screwdriver",

View File

@ -0,0 +1,223 @@
-- The supply converter is a generic device which can convert from
-- LV to MV and back, and HV to MV and back.
-- The machine will not convert from HV directly to LV.
-- The machine is configured by the wiring below and above it.
-- It is prepared for an upgrade slot if this is to be implemented later.
--
-- The conversion factor is a constant and the conversion is a lossy operation.
--
-- It works like this:
-- The top side is setup as the "RE" side, the bottom as the "PR" side.
-- Once the RE side is powered it will deliver power to the other side.
-- Unused power is wasted just like any other producer!
--
minetest.register_node(
"technic:supply_converter", {
description = "Supply Converter",
tiles = {"technic_mv_down_converter_top.png", "technic_mv_down_converter_bottom.png", "technic_mv_down_converter_side.png",
"technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
drawtype = "nodebox",
paramtype = "light",
is_ground_content = true,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_float("technic_hv_power_machine", 1)
meta:set_float("technic_mv_power_machine", 1)
meta:set_float("technic_power_machine", 1)
meta:set_string("infotext", "Supply Converter")
meta:set_float("active", false)
end,
})
minetest.register_craft({
output = 'technic:supply_converter 1',
recipe = {
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot','technic:stainless_steel_ingot'},
{'technic:mv_transformer', 'technic:mv_cable', 'technic:lv_transformer'},
{'technic:mv_cable', 'technic:rubber', 'technic:lv_cable'},
}
})
minetest.register_abm(
{ nodenames = {"technic:supply_converter"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- Conversion factors (a picture of V*A - loss) Asymmetric.
local lv_mv_factor = 5 -- division (higher is less efficient)
local mv_lv_factor = 4 -- multiplication (higher is more efficient)
local mv_hv_factor = 5 -- division
local hv_mv_factor = 4 -- multiplication
local max_lv_demand = 2000 -- The increment size pwer supply tier. Determines how many are needed
local max_mv_demand = 2000 -- -""-
local max_hv_demand = 2000 -- -""-
-- Machine information
local machine_name = "Supply Converter"
local meta = minetest.env:get_meta(pos)
local upgrade = "" -- Replace with expansion slot later??
-- High voltage on top, low at bottom regardless of converter direction
local pos_up = {x=pos.x, y=pos.y+1, z=pos.z}
local pos_down = {x=pos.x, y=pos.y-1, z=pos.z}
local meta_up = minetest.env:get_meta(pos_up)
local meta_down = minetest.env:get_meta(pos_down)
local convert_MV_LV = 0
local convert_LV_MV = 0
local convert_MV_HV = 0
local convert_HV_MV = 0
-- check cabling
if meta_up:get_float("mv_cablelike") == 1 and meta_down:get_float("cablelike") == 1 then
convert_MV_LV = 1
upgrade = "MV-LV step down"
end
if meta_up:get_float("cablelike") == 1 and meta_down:get_float("mv_cablelike") == 1 then
convert_LV_MV = 1
upgrade = "LV-MV step up"
end
if meta_up:get_float("mv_cablelike") == 1 and meta_down:get_float("hv_cablelike") == 1 then
convert_MV_HV = 1
upgrade = "MV-HV step up"
end
if meta_up:get_float("hv_cablelike") == 1 and meta_down:get_float("mv_cablelike") == 1 then
convert_HV_MV = 1
upgrade = "HV-MV step down"
end
--print("Cabling:"..convert_MV_LV.."|"..convert_LV_MV.."|"..convert_HV_MV.."|"..convert_MV_HV)
if convert_MV_LV == 0 and convert_LV_MV == 0 and convert_HV_MV == 0 and convert_MV_HV == 0 then
meta:set_string("infotext", machine_name.." has bad cabling")
return
end
-- The node is programmed with an upgrade slot
-- containing a MV-LV step down, LV-MV step up, HV-MV step down or MV-HV step up unit
if upgrade == "" then
meta:set_string("infotext", machine_name.." has an empty converter slot");
technic.unregister_LV_machine("technic:supply_converter")
technic.unregister_MV_machine("technic:supply_converter")
technic.unregister_HV_machine("technic:supply_converter")
meta:set_int("LV_EU_demand", 0)
meta:set_int("LV_EU_supply", 0)
meta:set_int("LV_EU_input", 0)
meta:set_int("MV_EU_demand", 0)
meta:set_int("MV_EU_supply", 0)
meta:set_int("MV_EU_input", 0)
meta:set_int("HV_EU_demand", 0)
meta:set_int("HV_EU_supply", 0)
meta:set_int("HV_EU_input", 0)
return
end
-- State machine
if upgrade == "MV-LV step down" and convert_MV_LV then
-- Register machine type
technic.register_LV_machine("technic:supply_converter","PR")
technic.register_MV_machine("technic:supply_converter","RE")
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "MV")
local eu_input = meta:get_int("MV_EU_input")
if eu_input == 0 then
-- Unpowered - go idle
--hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
meta:set_int("LV_EU_supply", 0)
meta:set_int("MV_EU_supply", 0)
meta:set_int("LV_EU_demand", 0)
meta:set_int("MV_EU_demand", max_mv_demand)
else
-- MV side has got power to spare
meta:set_string("infotext", machine_name.." is active (MV:"..max_mv_demand.."->LV:"..eu_input*mv_lv_factor..")");
meta:set_int("LV_EU_supply", eu_input*mv_lv_factor)
end
---------------------------------------------------
elseif upgrade == "LV-MV step up" and convert_LV_MV then
-- Register machine type
technic.register_LV_machine("technic:supply_converter","RE")
technic.register_MV_machine("technic:supply_converter","PR")
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
local eu_input = meta:get_int("LV_EU_input")
if eu_input == 0 then
-- Unpowered - go idle
--hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
meta:set_int("LV_EU_supply", 0)
meta:set_int("MV_EU_supply", 0)
meta:set_int("LV_EU_demand", max_lv_demand)
meta:set_int("MV_EU_demand", 0)
else
-- LV side has got power to spare
meta:set_string("infotext", machine_name.." is active (LV:"..max_lv_demand.."->MV:"..eu_input/lv_mv_factor..")");
meta:set_int("MV_EU_supply", eu_input/lv_mv_factor)
end
---------------------------------------------------
elseif upgrade == "HV-MV step down" and convert_HV_MV then
-- Register machine type
technic.register_MV_machine("technic:supply_converter","PR")
technic.register_HV_machine("technic:supply_converter","RE")
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "HV")
local eu_input = meta:get_int("HV_EU_input")
if eu_input == 0 then
-- Unpowered - go idle
--hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
meta:set_int("MV_EU_supply", 0)
meta:set_int("HV_EU_supply", 0)
meta:set_int("MV_EU_demand", 0)
meta:set_int("HV_EU_demand", max_hv_demand)
else
-- HV side has got power to spare
meta:set_string("infotext", machine_name.." is active (HV:"..max_hv_demand.."->MV:"..eu_input*hv_mv_factor..")");
meta:set_int("MV_EU_supply", eu_input*hv_mv_factor)
end
---------------------------------------------------
elseif upgrade == "MV-HV step up" and convert_MV_HV then
-- Register machine type
technic.register_MV_machine("technic:supply_converter","RE")
technic.register_HV_machine("technic:supply_converter","PR")
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "MV")
local eu_input = meta:get_int("MV_EU_input")
if eu_input == 0 then
-- Unpowered - go idle
--hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
meta:set_int("MV_EU_supply", 0)
meta:set_int("HV_EU_supply", 0)
meta:set_int("MV_EU_demand", max_mv_demand)
meta:set_int("HV_EU_demand", 0)
else
-- MV side has got power to spare
meta:set_string("infotext", machine_name.." is active (MV:"..max_mv_demand.."->HV:"..eu_input/mv_hv_factor..")");
meta:set_int("HV_EU_supply", eu_input/mv_hv_factor)
end
---------------------------------------------------
end
end,
})

View File

@ -0,0 +1,352 @@
-- SWITCHING STATION
-- The switching station is the center of all power distribution on an electric network.
-- The station will collect all produced power from producers (PR) and batteries (BA)
-- and distribute it to receivers (RE) and depleted batteries (BA).
--
-- It works like this:
-- All PR,BA,RE nodes are indexed and tagged with the switching station.
-- The tagging is to allow more stations to be built without allowing a cheat
-- with duplicating power.
-- All the RE nodes are queried for their current EU demand. Those which are off
-- would require no or a small standby EU demand, while those which are on would
-- require more.
-- If the total demand is less than the available power they are all updated with the
-- demand number.
-- If any surplus exists from the PR nodes the batteries will be charged evenly with this.
-- If the total demand requires draw on the batteries they will be discharged evenly.
--
-- If the total demand is more than the available power all RE nodes will be shut down.
-- We have a brown-out situation.
--
-- Hence all the power distribution logic resides in this single node.
--
-- Nodes connected to the network will have one or more of these parameters as meta data:
-- <LV|MV|HV>_EU_supply : Exists for PR and BA node types. This is the EU value supplied by the node. Output
-- <LV|MV|HV>_EU_demand : Exists for RE and BA node types. This is the EU value the node requires to run. Output
-- <LV|MV|HV>_EU_input : Exists for RE and BA node types. This is the actual EU value the network can give the node. Input
--
-- The reason the LV|MV|HV type is prepended toe meta data is because some machine could require several supplies to work.
-- This way the supplies are separated per network.
technic.DBG = 1
local dprint = technic.dprint
minetest.register_craft(
{
output = 'technic:switching_station 1',
recipe = {
{'technic:lv_transformer', 'technic:mv_transformer', 'technic:hv_transformer'},
{'technic:lv_transformer', 'technic:mv_transformer', 'technic:hv_transformer'},
{'technic:lv_cable', 'technic:mv_cable', 'technic:hv_cable'},
}
})
minetest.register_node(
"technic:switching_station",
{description = "Switching Station",
tiles = {"technic_mv_down_converter_top.png", "technic_mv_down_converter_bottom.png", "technic_mv_down_converter_side.png",
"technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png", "technic_mv_down_converter_side.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
drawtype = "nodebox",
paramtype = "light",
is_ground_content = true,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Switching Station")
-- minetest.chat_send_player(puncher:get_player_name(), "Switching station constructed. Punch the station to shut down the network.");
-- meta:set_int("active", 1)
end,
-- on_punch = function(pos, node, puncher)
-- local meta = minetest.env:get_meta(pos)
-- local active = meta:get_int("active")
-- if active == 1 then
-- meta:set_int("active", 0)
-- minetest.chat_send_player(puncher:get_player_name(), "Electrical network shut down. Punch again to turn it on.");
-- else
-- meta:set_int("active", 1)
-- minetest.chat_send_player(puncher:get_player_name(), "Electrical network turned on. Punch again to shut it down.");
-- end
-- end
})
--------------------------------------------------
-- Functions to help the machines on the electrical network
--------------------------------------------------
-- This one provides a timeout for a node in case it was disconnected from the network
-- A node must be touched by the station continuously in order to function
technic.switching_station_timeout_count = function(pos, machine_tier)
local meta = minetest.env:get_meta(pos)
timeout = meta:get_int(machine_tier.."_EU_timeout")
--print("Counting timeout "..timeout)
if timeout == 0 then
--print("OFF")
meta:set_int(machine_tier.."_EU_input", 0)
else
--print("ON")
meta:set_int(machine_tier.."_EU_timeout", timeout-1)
end
end
--------------------------------------------------
-- Functions to traverse the electrical network
--------------------------------------------------
-- Add a wire node to the LV/MV/HV network
local add_new_cable_node = function(nodes,pos)
local i = 1
repeat
if nodes[i]==nil then break end
if pos.x==nodes[i].x and pos.y==nodes[i].y and pos.z==nodes[i].z then return false end
i=i+1
until false
nodes[i] = {x=pos.x, y=pos.y, z=pos.z, visited=1} -- copy position
return true
end
-- Generic function to add found connected nodes to the right classification array
local check_node_subp = function(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos,machines,cablename)
local meta = minetest.env:get_meta(pos)
local name = minetest.env:get_node(pos).name
if meta:get_float(cablename)==1 then
add_new_cable_node(all_nodes,pos)
elseif machines[name] then
--dprint(name.." is a "..machines[name])
if machines[name] == "PR" then
add_new_cable_node(PR_nodes,pos)
elseif machines[name] == "RE" then
add_new_cable_node(RE_nodes,pos)
elseif machines[name] == "BA" then
add_new_cable_node(BA_nodes,pos)
end
if cablename == "cablelike" then
meta:set_int("LV_EU_timeout", 2) -- Touch node
elseif cablename == "mv_cablelike" then
meta:set_int("MV_EU_timeout", 2) -- Touch node
elseif cablename == "hv_cablelike" then
meta:set_int("HV_EU_timeout", 2) -- Touch node
end
end
end
-- Traverse a network given a list of machines and a cable type name
local traverse_network = function(PR_nodes,RE_nodes,BA_nodes,all_nodes, i, machines, cablename)
local pos = {x=all_nodes[i].x, y=all_nodes[i].y, z=all_nodes[i].z} -- copy position
pos.x=pos.x+1
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
pos.x=pos.x-2
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
pos.x=pos.x+1
pos.y=pos.y+1
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
pos.y=pos.y-2
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
pos.y=pos.y+1
pos.z=pos.z+1
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
pos.z=pos.z-2
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
pos.z=pos.z+1
end
----------------------------------------------
-- The action code for the switching station
----------------------------------------------
minetest.register_abm(
{nodenames = {"technic:switching_station"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local meta1 = nil
local pos1 = {}
local PR_EU = 0 -- EUs from PR nodes
local BA_PR_EU = 0 -- EUs from BA nodes (discharching)
local BA_RE_EU = 0 -- EUs to BA nodes (charging)
local RE_EU = 0 -- EUs to RE nodes
local network = ""
local all_nodes = {}
local PR_nodes = {}
local BA_nodes = {}
local RE_nodes = {}
-- -- Possible to turn off the entire network
-- if meta:get_int("active") == 0 then
-- for _,pos1 in pairs(RE_nodes) do
-- meta1 = minetest.env:get_meta(pos1)
-- meta1:set_int("EU_input", 0)
-- end
-- for _,pos1 in pairs(BA_nodes) do
-- meta1 = minetest.env:get_meta(pos1)
-- meta1:set_int("EU_input", 0)
-- end
-- return
-- end
-- Which kind of network are we on:
pos1 = {x=pos.x, y=pos.y-1, z=pos.z}
all_nodes[1] = pos1
meta1 = minetest.env:get_meta(pos1)
if meta1:get_float("cablelike") ==1 then
-- LV type
--dprint("LV type")
network = "LV"
local table_index = 1
repeat
traverse_network(PR_nodes,RE_nodes,BA_nodes,all_nodes,table_index, technic.LV_machines, "cablelike")
table_index = table_index + 1
if all_nodes[table_index] == nil then break end
until false
elseif meta1:get_float("mv_cablelike") ==1 then
-- MV type
--dprint("MV type")
network = "MV"
local table_index = 1
repeat
traverse_network(PR_nodes,RE_nodes,BA_nodes,all_nodes,table_index, technic.MV_machines, "mv_cablelike")
table_index = table_index + 1
if all_nodes[table_index] == nil then break end
until false
elseif meta1:get_float("hv_cablelike") ==1 then
-- HV type
--dprint("HV type")
network = "HV"
local table_index = 1
repeat
traverse_network(PR_nodes,RE_nodes,BA_nodes,all_nodes,table_index, technic.HV_machines, "hv_cablelike")
table_index = table_index + 1
if all_nodes[table_index] == nil then break end
until false
else
-- No type :-)
--dprint("Not connected to a network")
meta:set_string("infotext", "Switching Station - no network")
return
end
--dprint("nodes="..table.getn(all_nodes).." PR="..table.getn(PR_nodes).." BA="..table.getn(BA_nodes).." RE="..table.getn(RE_nodes))
-- Strings for the meta data
local eu_demand_str = network.."_EU_demand"
local eu_input_str = network.."_EU_input"
local eu_supply_str = network.."_EU_supply"
local eu_from_fuel_str = network.."_EU_from_fuel"
-- Get all the power from the PR nodes
local PR_eu_supply = 0 -- Total power
for _,pos1 in pairs(PR_nodes) do
meta1 = minetest.env:get_meta(pos1)
PR_eu_supply = PR_eu_supply + meta1:get_int(eu_supply_str)
end
--dprint("Total PR supply:"..PR_eu_supply)
-- Get all the demand from the RE nodes
local RE_eu_demand = 0
for _,pos1 in pairs(RE_nodes) do
meta1 = minetest.env:get_meta(pos1)
RE_eu_demand = RE_eu_demand + meta1:get_int(eu_demand_str)
end
--dprint("Total RE demand:"..RE_eu_demand)
-- Get all the power from the BA nodes
local BA_eu_supply = 0
for _,pos1 in pairs(BA_nodes) do
meta1 = minetest.env:get_meta(pos1)
BA_eu_supply = BA_eu_supply + meta1:get_int(eu_supply_str)
end
--dprint("Total BA supply:"..BA_eu_supply)
-- Get all the demand from the BA nodes
local BA_eu_demand = 0
for _,pos1 in pairs(BA_nodes) do
meta1 = minetest.env:get_meta(pos1)
BA_eu_demand = BA_eu_demand + meta1:get_int(eu_demand_str)
end
--dprint("Total BA demand:"..BA_eu_demand)
meta:set_string("infotext", "Switching Station. PR("..(PR_eu_supply+BA_eu_supply)..") RE("..(RE_eu_demand+BA_eu_demand)..")")
-- If the PR supply is enough for the RE demand supply them all
if PR_eu_supply >= RE_eu_demand then
--dprint("PR_eu_supply"..PR_eu_supply.." >= RE_eu_demand"..RE_eu_demand)
for _,pos1 in pairs(RE_nodes) do
meta1 = minetest.env:get_meta(pos1)
local eu_demand = meta1:get_int(eu_demand_str)
meta1:set_int(eu_input_str, eu_demand)
end
-- We have a surplus, so distribute the rest equally to the BA nodes
-- Let's calculate the factor of the demand
PR_eu_supply = PR_eu_supply - RE_eu_demand
local charge_factor = 0 -- Assume all batteries fully charged
if BA_eu_demand > 0 then
charge_factor = PR_eu_supply / BA_eu_demand
end
for n,pos1 in pairs(BA_nodes) do
meta1 = minetest.env:get_meta(pos1)
local eu_demand = meta1:get_int(eu_demand_str)
meta1:set_int(eu_input_str, math.floor(eu_demand*charge_factor))
--dprint("Charging battery:"..math.floor(eu_demand*charge_factor))
end
-- If still a surplus we can start giving back to the fuel burning generators
-- Only full EU packages are given back. The rest is wasted.
if BA_eu_demand == 0 then
for _,pos1 in pairs(PR_nodes) do
meta1 = minetest.env:get_meta(pos1)
if meta1:get_int(eu_from_fuel_str) == 1 then
local eu_supply = meta1:get_int(eu_supply_str)
if PR_eu_supply < eu_supply then
break
else
-- Set the supply to 0 if we did not require it.
meta1:set_int(eu_supply_str, 0)
PR_eu_supply = PR_eu_supply - eu_supply
end
end
end
end
return
end
-- If the PR supply is not enough for the RE demand we will discharge the batteries too
if PR_eu_supply+BA_eu_supply >= RE_eu_demand then
--dprint("PR_eu_supply "..PR_eu_supply.."+BA_eu_supply "..BA_eu_supply.." >= RE_eu_demand"..RE_eu_demand)
for _,pos1 in pairs(RE_nodes) do
meta1 = minetest.env:get_meta(pos1)
local eu_demand = meta1:get_int(eu_demand_str)
meta1:set_int(eu_input_str, eu_demand)
end
-- We have a deficit, so distribute to the BA nodes
-- Let's calculate the factor of the supply
local charge_factor = 0 -- Assume all batteries depleted
if BA_eu_supply > 0 then
charge_factor = (PR_eu_supply - RE_eu_demand) / BA_eu_supply
end
for n,pos1 in pairs(BA_nodes) do
meta1 = minetest.env:get_meta(pos1)
local eu_supply = meta1:get_int(eu_supply_str)
meta1:set_int(eu_input_str, math.floor(eu_supply*charge_factor))
--dprint("Discharging battery:"..math.floor(eu_supply*charge_factor))
end
return
end
-- If the PR+BA supply is not enough for the RE demand: Shut everything down!
-- Note: another behaviour could also be imagined: provide the average power for all and let the node decide what happens.
-- This is much simpler though: Not enough power for all==no power for all
--print("NO POWER")
for _,pos1 in pairs(RE_nodes) do
meta1 = minetest.env:get_meta(pos1)
meta1:set_int(eu_input_str, 0)
end
end,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 258 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 261 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 350 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 353 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 352 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 264 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 475 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 478 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 225 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 330 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 633 B

View File

@ -1,3 +1,5 @@
-- LV Tool workshop
-- This machine repairs tools.
minetest.register_alias("tool_workshop", "technic:tool_workshop") minetest.register_alias("tool_workshop", "technic:tool_workshop")
minetest.register_craft({ minetest.register_craft({
output = 'technic:tool_workshop', output = 'technic:tool_workshop',
@ -13,88 +15,108 @@ minetest.register_craftitem("technic:tool_workshop", {
stack_max = 99, stack_max = 99,
}) })
workshop_formspec = local workshop_formspec =
"invsize[8,9;]".. "invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "list[current_name;src;3,1;1,1;]"..
"list[current_name;src;3,1;1,1;]".. "label[0,0;Tool Workshop]"..
"label[0,0;Tool Workshop]".. "list[current_player;main;0,5;8,4;]"
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:tool_workshop", { minetest.register_node(
description = "Tool Workshop", "technic:tool_workshop",
tiles = {"technic_workshop_top.png", "technic_machine_bottom.png", "technic_workshop_side.png", {
"technic_workshop_side.png", "technic_workshop_side.png", "technic_workshop_side.png"}, description = "Tool Workshop",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, tiles = {"technic_workshop_top.png", "technic_machine_bottom.png", "technic_workshop_side.png",
sounds = default.node_sound_wood_defaults(), "technic_workshop_side.png", "technic_workshop_side.png", "technic_workshop_side.png"},
technic_power_machine=1, groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
internal_EU_buffer=0; sounds = default.node_sound_wood_defaults(),
internal_EU_buffer_size=2000; on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
on_construct = function(pos) meta:set_string("infotext", "Tool Workshop")
local meta = minetest.env:get_meta(pos) meta:set_float("technic_power_machine", 1)
meta:set_string("infotext", "Tool Workshop") meta:set_string("formspec", workshop_formspec)
meta:set_float("technic_power_machine", 1) local inv = meta:get_inventory()
meta:set_float("internal_EU_buffer", 1) inv:set_size("src", 1)
meta:set_float("internal_EU_buffer_size", 2000) end,
meta:set_string("formspec", workshop_formspec) can_dig = function(pos,player)
local inv = meta:get_inventory() local meta = minetest.env:get_meta(pos);
inv:set_size("src", 1) local inv = meta:get_inventory()
if not inv:is_empty("src") then
minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
return false
end
return true
end, 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_abm({ minetest.register_abm(
nodenames = {"technic:tool_workshop"}, { nodenames = {"technic:tool_workshop"},
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.env:get_meta(pos) local meta = minetest.env:get_meta(pos)
local charge= meta:get_float("internal_EU_buffer") local eu_input = meta:get_int("LV_EU_input")
local max_charge= meta:get_float("internal_EU_buffer_size") local state = meta:get_int("state")
local load_step=2000 local next_state = state
local load_cost=200
local inv = meta:get_inventory()
if inv:is_empty("src")==false then
srcstack = inv:get_stack("src", 1)
src_item=srcstack:to_table()
if (src_item["name"]=="technic:water_can" or src_item["name"]=="technic:lava_can") then
load_step=0
load_cost=0
end
local load1=tonumber((src_item["wear"]))
if charge>load_cost then
if load1>1 then
if load1-load_step<0 then load_step=load1 load1=1
else load1=load1-load_step end
charge=charge-load_cost
src_item["wear"]=tostring(load1)
inv:set_stack("src", 1, src_item)
end
end
end
meta:set_float("internal_EU_buffer",charge) -- Machine information
local machine_name = "Tool Workshop"
local machine_node = "technic:tool_workshop"
local machine_state_demand = { 50, 150 }
-- Setup meta data if it does not exist. state is used as an indicator of this
if state == 0 then
meta:set_int("state", 1)
meta:set_int("LV_EU_demand", machine_state_demand[1])
meta:set_int("LV_EU_input", 0)
return
end
local load = math.floor((charge/max_charge)*100) -- Power off automatically if no longer connected to a switching station
meta:set_string("formspec", technic.switching_station_timeout_count(pos, "LV")
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"..
"list[current_name;src;3,1;1,1;]"..
"label[0,0;Tool Workshop]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]")
end
})
register_LV_machine ("technic:tool_workshop","RE") -- State machine
if eu_input == 0 then
-- Unpowered - go idle
--hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
next_state = 1
elseif eu_input == machine_state_demand[state] then
-- Powered - do the state specific actions
local inv = meta:get_inventory()
if state == 1 then
--hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
if not inv:is_empty("src") then
next_state = 2
end
elseif state == 2 then
--hacky_swap_node(pos, machine_node.."_active")
meta:set_string("infotext", machine_name.." Active")
if inv:is_empty("src") then
next_state = 1
else
srcstack = inv:get_stack("src", 1)
src_item=srcstack:to_table()
-- Cannot charge cans
if (src_item["name"]=="technic:water_can" or src_item["name"]=="technic:lava_can") then
return
end
local wear=tonumber(src_item["wear"])
wear = math.max(1, wear-2000) -- Improve the tool this much every tick
src_item["wear"]=tostring(wear)
inv:set_stack("src", 1, src_item)
end
end
end
-- Change state?
if next_state ~= state then
meta:set_int("LV_EU_demand", machine_state_demand[next_state])
meta:set_int("state", next_state)
end
end
})
technic.register_LV_machine ("technic:tool_workshop","RE")

View File

@ -1,3 +1,6 @@
-- A water mill produces LV EUs by exploiting flowing water across it
-- It is a LV EU supplyer and fairly low yield (max 120EUs)
-- It is a little under half as good as the thermal generator.
minetest.register_alias("water_mill", "technic:water_mill") minetest.register_alias("water_mill", "technic:water_mill")
minetest.register_craft({ minetest.register_craft({
@ -14,7 +17,7 @@ minetest.register_craftitem("technic:water_mill", {
stack_max = 99, stack_max = 99,
}) })
water_mill_formspec = local water_mill_formspec =
"invsize[8,4;]".. "invsize[8,4;]"..
"image[1,1;1,2;technic_power_meter_bg.png]".. "image[1,1;1,2;technic_power_meter_bg.png]"..
"label[0,0;Water Mill]".. "label[0,0;Water Mill]"..
@ -22,110 +25,98 @@ water_mill_formspec =
"list[current_player;main;0,5;8,4;]" "list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:water_mill", { minetest.register_node(
description = "Water Mill", "technic:water_mill",
tiles = {"technic_water_mill_top.png", "technic_machine_bottom.png", "technic_water_mill_side.png", {
"technic_water_mill_side.png", "technic_water_mill_side.png", "technic_water_mill_side.png"}, description = "Water Mill",
paramtype2 = "facedir", tiles = {"technic_water_mill_top.png", "technic_machine_bottom.png", "technic_water_mill_side.png",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}, "technic_water_mill_side.png", "technic_water_mill_side.png", "technic_water_mill_side.png"},
legacy_facedir_simple = true, paramtype2 = "facedir",
sounds = default.node_sound_wood_defaults(), groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
technic_power_machine=1, legacy_facedir_simple = true,
internal_EU_buffer=0; sounds = default.node_sound_wood_defaults(),
internal_EU_buffer_size=5000; on_construct = function(pos)
burn_time=0; local meta = minetest.env:get_meta(pos)
on_construct = function(pos) meta:set_string("infotext", "Water Mill")
local meta = minetest.env:get_meta(pos) meta:set_float("technic_power_machine", 1)
meta:set_string("infotext", "Water Mill") meta:set_int("LV_EU_supply", 0)
meta:set_float("technic_power_machine", 1) meta:set_string("formspec", water_mill_formspec)
meta:set_float("internal_EU_buffer", 0) end,
meta:set_float("internal_EU_buffer_size", 3000) })
meta:set_string("formspec", water_mill_formspec)
end,
minetest.register_node(
"technic:water_mill_active",
{
description = "Water Mill",
tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png", "technic_water_mill_side.png",
"technic_water_mill_side.png", "technic_water_mill_side.png", "technic_water_mill_side.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:water_mill",
}) })
minetest.register_node("technic:water_mill_active", { local check_node_around_mill = function(pos)
description = "Water Mill", local node=minetest.env:get_node(pos)
tiles = {"technic_water_mill_top_active.png", "technic_machine_bottom.png", "technic_water_mill_side.png", if node.name=="default:water_flowing" then return 1 end
"technic_water_mill_side.png", "technic_water_mill_side.png", "technic_water_mill_side.png"}, return 0
paramtype2 = "facedir", end
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:water_mill",
technic_power_machine=1,
internal_EU_buffer=0;
internal_EU_buffer_size=0;
})
minetest.register_abm({ minetest.register_abm(
nodenames = {"technic:water_mill","technic:water_mill_active"}, {
interval = 1, nodenames = {"technic:water_mill","technic:water_mill_active"},
chance = 1, interval = 1,
action = function(pos, node, active_object_count, active_object_count_wider) chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local water_nodes = 0
local lava_nodes = 0
local production_level = 0
local eu_supply = 0
local meta = minetest.env:get_meta(pos) pos.x=pos.x+1
local charge= meta:get_float("internal_EU_buffer") local check=check_node_around_mill (pos)
local max_charge= meta:get_float("internal_EU_buffer_size") if check==1 then water_nodes=water_nodes+1 end
local water_nodes = 0 pos.x=pos.x-2
local lava_nodes = 0 check=check_node_around_mill (pos)
local production_level=0 if check==1 then water_nodes=water_nodes+1 end
local load_step=0 pos.x=pos.x+1
pos.z=pos.z+1
check=check_node_around_mill (pos)
if check==1 then water_nodes=water_nodes+1 end
pos.z=pos.z-2
check=check_node_around_mill (pos)
if check==1 then water_nodes=water_nodes+1 end
pos.z=pos.z+1
pos.x=pos.x+1 if water_nodes==1 then production_level = 25; eu_supply = 30 end
local check=check_node_around_mill (pos) if water_nodes==2 then production_level = 50; eu_supply = 60 end
if check==1 then water_nodes=water_nodes+1 end if water_nodes==3 then production_level = 75; eu_supply = 90 end
pos.x=pos.x-2 if water_nodes==4 then production_level = 100; eu_supply = 120 end
check=check_node_around_mill (pos)
if check==1 then water_nodes=water_nodes+1 end
pos.x=pos.x+1
pos.z=pos.z+1
check=check_node_around_mill (pos)
if check==1 then water_nodes=water_nodes+1 end
pos.z=pos.z-2
check=check_node_around_mill (pos)
if check==1 then water_nodes=water_nodes+1 end
pos.z=pos.z+1
if water_nodes==1 then production_level=25 load_step=30 end if production_level>0 then
if water_nodes==2 then production_level=50 load_step=60 end meta:set_int("LV_EU_supply", eu_supply)
if water_nodes==3 then production_level=75 load_step=90 end end
if water_nodes==4 then production_level=100 load_step=120 end
if production_level>0 then local load = 1 -- math.floor((charge/max_charge)*100)
if charge+load_step>max_charge then meta:set_string("formspec",
load_step=max_charge-charge "invsize[8,4;]"..
end "image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
if load_step>0 then (load)..":technic_power_meter_fg.png]"..
charge=charge+load_step "label[0,0;Water Mill]"..
meta:set_float("internal_EU_buffer",charge) "label[1,3;Power level]"..
end "label[4,0;Production at "..tostring(production_level).."%]"
end )
local load = math.floor((charge/max_charge)*100) if production_level>0 and minetest.env:get_node(pos).name=="technic:water_mill" then
meta:set_string("formspec", hacky_swap_node (pos,"technic:water_mill_active")
"invsize[8,4;]".. meta:set_int("LV_EU_supply", 0)
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:".. return
(load)..":technic_power_meter_fg.png]".. end
"label[0,0;Water Mill]".. if production_level==0 then hacky_swap_node (pos,"technic:water_mill") end
"label[1,3;Power level]".. end
"label[4,0;Production at "..tostring(production_level).."%]" })
)
if production_level>0 and minetest.env:get_node(pos).name=="technic:water_mill" then technic.register_LV_machine ("technic:water_mill","PR")
hacky_swap_node (pos,"technic:water_mill_active") technic.register_LV_machine ("technic:water_mill_active","PR")
return
end
if production_level==0 then hacky_swap_node (pos,"technic:water_mill") end
end
})
function check_node_around_mill (pos)
local node=minetest.env:get_node(pos)
if node.name=="default:water_flowing" then return 1 end
return 0
end
register_LV_machine ("technic:water_mill","PR")
register_LV_machine ("technic:water_mill_active","PR")