Partial rewrite

This commit is contained in:
ShadowNinja 2013-07-17 15:34:35 -04:00
parent 48ea6fb99d
commit ee0765804c
123 changed files with 5513 additions and 8341 deletions

View File

@ -1,6 +1,15 @@
--Minetest 0.4.7 mod: concrete
--(c) 2013 by RealBadAngel <mk@realbadangel.pl>
local technic = technic or {}
technic.concrete_posts = {}
minetest.register_alias("technic:concrete_post", "technic:concrete_post0")
minetest.register_alias("technic:concrete_post32", "technic:concrete_post12")
minetest.register_alias("technic:concrete_post33", "technic:concrete_post3")
minetest.register_alias("technic:concrete_post34", "technic:concrete_post28")
minetest.register_alias("technic:concrete_post35", "technic:concrete_post19")
minetest.register_craft({
output = 'technic:rebar 6',
recipe = {
@ -22,12 +31,12 @@ minetest.register_craft({
minetest.register_craft({
output = 'technic:concrete_post_platform 6',
recipe = {
{'technic:concrete','technic:concrete_post','technic:concrete'},
{'technic:concrete','technic:concrete_post0','technic:concrete'},
}
})
minetest.register_craft({
output = 'technic:concrete_post 12',
output = 'technic:concrete_post0 12',
recipe = {
{'default:stone','technic:rebar','default:stone'},
{'default:stone','technic:rebar','default:stone'},
@ -44,500 +53,195 @@ minetest.register_craft({
}
})
platform_box = {-0.5 , 0.3 , -0.5 , 0.5 , 0.5 , 0.5 }
post_str_y={ -0.15 , -0.5 , -0.15 , 0.15 , 0.5 , 0.15 }
post_str_x1={ 0 , -0.3 , -0.1, 0.5 , 0.3 , 0.1 } -- x+
post_str_z1={ -0.1 , -0.3 , 0, 0.1 , 0.3 , 0.5 } -- z+
post_str_x2={ 0 , -0.3 , -0.1, -0.5 , 0.3 , 0.1 } -- x-
post_str_z2={ -0.1 , -0.3 , 0, 0.1 , 0.3 , -0.5 } -- z-
local box_platform = {-0.5, 0.3, -0.5, 0.5, 0.5, 0.5}
local box_center = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15}
local box_x1 = {0, -0.3, -0.1, 0.5, 0.3, 0.1}
local box_z1 = {-0.1, -0.3, 0, 0.1, 0.3, 0.5}
local box_x2 = {0, -0.3, -0.1, -0.5, 0.3, 0.1}
local box_z2 = {-0.1, -0.3, 0, 0.1, 0.3, -0.5}
minetest.register_craftitem(":technic:rebar", {
description = "Rebar",
inventory_image = "technic_rebar.png",
stack_max = 99,
})
minetest.register_craftitem(":technic:blast_resistant_concrete", {
description = "Blast-resistant Concrete Block",
inventory_image = "technic_blast_resistant_concrete_block.png",
stack_max = 99,
})
minetest.register_craftitem(":technic:concrete", {
description = "Concrete Block",
inventory_image = "technic_concrete_block.png",
stack_max = 99,
})
minetest.register_craftitem(":technic:concrete_post", {
description = "Concrete Post",
stack_max = 99,
})
minetest.register_craftitem(":technic:concrete_post_platform", {
description = "Concrete Post Platform",
stack_max = 99,
})
minetest.register_node(":technic:concrete", {
description = "Concrete Block",
tile_images = {"technic_concrete_block.png",},
is_ground_content = true,
groups={cracky=1,level=2},
groups = {cracky=1, level=2, concrete=1},
sounds = default.node_sound_stone_defaults(),
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
on_construct = function(pos)
meta=minetest.env:get_meta(pos)
meta:set_float("postlike",1)
check_post_connections (pos,1)
after_place_node = function(pos, placer, itemstack)
technic.update_posts(pos, false)
end,
after_dig_node = function (pos, oldnode, oldmetadata, digger)
check_post_connections (pos,0)
technic.update_posts(pos, false)
end,
})
minetest.register_node(":technic:blast_resistant_concrete", {
description = "Blast-resistant Concrete Block",
tile_images = {"technic_blast_resistant_concrete_block.png",},
is_ground_content = true,
groups={cracky=1,level=3},
groups={cracky=1, level=3, concrete=1},
sounds = default.node_sound_stone_defaults(),
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
on_construct = function(pos)
meta=minetest.env:get_meta(pos)
meta:set_float("postlike",1)
check_post_connections (pos,1)
after_place_node = function(pos, player, itemstack)
technic.update_posts(pos, false)
end,
after_dig_node = function (pos, oldnode, oldmetadata, digger)
check_post_connections (pos,0)
technic.update_posts(pos, false)
end,
})
minetest.register_node(":technic:concrete_post_platform", {
description = "Concrete Post Platform",
tile_images = {"technic_concrete_block.png",},
is_ground_content = true,
groups={cracky=1,level=2},
groups={cracky=1, level=2},
sounds = default.node_sound_stone_defaults(),
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {platform_box}
},
node_box = {
type = "fixed",
fixed = {platform_box}
},
on_place=function (itemstack, placer, pointed_thing)
local node=minetest.env:get_node(pointed_thing.under)
if minetest.get_item_group(node.name, "concrete_post")==0 then
return minetest.item_place_node(itemstack, placer, pointed_thing)
fixed = {box_platform}
},
on_place = function (itemstack, placer, pointed_thing)
local node = minetest.get_node(pointed_thing.under)
if not technic.concrete_posts[node.name] then
return minetest.item_place_node(itemstack, placer, pointed_thing)
end
local links = technic.concrete_posts[node.name]
if links[5] ~= 0 then -- The post already has a platform
return minetest.item_place_node(itemstack, placer, pointed_thing)
end
local id = technic.get_post_id({links[1], links[2], links[3], links[4], 1})
minetest.set_node(pointed_thing.under, {name="technic:concrete_post"..id})
itemstack:take_item()
placer:set_wielded_item(itemstack)
return itemstack
end,
})
local function gen_post_nodebox(x1, x2, z1, z2, platform)
local box = {box_center}
if x1 ~= 0 then
table.insert(box, box_x1)
end
local meta=minetest.env:get_meta(pointed_thing.under)
y1=meta:get_float("y1")
platform=meta:get_float("platform")
if y1==1 or platform==1 then
return minetest.item_place_node(itemstack, placer, pointed_thing)
if x2 ~= 0 then
table.insert(box, box_x2)
end
y2=meta:get_float("y2")
x1=meta:get_float("x1")
x2=meta:get_float("x2")
z1=meta:get_float("z1")
z2=meta:get_float("z2")
rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,1)
meta:set_float("platform",1)
hacky_swap_posts(pointed_thing.under,"technic:concrete_post"..rule)
itemstack:take_item()
placer:set_wielded_item(itemstack)
return itemstack
end,
})
if z1 ~= 0 then
table.insert(box, box_z1)
end
if z2 ~= 0 then
table.insert(box, box_z2)
end
if platform ~= 0 then
table.insert(box, box_platform)
end
return box
end
local function dig_post_with_platform(pos, oldnode, oldmetadata)
oldnode.name = "technic:concrete_post0"
minetest.set_node(pos, oldnode)
technic.update_posts(pos, true)
end
minetest.register_node(":technic:concrete_post", {
description = "Concrete Post",
tiles = {"technic_concrete_block.png"},
groups={cracky=1,level=2,concrete_post=1},
sounds = default.node_sound_stone_defaults(),
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = { -0.15 , -0.5 , -0.15 , 0.15 , 0.5 , 0.15 }},
node_box = {
type = "fixed",
fixed = {-0.15 , -0.5 , -0.15 , 0.15 , 0.5 , 0.15 }},
on_construct = function(pos)
meta=minetest.env:get_meta(pos)
meta:set_int("postlike",1)
meta:set_int("platform",0)
meta:set_int("x1",0)
meta:set_int("x2",0)
meta:set_int("y1",0)
meta:set_int("y2",0)
meta:set_int("z1",0)
meta:set_int("z2",0)
check_post_connections (pos,1)
end,
after_dig_node = function (pos, oldnode, oldmetadata, digger)
check_post_connections (pos,0)
end,
})
local x1,x2,y1,z1,z2
local count=0
for x1 = 0, 1, 1 do --x-
for x2 = 0, 1, 1 do --x+
for z1 = 0, 1, 1 do --z-
for z2 = 0, 1, 1 do --z+
temp_x1={} temp_x2={} temp_z1={} temp_z2={}
if x1==1 then temp_x1=post_str_x1 end
if x2==1 then temp_x2=post_str_x2 end
if z1==1 then temp_z1=post_str_z1 end
if z2==1 then temp_z2=post_str_z2 end
minetest.register_node(":technic:concrete_post"..count, {
description = "Concrete Post",
tiles = {"technic_concrete_block.png"},
groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
sounds = default.node_sound_stone_defaults(),
drop = "technic:concrete_post",
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {
temp_x1,temp_x2,post_str_y,temp_z1,temp_z2,
}},
node_box = {
type = "fixed",
fixed = {
temp_x1,temp_x2,post_str_y,temp_z1,temp_z2,
}},
after_dig_node = function (pos, oldnode, oldmetadata, digger)
check_post_connections (pos,0)
end,
})
minetest.register_node(":technic:concrete_post"..count+16, {
description = "Concrete Post",
tiles = {"technic_concrete_block.png"},
groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
sounds = default.node_sound_stone_defaults(),
drop = "technic:concrete_post_platform",
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {
platform_box,temp_x1,temp_x2,post_str_y,temp_z1,temp_z2,
}},
node_box = {
type = "fixed",
fixed = {
platform_box,temp_x1,temp_x2,post_str_y,temp_z1,temp_z2,
}},
after_dig_node = function (pos, oldnode, oldmetadata, digger)
dig_post_with_platform (pos,oldnode,oldmetadata)
end,
})
count=count+1 end end end end
minetest.register_node(":technic:concrete_post32", {
description = "Concrete Post",
tiles = {"technic_concrete_block.png"},
groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
sounds = default.node_sound_stone_defaults(),
drop = "technic:concrete_post",
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {-0.5,-0.3,-0.1,0.5,0.3,0.1},
},
node_box = {
type = "fixed",
fixed = {
post_str_x1,post_str_x2,
}},
after_dig_node = function (pos, oldnode, oldmetadata, digger)
check_post_connections (pos,0)
end,
})
minetest.register_node(":technic:concrete_post33", {
description = "Concrete Post",
tiles = {"technic_concrete_block.png"},
groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
sounds = default.node_sound_stone_defaults(),
drop = "technic:concrete_post",
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {
post_str_z1,post_str_z2,
}},
node_box = {
type = "fixed",
fixed = {
post_str_z1,post_str_z2,
}},
after_dig_node = function (pos, oldnode, oldmetadata, digger)
check_post_connections (pos,0)
end,
})
minetest.register_node(":technic:concrete_post34", {
description = "Concrete Post",
tiles = {"technic_concrete_block.png"},
groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
sounds = default.node_sound_stone_defaults(),
drop = "technic:concrete_post_platform",
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {
platform_box,post_str_x1,post_str_x2,
}},
node_box = {
type = "fixed",
fixed = {
platform_box,post_str_x1,post_str_x2,
}},
after_dig_node = function (pos, oldnode, oldmetadata, digger)
dig_post_with_platform (pos,oldnode,oldmetadata)
end,
})
minetest.register_node(":technic:concrete_post35", {
description = "Concrete Post",
tiles = {"technic_concrete_block.png"},
groups={cracky=1,level=2,not_in_creative_inventory=1,concrete_post=1},
sounds = default.node_sound_stone_defaults(),
drop = "technic:concrete_post_platform",
paramtype = "light",
light_source = 0,
sunlight_propagates = true,
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {
platform_box,post_str_z1,post_str_z2,
}},
node_box = {
type = "fixed",
fixed = {
platform_box,post_str_z1,post_str_z2,
}},
after_dig_node = function (pos, oldnode, oldmetadata, digger)
dig_post_with_platform (pos,oldnode,oldmetadata)
end,
})
dig_post_with_platform = function (pos,oldnode,oldmetadata)
x1=tonumber(oldmetadata.fields["x1"])
x2=tonumber(oldmetadata.fields["x2"])
y1=tonumber(oldmetadata.fields["y1"])
y2=tonumber(oldmetadata.fields["y2"])
z1=tonumber(oldmetadata.fields["z1"])
z2=tonumber(oldmetadata.fields["z2"])
print(dump(x1))
oldmetadata.fields["platform"]="0"
local rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,0)
--print(dump(rule))
oldnode.name="technic:concrete_post"..rule
minetest.env:set_node(pos,oldnode)
meta = minetest.env:get_meta(pos)
meta:from_table(oldmetadata)
end
check_post_connections = function(pos,mode)
local pos1={}
pos1.x=pos.x
pos1.y=pos.y
pos1.z=pos.z
tempx1=0
tempx2=0
tempy1=0
tempy2=0
tempz1=0
tempz2=0
pos1.x=pos1.x+1
if minetest.env:get_meta(pos1):get_int("postlike")==1 then
x2=mode
x1=minetest.env:get_meta(pos1):get_int("x1")
y1=minetest.env:get_meta(pos1):get_int("y1")
y2=minetest.env:get_meta(pos1):get_int("y2")
z1=minetest.env:get_meta(pos1):get_int("z1")
z2=minetest.env:get_meta(pos1):get_int("z2")
platform=minetest.env:get_meta(pos1):get_int("platform")
rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
hacky_swap_posts(pos1,"technic:concrete_post"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_int("x2",x2)
tempx1=mode
end
pos1.x=pos1.x-2
if minetest.env:get_meta(pos1):get_int("postlike")==1 then
x1=mode
x2=minetest.env:get_meta(pos1):get_int("x2")
y1=minetest.env:get_meta(pos1):get_int("y1")
y2=minetest.env:get_meta(pos1):get_int("y2")
z1=minetest.env:get_meta(pos1):get_int("z1")
z2=minetest.env:get_meta(pos1):get_int("z2")
platform=minetest.env:get_meta(pos1):get_int("platform")
rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
hacky_swap_posts(pos1,"technic:concrete_post"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_int("x1",x1)
tempx2=mode
end
pos1.x=pos1.x+1
pos1.y=pos1.y+1
if minetest.env:get_meta(pos1):get_int("postlike")==1 then
y2=mode
x1=minetest.env:get_meta(pos1):get_int("x1")
x2=minetest.env:get_meta(pos1):get_int("x2")
y1=minetest.env:get_meta(pos1):get_int("y1")
z1=minetest.env:get_meta(pos1):get_int("z1")
z2=minetest.env:get_meta(pos1):get_int("z2")
platform=minetest.env:get_meta(pos1):get_int("platform")
rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
hacky_swap_posts(pos1,"technic:concrete_post"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_int("y2",y2)
tempy1=mode
end
pos1.y=pos1.y-2
if minetest.env:get_meta(pos1):get_int("postlike")==1 then
y1=mode
x1=minetest.env:get_meta(pos1):get_int("x1")
x2=minetest.env:get_meta(pos1):get_int("x2")
y2=minetest.env:get_meta(pos1):get_int("y2")
z1=minetest.env:get_meta(pos1):get_int("z1")
z2=minetest.env:get_meta(pos1):get_int("z2")
platform=minetest.env:get_meta(pos1):get_int("platform")
rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
hacky_swap_posts(pos1,"technic:concrete_post"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_int("y1",y1)
tempy2=mode
end
pos1.y=pos1.y+1
pos1.z=pos1.z+1
if minetest.env:get_meta(pos1):get_int("postlike")==1 then
z2=mode
x1=minetest.env:get_meta(pos1):get_int("x1")
x2=minetest.env:get_meta(pos1):get_int("x2")
y1=minetest.env:get_meta(pos1):get_int("y1")
y2=minetest.env:get_meta(pos1):get_int("y2")
z1=minetest.env:get_meta(pos1):get_int("z1")
platform=minetest.env:get_meta(pos1):get_int("platform")
rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
hacky_swap_posts(pos1,"technic:concrete_post"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_int("z2",z2)
tempz1=mode
end
pos1.z=pos1.z-2
if minetest.env:get_meta(pos1):get_int("postlike")==1 then
z1=mode
x1=minetest.env:get_meta(pos1):get_int("x1")
x2=minetest.env:get_meta(pos1):get_int("x2")
y1=minetest.env:get_meta(pos1):get_int("y1")
y2=minetest.env:get_meta(pos1):get_int("y2")
z2=minetest.env:get_meta(pos1):get_int("z2")
platform=minetest.env:get_meta(pos1):get_int("platform")
rule=make_post_rule_number(x1,x2,y1,y2,z1,z2,platform)
hacky_swap_posts(pos1,"technic:concrete_post"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_int("z1",z1)
tempz2=mode
end
pos1.z=pos1.z+1
if mode==1 then
meta=minetest.env:get_meta(pos)
meta:set_int("x1",tempx1)
meta:set_int("x2",tempx2)
meta:set_int("y1",tempy1)
meta:set_int("y2",tempy2)
meta:set_int("z1",tempz1)
meta:set_int("z2",tempz2)
rule=make_post_rule_number(tempx1,tempx2,tempy1,tempy2,tempz1,tempz2,0)
hacky_swap_posts(pos,"technic:concrete_post"..rule)
end
end
function make_post_rule_number (x1,x2,y1,y2,z1,z2,platform)
local tempy=y1+y2
local tempx=x1+x2
local tempz=z1+z2
if platform==0 then
if tempy==0 and tempx==0 and tempz==0 then return 0 end
if x1==1 and x2==1 and tempz==0 and tempy==0 then return 32 end
if z1==1 and z2==1 and tempx==0 and tempy==0 then return 33 end
return z2+z1*2+x2*4+x1*8
else
if tempy==0 and tempx==0 and tempz==0 then return 16 end
if x1==1 and x2==1 and tempz==0 and tempy==0 then return 34 end
if z1==1 and z2==1 and tempx==0 and tempy==0 then return 35 end
return z2+z1*2+x2*4+x1*8+16
function technic.posts_should_connect(pos)
local node = minetest.get_node(pos)
if technic.concrete_posts[node.name] then
return "post"
elseif minetest.get_item_group(node.name, "concrete") ~= 0 then
return "block"
end
end
function hacky_swap_posts(pos,name)
local node = minetest.env:get_node(pos)
if node.name == "technic:concrete" or node.name == "technic:blast_resistant_concrete" then
return nil
end
local meta = minetest.env:get_meta(pos)
local meta0 = meta:to_table()
node.name = name
local meta0 = meta:to_table()
minetest.env:set_node(pos,node)
meta = minetest.env:get_meta(pos)
meta:from_table(meta0)
return 1
function technic.get_post_id(links)
return (links[4] * 1) + (links[3] * 2)
+ (links[2] * 4) + (links[1] * 8)
+ (links[5] * 16)
end
function technic.update_posts(pos, set, secondrun)
local node = minetest.get_node(pos)
local link_positions = {
{x=pos.x+1, y=pos.y, z=pos.z},
{x=pos.x-1, y=pos.y, z=pos.z},
{x=pos.x, y=pos.y, z=pos.z+1},
{x=pos.x, y=pos.y, z=pos.z-1},
}
local links = {0, 0, 0, 0, 0}
for i, link_pos in pairs(link_positions) do
local connecttype = technic.posts_should_connect(link_pos)
if connecttype then
links[i] = 1
-- Have posts next to us update theirselves,
-- but only once. (We don't want to start an
-- infinite loop of updates)
if not secondrun and connecttype == "post" then
technic.update_posts(link_pos, true, true)
end
end
end
-- We don't want to set ourselves if we have been removed or we are
-- updating a concrete node
if set then
-- Preserve platform
local oldlinks = technic.concrete_posts[node.name]
if oldlinks then
links[5] = oldlinks[5]
end
minetest.set_node(pos, {name="technic:concrete_post"
..technic.get_post_id(links)})
end
end
for x1 = 0, 1 do
for x2 = 0, 1 do
for z1 = 0, 1 do
for z2 = 0, 1 do
for platform = 0, 1 do
local links = {x1, x2, z1, z2, platform}
local id = technic.get_post_id(links)
technic.concrete_posts["technic:concrete_post"..id] = links
local groups = {cracky=1, level=2, concrete_post=1}
if id ~= 0 then
groups.not_in_creative_inventory = 1
end
local drop = "technic:concrete_post0"
local after_dig_node = function(pos, oldnode, oldmetadata, digger)
technic.update_posts(pos, false)
end
if platform ~= 0 then
drop = "technic:concrete_post_platform"
after_dig_node = function(pos, oldnode, oldmetadata, digger)
dig_post_with_platform(pos, oldnode, oldmetadata)
end
end
minetest.register_node(":technic:concrete_post"..id, {
description = "Concrete Post",
tiles = {"technic_concrete_block.png"},
groups = groups,
sounds = default.node_sound_stone_defaults(),
drop = drop,
paramtype = "light",
sunlight_propagates = true,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = gen_post_nodebox(x1, x2, z1, z2, platform),
},
after_place_node = function(pos, placer, itemstack)
technic.update_posts(pos, true)
end,
after_dig_node = after_dig_node,
})
end
end
end
end
end

View File

@ -1,38 +1,39 @@
dofile(minetest.get_modpath("item_drop").."/item_entity.lua")
time_pick = 3
if technic.config:getBool("enable_item_pickup") then
if technic.config:get_bool("enable_item_pickup") then
minetest.register_globalstep(function(dtime)
for _,player in ipairs(minetest.get_connected_players()) do
if player and player:get_hp() > 0 then
local pos = player:getpos()
pos.y = pos.y+0.5
local inv = player:get_inventory()
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 2)) do
if not object:is_player() and object:get_luaentity() then
local obj=object:get_luaentity()
if obj.name == "__builtin:item" then
if inv:room_for_item("main", ItemStack(obj.itemstring)) then
if obj.timer > time_pick then
inv:add_item("main", ItemStack(obj.itemstring))
if obj.itemstring ~= "" then
minetest.sound_play("item_drop_pickup",{pos = pos, gain = 1.0, max_hear_distance = 10})
end
if object:get_luaentity() then
object:get_luaentity().itemstring = ""
object:remove()
local pos = player:getpos()
pos.y = pos.y + 0.5
local inv = player:get_inventory()
for _, object in ipairs(minetest.get_objects_inside_radius(pos, 2)) do
if not object:is_player() and object:get_luaentity() then
local obj = object:get_luaentity()
if obj.name == "__builtin:item" then
if inv and inv:room_for_item("main", ItemStack(obj.itemstring)) then
if obj.timer > time_pick then
inv:add_item("main", ItemStack(obj.itemstring))
if obj.itemstring ~= "" then
minetest.sound_play("item_drop_pickup",
{pos = pos, gain = 1.0, max_hear_distance = 10})
end
if object:get_luaentity() then
object:get_luaentity().itemstring = ""
object:remove()
end
end
end
end
end
end
end
end
end
end)
end
if technic.config:getBool("enable_item_drop") then
if technic.config:get_bool("enable_item_drop") then
function minetest.handle_node_drops(pos, drops, digger)
for _,item in ipairs(drops) do
local count, name

View File

@ -1,8 +1,11 @@
technic.config = {}
technic.config.loaded = {}
local worldpath = minetest.get_worldpath()
technic.config.default = {
technic.config = Settings(worldpath.."/technic.conf")
local conf_table = technic.config:to_table()
local defaults = {
enable_mining_drill = "true",
enable_mining_laser = "true",
enable_flashlight = "true",
@ -10,33 +13,12 @@ technic.config.default = {
enable_item_pickup = "true",
enable_rubber_tree_generation = "true",
enable_marble_generation = "true",
enable_granite_generation = "true"
enable_granite_generation = "true",
}
function technic.config:load(filename)
file, error = io.open(filename, "r")
if error then return end
local line = file:read("*l")
while line do
local found, _, setting, value = line:find("^([^#%s=]+)%s?=%s?([^%s#]+)")
if found then
self.loaded[setting] = value
end
line = file:read("*l")
end
file:close()
end
technic.config:load(minetest.get_worldpath().."/technic.conf")
function technic.config:get(setting)
if self.loaded[setting] then
return self.loaded[setting]
else
return self.default[setting]
for k, v in pairs(defaults) do
if conf_table[k] == nil then
technic.config:set(k, v)
end
end
function technic.config:getBool(setting)
return string.lower(self:get(setting)) == "true"
end

169
technic/crafts.lua Normal file
View File

@ -0,0 +1,169 @@
-- tubes crafting recipes
minetest.register_craft({
output = 'pipeworks:tube_000000 9',
recipe = {
{'technic:stainless_steel_ingot', 'default:glass', 'technic:stainless_steel_ingot'},
{'technic:stainless_steel_ingot', 'default:glass', 'technic:stainless_steel_ingot'},
{'technic:stainless_steel_ingot', 'default:glass', 'technic:stainless_steel_ingot'},
}
})
minetest.register_craft({
output = 'pipeworks:mese_tube_000000',
recipe = {
{'default:mese_crystal_fragment', 'pipeworks:tube_000000', 'default:mese_crystal_fragment'},
}
})
minetest.register_craft({
output = 'pipeworks:accelerator_tube_000000',
recipe = {
{'technic:copper_coil', 'pipeworks:tube_000000', 'technic:copper_coil'},
}
})
minetest.register_craft({
output = 'pipeworks:detector_tube_off_000000',
recipe = {
{'mesecons:mesecon', 'pipeworks:tube_000000', 'mesecons:mesecon'},
}
})
minetest.register_craft({
output = 'pipeworks:sand_tube_000000',
recipe = {
{'default:sand', 'pipeworks:tube_000000', 'default:sand'},
}
})
minetest.register_craft({
output = 'pipeworks:mese_sand_tube_000000',
recipe = {
{'default:mese_crystal_fragment', 'pipeworks:sand_tube_000000', 'default:mese_crystal_fragment'},
}
})
minetest.register_craft({
output = 'pipeworks:teleport_tube_000000',
recipe = {
{'default:mese_crystal', 'technic:copper_coil', 'default:mese_crystal'},
{'pipeworks:tube_000000', 'technic:control_logic_unit', 'pipeworks:tube_000000'},
{'default:mese_crystal', 'technic:copper_coil', 'default:mese_crystal'},
}
})
minetest.register_craft({
output = 'technic:diamond_drill_head',
recipe = {
{'technic:stainless_steel_ingot', 'default:diamond', 'technic:stainless_steel_ingot'},
{'default:diamond', '', 'default:diamond'},
{'technic:stainless_steel_ingot', 'default:diamond', 'technic:stainless_steel_ingot'},
}
})
minetest.register_craft({
output = 'technic:green_energy_crystal',
recipe = {
{'default:gold_ingot', 'technic:battery', 'dye:green'},
{'technic:battery', 'technic:red_energy_crystal', 'technic:battery'},
{'dye:green', 'technic:battery', 'default:gold_ingot'},
}
})
minetest.register_craft({
output = 'technic:blue_energy_crystal',
recipe = {
{'default:gold_ingot', 'technic:battery', 'dye:blue'},
{'technic:battery', 'technic:green_energy_crystal', 'technic:battery'},
{'dye:blue', 'technic:battery', 'default:gold_ingot'},
}
})
minetest.register_craft({
output = 'technic:red_energy_crystal',
recipe = {
{'default:gold_ingot', 'technic:battery', 'dye:red'},
{'technic:battery', 'default:diamondblock', 'technic:battery'},
{'dye:red', 'technic:battery', 'default:gold_ingot'},
}
})
minetest.register_craft({
output = 'technic:fine_copper_wire 2',
recipe = {
{'', 'default:copper_ingot', ''},
{'', 'default:copper_ingot', ''},
{'', 'default:copper_ingot', ''},
}
})
minetest.register_craft({
output = 'technic:copper_coil 1',
recipe = {
{'technic:fine_copper_wire', 'default:steel_ingot', 'technic:fine_copper_wire'},
{'default:steel_ingot', '', 'default:steel_ingot'},
{'technic:fine_copper_wire', 'default:steel_ingot', 'technic:fine_copper_wire'},
}
})
minetest.register_craft({
output = 'technic:motor',
recipe = {
{'default:steel_ingot', 'technic:copper_coil', 'default:steel_ingot'},
{'default:steel_ingot', 'technic:copper_coil', 'default:steel_ingot'},
{'default:steel_ingot', 'default:copper_ingot', 'default:steel_ingot'},
}
})
minetest.register_craft({
output = 'technic:lv_transformer',
recipe = {
{'default:iron_lump', 'default:iron_lump', 'default:iron_lump'},
{'technic:copper_coil', 'default:iron_lump', 'technic:copper_coil'},
{'default:iron_lump', 'default:iron_lump', 'default:iron_lump'},
}
})
minetest.register_craft({
output = 'technic:mv_transformer',
recipe = {
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
{'technic:copper_coil', 'default:steel_ingot', 'technic:copper_coil'},
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
}
})
minetest.register_craft({
output = 'technic:hv_transformer',
recipe = {
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
{'technic:copper_coil', 'technic:stainless_steel_ingot', 'technic:copper_coil'},
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
}
})
minetest.register_craft({
output = 'technic:control_logic_unit',
recipe = {
{'', 'default:gold_ingot', ''},
{'default:copper_ingot', 'technic:silicon_wafer', 'default:copper_ingot'},
{'', 'default:copper_ingot', ''},
}
})
minetest.register_craft({
output = 'technic:mixed_metal_ingot 9',
recipe = {
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
{'default:bronze_ingot', 'default:bronze_ingot', 'default:bronze_ingot'},
{'moreores:tin_ingot', 'moreores:tin_ingot', 'moreores:tin_ingot'},
}
})
minetest.register_craft({
output = 'technic:carbon_cloth',
recipe = {
{'technic:graphite', 'technic:graphite', 'technic:graphite'}
}
})

View File

@ -2,4 +2,4 @@ default
moreores
pipeworks
mesecons
moretrees
mesecons_mvps?

View File

@ -4,26 +4,25 @@
technic = {}
local load_start = os.clock()
local modpath = minetest.get_modpath("technic")
technic.modpath = modpath
technic.dprint = function(string)
if technic.DBG == 1 then
print(string)
end
end
--Read technic config file
-- Read configuration file
dofile(modpath.."/config.lua")
--helper functions
-- Helper functions
dofile(modpath.."/helpers.lua")
--items
-- Items
dofile(modpath.."/items.lua")
-- Craft recipes for items
dofile(modpath.."/crafts.lua")
-- Register functions
dofile(modpath.."/register_machine_and_tool.lua")
dofile(modpath.."/register.lua")
-- Machines
dofile(modpath.."/machines/init.lua")
@ -31,24 +30,31 @@ dofile(modpath.."/machines/init.lua")
-- Tools
dofile(modpath.."/tools/init.lua")
function has_locked_chest_privilege(meta, player)
if player:get_player_name() ~= meta:get_string("owner") then
return false
end
return true
end
-- Aliases for legacy node/item names
dofile(modpath.."/legacy.lua")
function has_locked_chest_privilege(meta, player)
if player:get_player_name() ~= meta:get_string("owner") then
return false
end
return true
end
-- Swap nodes out. Return the node name.
function hacky_swap_node(pos,name)
local node = minetest.env:get_node(pos)
if node.name ~= name then
local meta = minetest.env:get_meta(pos)
local meta0 = meta:to_table()
node.name = name
minetest.env:set_node(pos,node)
meta = minetest.env:get_meta(pos)
meta:from_table(meta0)
end
return node.name
function hacky_swap_node(pos, name)
local node = minetest.get_node(pos)
if node.name ~= name then
local meta = minetest.get_meta(pos)
local meta_table = meta:to_table()
node.name = name
minetest.set_node(pos, node)
meta = minetest.get_meta(pos)
meta:from_table(meta_table)
end
return node.name
end
if minetest.setting_get("log_mod") then
print("[Technic] Loaded in "..tostring(os.clock() - load_start).."s")
end

View File

@ -1,131 +1,69 @@
minetest.register_craftitem( "technic:silicon_wafer", {
description = "Silicon Wafer",
inventory_image = "technic_silicon_wafer.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem( "technic:doped_silicon_wafer", {
description = "Doped Silicon Wafer",
inventory_image = "technic_doped_silicon_wafer.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem( "technic:enriched_uranium", {
minetest.register_craftitem("technic:enriched_uranium", {
description = "Enriched Uranium",
inventory_image = "technic_enriched_uranium.png",
on_place_on_ground = minetest.craftitem_place_item,
})
-- tubes crafting recipes
minetest.register_craft({
output = 'pipeworks:tube_000000 9',
recipe = {
{'technic:stainless_steel_ingot', 'default:glass', 'technic:stainless_steel_ingot'},
{'technic:stainless_steel_ingot', 'default:glass', 'technic:stainless_steel_ingot'},
{'technic:stainless_steel_ingot', 'default:glass', 'technic:stainless_steel_ingot'},
}
})
minetest.register_craft({
output = 'pipeworks:mese_tube_000000',
recipe = {
{'default:mese_crystal_fragment', 'pipeworks:tube_000000', 'default:mese_crystal_fragment'},
}
})
minetest.register_craft({
output = 'pipeworks:accelerator_tube_000000',
recipe = {
{'technic:copper_coil', 'pipeworks:tube_000000', 'technic:copper_coil'},
}
})
minetest.register_craft({
output = 'pipeworks:detector_tube_off_000000',
recipe = {
{'mesecons:mesecon', 'pipeworks:tube_000000', 'mesecons:mesecon'},
}
})
minetest.register_craft({
output = 'pipeworks:sand_tube_000000',
recipe = {
{'default:sand', 'pipeworks:tube_000000', 'default:sand'},
}
})
minetest.register_craft({
output = 'pipeworks:mese_sand_tube_000000',
recipe = {
{'default:mese_crystal_fragment', 'pipeworks:sand_tube_000000', 'default:mese_crystal_fragment'},
}
})
minetest.register_craft({
output = 'pipeworks:teleport_tube_000000',
recipe = {
{'default:mese_crystal', 'technic:copper_coil', 'default:mese_crystal'},
{'pipeworks:tube_000000', 'technic:control_logic_unit', 'pipeworks:tube_000000'},
{'default:mese_crystal', 'technic:copper_coil', 'default:mese_crystal'},
}
minetest.register_craftitem("technic:uranium_fuel", {
description = "Uranium Fuel",
inventory_image = "technic_uranium_fuel.png",
})
minetest.register_craftitem( "technic:diamond_drill_head", {
description = "Diamond Drill Head",
inventory_image = "technic_diamond_drill_head.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
output = 'technic:diamond_drill_head',
recipe = {
{'technic:stainless_steel_ingot', 'default:diamond', 'technic:stainless_steel_ingot'},
{'default:diamond', '', 'default:diamond'},
{'technic:stainless_steel_ingot', 'default:diamond', 'technic:stainless_steel_ingot'},
minetest.register_tool("technic:blue_energy_crystal", {
description = "Blue Energy Crystal",
inventory_image = minetest.inventorycube(
"technic_diamond_block_blue.png",
"technic_diamond_block_blue.png",
"technic_diamond_block_blue.png"),
tool_capabilities = {
max_drop_level = 0,
groupcaps = {
fleshy = {times={}, uses=10000, maxlevel=0}
}
}
})
})
minetest.register_craft({
output = 'technic:green_energy_crystal',
recipe = {
{'default:gold_ingot', 'technic:battery', 'dye:green'},
{'technic:battery', 'technic:red_energy_crystal', 'technic:battery'},
{'dye:green', 'technic:battery', 'default:gold_ingot'},
minetest.register_tool("technic:green_energy_crystal", {
description = "Green Energy Crystal",
inventory_image = minetest.inventorycube(
"technic_diamond_block_green.png",
"technic_diamond_block_green.png",
"technic_diamond_block_green.png"),
tool_capabilities = {
max_drop_level = 0,
groupcaps = {
fleshy = {times={}, uses=10000, maxlevel=0}
}
}
})
})
minetest.register_craft({
output = 'technic:blue_energy_crystal',
recipe = {
{'default:gold_ingot', 'technic:battery', 'dye:blue'},
{'technic:battery', 'technic:green_energy_crystal', 'technic:battery'},
{'dye:blue', 'technic:battery', 'default:gold_ingot'},
minetest.register_tool("technic:red_energy_crystal", {
description = "Red Energy Crystal",
inventory_image = minetest.inventorycube(
"technic_diamond_block_red.png",
"technic_diamond_block_red.png",
"technic_diamond_block_red.png"),
tool_capabilities = {
max_drop_level = 0,
groupcaps = {
fleshy = {times={}, uses=10000, maxlevel=0}
}
}
})
minetest.register_craft({
output = 'technic:red_energy_crystal',
recipe = {
{'default:gold_ingot', 'technic:battery', 'dye:red'},
{'technic:battery', 'default:diamondblock', 'technic:battery'},
{'dye:red', 'technic:battery', 'default:gold_ingot'},
}
})
minetest.register_tool("technic:blue_energy_crystal",
{description = "Blue Energy Crystal",
inventory_image = minetest.inventorycube("technic_diamond_block_blue.png", "technic_diamond_block_blue.png", "technic_diamond_block_blue.png"),
tool_capabilities = {load=0,max_drop_level=0, groupcaps={fleshy={times={}, uses=10000, maxlevel=0}}}})
minetest.register_tool("technic:green_energy_crystal",
{description = "Green Energy Crystal",
inventory_image = minetest.inventorycube("technic_diamond_block_green.png", "technic_diamond_block_green.png", "technic_diamond_block_green.png"),
tool_capabilities = {load=0,max_drop_level=0, groupcaps={fleshy={times={}, uses=10000, maxlevel=0}}}})
minetest.register_tool("technic:red_energy_crystal",
{description = "Red Energy Crystal",
inventory_image = minetest.inventorycube("technic_diamond_block_red.png", "technic_diamond_block_red.png", "technic_diamond_block_red.png"),
tool_capabilities = {load=0,max_drop_level=0, groupcaps={fleshy={times={}, uses=10000, maxlevel=0}}}})
})
minetest.register_craftitem( "technic:fine_copper_wire", {
@ -134,43 +72,22 @@ minetest.register_craftitem( "technic:fine_copper_wire", {
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
output = 'technic:fine_copper_wire 2',
recipe = {
{'', 'default:copper_ingot', ''},
{'', 'default:copper_ingot', ''},
{'', 'default:copper_ingot', ''},
}
})
minetest.register_craftitem( "technic:copper_coil", {
description = "Copper Coil",
inventory_image = "technic_copper_coil.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
output = 'technic:copper_coil 1',
recipe = {
{'technic:fine_copper_wire', 'default:steel_ingot', 'technic:fine_copper_wire'},
{'default:steel_ingot', '', 'default:steel_ingot'},
{'technic:fine_copper_wire', 'default:steel_ingot', 'technic:fine_copper_wire'},
}
})
minetest.register_craftitem( "technic:motor", {
description = "Electric Motor",
inventory_image = "technic_motor.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
output = 'technic:motor',
recipe = {
{'default:steel_ingot', 'technic:copper_coil', 'default:steel_ingot'},
{'default:steel_ingot', 'technic:copper_coil', 'default:steel_ingot'},
{'default:steel_ingot', 'default:copper_ingot', 'default:steel_ingot'},
}
minetest.register_craftitem( "technic:lv_transformer", {
description = "Low Voltage Transformer",
inventory_image = "technic_lv_transformer.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem( "technic:lv_transformer", {
@ -178,91 +95,30 @@ minetest.register_craftitem( "technic:lv_transformer", {
inventory_image = "technic_lv_transformer.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
output = 'technic:lv_transformer',
recipe = {
{'default:iron_lump', 'default:iron_lump', 'default:iron_lump'},
{'technic:copper_coil', 'default:iron_lump', 'technic:copper_coil'},
{'default:iron_lump', 'default:iron_lump', 'default:iron_lump'},
}
})
minetest.register_craftitem( "technic:lv_transformer", {
description = "Low Voltage Transformer",
inventory_image = "technic_lv_transformer.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
output = 'technic:lv_transformer',
recipe = {
{'default:iron_lump', 'default:iron_lump', 'default:iron_lump'},
{'technic:copper_coil', 'default:iron_lump', 'technic:copper_coil'},
{'default:iron_lump', 'default:iron_lump', 'default:iron_lump'},
}
})
minetest.register_craftitem( "technic:mv_transformer", {
description = "Medium Voltage Transformer",
inventory_image = "technic_mv_transformer.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
output = 'technic:mv_transformer',
recipe = {
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
{'technic:copper_coil', 'default:steel_ingot', 'technic:copper_coil'},
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
}
})
minetest.register_craftitem( "technic:hv_transformer", {
description = "High Voltage Transformer",
inventory_image = "technic_hv_transformer.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
output = 'technic:hv_transformer',
recipe = {
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
{'technic:copper_coil', 'technic:stainless_steel_ingot', 'technic:copper_coil'},
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
}
})
minetest.register_craftitem( "technic:control_logic_unit", {
description = "Control Logic Unit",
inventory_image = "technic_control_logic_unit.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
output = 'technic:control_logic_unit',
recipe = {
{'', 'default:gold_ingot', ''},
{'default:copper_ingot', 'technic:silicon_wafer', 'default:copper_ingot'},
{'', 'default:copper_ingot', ''},
}
})
minetest.register_craftitem("technic:mixed_metal_ingot", {
description = "Mixed Metal Ingot",
inventory_image = "technic_mixed_metal_ingot.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
output = 'technic:mixed_metal_ingot 2',
recipe = {
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
{'default:bronze_ingot', 'default:bronze_ingot', 'default:bronze_ingot'},
{'moreores:tin_ingot', 'moreores:tin_ingot', 'moreores:tin_ingot'},
}
})
minetest.register_craftitem("technic:composite_plate", {
description = "Composite Plate",
inventory_image = "technic_composite_plate.png",
@ -293,10 +149,3 @@ minetest.register_craftitem("technic:carbon_cloth", {
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
output = 'technic:carbon_cloth',
recipe = {
{'technic:graphite', 'technic:graphite', 'technic:graphite'}
}
})

30
technic/legacy.lua Normal file
View File

@ -0,0 +1,30 @@
-- Aliases to convert from legacy node/item names
technic.legacy_nodenames = {
["technic:alloy_furnace"] = "technic:lv_alloy_furnace",
["technic:alloy_furnace_active"] = "technic:lv_alloy_furnace_active",
["technic:battery_box"] = "technic:lv_battery_box0",
["technic:battery_box1"] = "technic:lv_battery_box1",
["technic:battery_box2"] = "technic:lv_battery_box2",
["technic:battery_box3"] = "technic:lv_battery_box3",
["technic:battery_box4"] = "technic:lv_battery_box4",
["technic:battery_box5"] = "technic:lv_battery_box5",
["technic:battery_box6"] = "technic:lv_battery_box6",
["technic:battery_box7"] = "technic:lv_battery_box7",
["technic:battery_box8"] = "technic:lv_battery_box8",
["technic:electric_furnace"] = "technic:lv_electric_furnace",
["technic:electric_furnace_active"] = "technic:lv_electric_furnace_active",
["technic:grinder"] = "technic:lv_grinder",
["technic:grinder_active"] = "technic:lv_grinder_active",
["technic:hv_battery_box"] = "technic:hv_battery_box0",
["technic:hv_cable"] = "technic:hv_cable0",
["technic:lv_cable"] = "technic:lv_cable0",
["technic:mv_cable"] = "technic:mv_cable0",
["technic:mv_battery_box"] = "technic:mv_battery_box0",
}
for old, new in pairs(technic.legacy_nodenames) do
minetest.register_alias(old, new)
end

View File

@ -0,0 +1,19 @@
-- HV battery box
minetest.register_craft({
output = 'technic:hv_battery_box0',
recipe = {
{'technic:mv_battery_box0', 'technic:mv_battery_box0', 'technic:mv_battery_box0'},
{'technic:mv_battery_box0', 'technic:hv_transformer', 'technic:mv_battery_box0'},
{'', 'technic:hv_cable0', ''},
}
})
technic.register_battery_box({
tier = "HV",
max_charge = 1500000,
charge_rate = 100000,
discharge_rate = 400000,
charge_step = 10000,
discharge_step = 40000,
})

View File

@ -0,0 +1,12 @@
minetest.register_craft({
output = 'technic:hv_cable0 3',
recipe = {
{'technic:rubber', 'technic:rubber', 'technic:rubber'},
{'technic:mv_cable0', 'technic:mv_cable0', 'technic:mv_cable0'},
{'technic:rubber', 'technic:rubber', 'technic:rubber'},
}
})
technic.register_cable("HV", 3/16)

View File

@ -0,0 +1,206 @@
-- Forcefield mod by ShadowNinja
-- Modified by kpoppel
--
-- Forcefields are powerful barriers but they consume huge amounts of power.
-- Forcefield Generator is a HV machine.
-- How expensive is the generator?
-- Leaves room for upgrades lowering the power drain?
local forcefield_power_drain = 10
local forcefield_step_interval = 1
minetest.register_craft({
output = 'technic:forcefield_emitter_off',
recipe = {
{'default:mese', 'technic:deployer_off', 'default:mese' },
{'technic:deployer_off', 'technic:motor', 'technic:deployer_off'},
{'default:mese', 'technic:deployer_off', 'default:mese' },
}
})
-- Idea: Let forcefields have different colors by upgrade slot.
-- Idea: Let forcefields add up by detecting if one hits another.
-- ___ __
-- / \/ \
-- | |
-- \___/\___/
local function update_forcefield(pos, range, active)
local vm = VoxelManip()
local p1 = {x = pos.x-range, y = pos.y-range, z = pos.z-range}
local p2 = {x = pos.x+range, y = pos.y+range, z = pos.z+range}
local MinEdge, MaxEdge = vm:read_from_map(p1, p2)
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
local data = vm:get_data()
local c_air = minetest.get_content_id("air")
local c_field = minetest.get_content_id("technic:forcefield")
for z=-range, range do
for y=-range, range do
local vi = area:index(pos.x+(-range), pos.y+y, pos.z+z)
for x=-range, range do
if x*x+y*y+z*z <= range * range + range and
x*x+y*y+z*z >= (range-1) * (range-1) + (range-1) then
if active and data[vi] == c_air then
data[vi] = c_field
elseif not active and data[vi] == c_field then
data[vi] = c_air
end
end
vi = vi + 1
end
end
end
vm:set_data(data)
vm:update_liquids()
vm:write_to_map()
vm:update_map()
end
local get_forcefield_formspec = function(range)
return "size[3,1.5]"..
"field[1,0.5;2,1;range;Range;"..range.."]"..
"button[0,1;3,1;toggle;Enable/Disable]"
end
local forcefield_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
local range = fields.range
if fields.toggle then
if meta:get_int("enabled") == 1 then
meta:set_int("enabled", 0)
else
meta:set_int("enabled", 1)
end
end
-- Smallest field is 5. Anything less is asking for trouble.
-- Largest is 20. It is a matter of pratical node handling.
-- At the maximim range updating the forcefield takes about 0.2s
range = math.max(range, 5)
range = math.min(range, 20)
if meta:get_int("range") ~= range then
update_forcefield(pos, meta:get_int("range"), false)
meta:set_int("range", range)
meta:set_string("formspec", get_forcefield_formspec(range))
end
end
local mesecons = {
effector = {
action_on = function(pos, node)
minetest.get_meta(pos):set_int("enabled", 0)
end,
action_off = function(pos, node)
minetest.get_meta(pos):set_int("enabled", 1)
end
}
}
minetest.register_node("technic:forcefield_emitter_off", {
description = "Forcefield emitter",
tiles = {"technic_forcefield_emitter_off.png"},
groups = {cracky = 1},
on_receive_fields = forcefield_receive_fields,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("HV_EU_input", 0)
meta:set_int("HV_EU_demand", 0)
meta:set_int("range", 10)
meta:set_int("enabled", 0)
meta:set_string("formspec", get_forcefield_formspec(10))
meta:set_string("infotext", "Forcefield emitter");
end,
mesecons = mesecons
})
minetest.register_node("technic:forcefield_emitter_on", {
description = "Forcefield emitter on (you hacker you)",
tiles = {"technic_forcefield_emitter_on.png"},
groups = {cracky = 1, not_in_creative_inventory=1},
drop = "technic:forcefield_emitter_off",
on_receive_fields = forcefield_receive_fields,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local range = meta:get_int("range")
meta:set_string("formspec", get_forcefield_formspec(range))
end,
on_destruct = function(pos)
local meta = minetest.get_meta(pos)
update_forcefield(pos, meta:get_int("range"), false)
end,
mesecons = mesecons
})
minetest.register_node("technic:forcefield", {
description = "Forcefield (you hacker you)",
sunlight_propagates = true,
drawtype = "glasslike",
groups = {not_in_creative_inventory=1, unbreakable=1},
paramtype = "light",
light_source = 15,
drop = '',
tiles = {{
name = "technic_forcefield_animated.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 1.0,
},
}},
})
minetest.register_abm({
nodenames = {"technic:forcefield_emitter_on", "technic:forcefield_emitter_off"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local eu_input = meta:get_int("HV_EU_input")
local eu_demand = meta:get_int("HV_EU_demand")
local enabled = meta:get_int("enabled")
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "HV")
local power_requirement = math.floor(
4 * math.pi * math.pow(meta:get_int("range"), 2)
) * forcefield_power_drain
if meta:get_int("enabled") == 0 then
if node.name == "technic:forcefield_emitter_on" then
meta:set_int("HV_EU_demand", 0)
update_forcefield(pos, meta:get_int("range"), false)
hacky_swap_node(pos, "technic:forcefield_emitter_off")
meta:set_string("infotext", "Forcefield Generator Disabled")
return
end
elseif eu_input < power_requirement then
meta:set_string("infotext", "Forcefield Generator Unpowered")
if node.name == "technic:forcefield_emitter_on" then
update_forcefield(pos, meta:get_int("range"), false)
hacky_swap_node(pos, "technic:forcefield_emitter_off")
end
elseif eu_input >= power_requirement then
if node.name == "technic:forcefield_emitter_off" then
hacky_swap_node(pos, "technic:forcefield_emitter_on")
meta:set_string("infotext", "Forcefield Generator Active")
end
update_forcefield(pos, meta:get_int("range"), true)
end
meta:set_int("HV_EU_demand", power_requirement)
end
})
if minetest.get_modpath("mesecons_mvps") then
mesecon:register_mvps_stopper("technic:forcefield")
end
-- TODO: Register a stopper for frames
technic.register_machine("HV", "technic:forcefield_emitter_on", technic.receiver)
technic.register_machine("HV", "technic:forcefield_emitter_off", technic.receiver)

View File

@ -0,0 +1,12 @@
technic.register_tier("HV", "High Voltage")
local path = technic.modpath.."/machines/HV"
dofile(path.."/cables.lua")
dofile(path.."/quarry.lua")
dofile(path.."/forcefield.lua")
dofile(path.."/battery_box.lua")
dofile(path.."/solar_array.lua")
dofile(path.."/nuclear_reactor.lua")

View File

@ -6,9 +6,9 @@
-- The nuclear reactor core needs water and a protective shield to work.
-- This is checked now and then and if the machine is tampered with... BOOM!
local burn_ticks = 24*60 -- [minutes]. How many minutes does the power plant burn per serving?
local power_supply = 10000 -- [HV] EUs
local fuel_type = "technic:enriched_uranium" -- The reactor burns this stuff
local burn_ticks = 7 * 24 * 60 * 60 -- (seconds).
local power_supply = 100000 -- EUs
local fuel_type = "technic:uranium_fuel" -- The reactor burns this stuff
-- FIXME: recipe must make more sense like a rod recepticle, steam chamber, HV generator?
@ -21,14 +21,8 @@ minetest.register_craft({
}
})
minetest.register_craftitem("technic:hv_nuclear_reactor_core",{
description = "Uranium Rod Driven HV Reactor",
stack_max = 1,
})
local generator_formspec =
"invsize[8,9;]"..
--"image[0,0;5,5;technic_generator_menu.png]"..
"label[0,0;Nuclear Reactor Rod Compartment]"..
"list[current_name;src;2,1;3,2;]"..
"list[current_player;main;0,5;8,4;]"
@ -63,26 +57,29 @@ minetest.register_node("technic:hv_nuclear_reactor_core", {
sounds = default.node_sound_wood_defaults(),
drawtype="nodebox",
paramtype = "light",
stack_max = 1,
node_box = {
type = "fixed",
fixed = nodebox
},
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Nuclear Reactor Core")
meta:set_float("technic_hv_power_machine", 1)
meta:set_int("HV_EU_supply", 0)
meta:set_int("HV_EU_from_fuel", 1) -- Signal to the switching station that this device burns some sort of fuel and needs special handling
-- Signal to the switching station that this device burns some
-- sort of fuel and needs special handling
meta:set_int("HV_EU_from_fuel", 1)
meta:set_int("burn_time", 0)
meta:set_string("formspec", generator_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 6)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local meta = minetest.get_meta(pos);
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");
minetest.chat_send_player(player:get_player_name(),
"Machine cannot be removed because it is not empty");
return false
else
return true
@ -91,7 +88,7 @@ minetest.register_node("technic:hv_nuclear_reactor_core", {
})
minetest.register_node("technic:hv_nuclear_reactor_core_active", {
description = "Uranium Rod Driven HV Reactor",
description = "HV Uranium Reactor",
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
@ -107,10 +104,11 @@ minetest.register_node("technic:hv_nuclear_reactor_core_active", {
fixed = nodebox
},
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local meta = minetest.get_meta(pos);
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");
minetest.chat_send_player(player:get_player_name(),
"Machine cannot be removed because it is not empty");
return false
else
return true
@ -119,62 +117,89 @@ minetest.register_node("technic:hv_nuclear_reactor_core_active", {
})
local check_reactor_structure = function(pos)
-- The reactor consists of an 11x11x11 cube structure
-- The reactor consists of a 9x9x9 cube structure
-- A cross section through the middle:
-- CCCCC CCCCC
-- CCCCC CCCCC
-- CCSSS SSSCC
-- CCSCC CCSCC
-- CCSCWWWCSCC
-- CCSCW#WCSCC
-- CCSCW|WCSCC
-- CCSCC|CCSCC
-- CCSSS|SSSCC
-- CCCCC|CCCCC
-- C = Concrete, S = Stainless Steel, W = water node (not floating), #=reactor core, |=HV cable
-- CCCC CCCC
-- CBBB BBBC
-- CBSS SSBC
-- CBSWWWSBC
-- CBSW#WSBC
-- CBSW|WSBC
-- CBSS|SSBC
-- CBBB|BBBC
-- CCCC|CCCC
-- C = Concrete, B = Blast resistant concrete, S = Stainless Steel,
-- W = water node, # = reactor core, | = HV cable
-- The man-hole and the HV cable is only in the middle
-- The man-hole is optional
local source_water_nodes = minetest.find_nodes_in_area(
{x=pos.x-1, y=pos.y-1, z=pos.z-1},
{x=pos.x+1, y=pos.y+1, z=pos.z+1},
"default:water_source")
local flowing_water_nodes = minetest.find_nodes_in_area(
{x=pos.x-1, y=pos.y-1, z=pos.z-1},
{x=pos.x+1, y=pos.y+1, z=pos.z+1},
"default:water_flowing")
if not ((#source_water_nodes + #flowing_water_nodes) >= 25) then
return false
end
local vm = VoxelManip()
local pos1 = vector.subtract(pos, 4)
local pos2 = vector.add(pos, 4)
local MinEdge, MaxEdge = vm:read_from_map(pos1, pos2)
local data = vm:get_data()
local area = VoxelArea:new({MinEdge=MinEdge, MaxEdge=MaxEdge})
local inner_shield_nodes = minetest.find_nodes_in_area(
{x=pos.x-2, y=pos.y-2, z=pos.z-2},
{x=pos.x+2, y=pos.y+2, z=pos.z+2},
"technic:concrete")
if not (#inner_shield_nodes >= 96) then
return false
end
local c_concrete = minetest.get_content_id("technic:concrete")
local c_blast_concrete = minetest.get_content_id("technic:blast_resistant_concrete")
local c_stainless_steel = minetest.get_content_id("technic:stainless_steel_block")
local c_water_source = minetest.get_content_id("default:water_source")
local c_water_flowing = minetest.get_content_id("default:water_flowing")
local steel_shield_nodes = minetest.find_nodes_in_area(
{x=pos.x-3, y=pos.y-3, z=pos.z-3},
{x=pos.x+3, y=pos.y+3, z=pos.z+3},
"default:steelblock")
if not (#steel_shield_nodes >= 216) then
return false
end
local concretelayer, blastlayer, steellayer, waterlayer = 0, 0, 0, 0
local outer_shield_nodes = minetest.find_nodes_in_area(
{x=pos.x-5, y=pos.y-5, z=pos.z-5},
{x=pos.x+5, y=pos.y+5, z=pos.z+5},
"technic:concrete")
if not (#outer_shield_nodes >= (984 + #inner_shield_nodes)) then
return false
for z = pos1.z, pos2.z do
for y = pos1.y, pos2.y do
for x = pos1.x, pos2.x do
-- If the position is in the outer layer
if x == pos1.x or x == pos2.x or
y == pos1.y or y == pos2.y or
z == pos1.z or z == pos2.z then
if data[area:index(x, y, z)] == c_concrete then
concretelayer = concretelayer + 1
end
elseif x == pos1.x+1 or x == pos2.x-1 or
y == pos1.y+1 or y == pos2.y-1 or
z == pos1.z+1 or z == pos2.z-1 then
if data[area:index(x, y, z)] == c_blast_concrete then
blastlayer = blastlayer + 1
end
elseif x == pos1.x+2 or x == pos2.x-2 or
y == pos1.y+2 or y == pos2.y-2 or
z == pos1.z+2 or z == pos2.z-2 then
if data[area:index(x, y, z)] == c_stainless_steel then
steellayer = steellayer + 1
end
elseif x == pos1.x+3 or x == pos2.x-3 or
y == pos1.y+3 or y == pos2.y-3 or
z == pos1.z+3 or z == pos2.z-3 then
local cid = data[area:index(x, y, z)]
if cid == c_water_source or cid == c_water_flowing then
waterlayer = waterlayer + 1
end
end
end
end
end
if waterlayer >= 25 and
steellayer >= 96 and
blastlayer >= 216 and
concretelayer >= 384 then
return true
end
return true
end
local explode_reactor = function(pos)
print("BOOM A reactor exploded!")
print("A reactor exploded at "..minetest.pos_to_string(pos))
end
local function damage_nearby_players(pos)
local objs = minetest.get_objects_inside_radius(pos, 4)
for _, o in pairs(objs) do
if o:is_player() then
o:set_hp(math.max(o:get_hp() - 2, 0))
end
end
end
minetest.register_abm({
@ -182,64 +207,53 @@ minetest.register_abm({
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local burn_time = meta:get_int("burn_time")
local meta = minetest.get_meta(pos)
local burn_time = meta:get_int("burn_time") or 0
-- If more to burn and the energy produced was used: produce some more
if burn_time > 0 then
if not check_reactor_structure(pos) then
explode_reactor(pos)
end
if meta:get_int("HV_EU_supply") == 0 then
-- We did not use the power
meta:set_int("HV_EU_supply", power_supply)
else
burn_time = burn_time - 1
meta:set_int("burn_time", burn_time)
local percent = math.floor(burn_time / (burn_ticks * 60) * 100)
meta:set_string("infotext", "Nuclear Reactor Core ("..percent.."%)")
end
end
-- Burn another piece of coal
if burn_time <= 0 then
if burn_time >= burn_ticks or burn_time == 0 then
local inv = meta:get_inventory()
local correct_fuel_count = 0
if not inv:is_empty("src") then
local srclist = inv:get_list("src")
local correct_fuel_count = 0
for _, srcstack in pairs(srclist) do
if srcstack then
local src_item=srcstack:to_table()
if src_item and src_item["name"] == fuel_type then
if srcstack:get_name() == fuel_type then
correct_fuel_count = correct_fuel_count + 1
end
end
end
-- Check that the reactor is complete as well as the correct number of correct fuel
if correct_fuel_count == 6 then
if not check_reactor_structure(pos) then
burn_time = burn_ticks * 60
meta:set_int("burn_time", burn_time)
hacky_swap_node (pos,"technic:hv_nuclear_reactor_core_active")
meta:set_int("HV_EU_supply", power_supply)
for idx, srcstack in pairs(srclist) do
srcstack:take_item()
inv:set_stack("src", idx, srcstack)
end
-- Check that the reactor is complete as well
-- as the correct number of correct fuel
if correct_fuel_count == 6 and
check_reactor_structure(pos) then
meta:set_int("burn_time", 1)
hacky_swap_node(pos, "technic:hv_nuclear_reactor_core_active")
meta:set_int("HV_EU_supply", power_supply)
for idx, srcstack in pairs(srclist) do
srcstack:take_item()
inv:set_stack("src", idx, srcstack)
end
else
meta:set_int("HV_EU_supply", 0)
return
end
end
end
-- Nothing left to burn
if burn_time == 0 then
meta:set_int("HV_EU_supply", 0)
meta:set_int("burn_time", 0)
meta:set_string("infotext", "Nuclear Reactor Core (idle)")
hacky_swap_node(pos,"technic:hv_nuclear_reactor_core")
hacky_swap_node(pos, "technic:hv_nuclear_reactor_core")
elseif burn_time > 0 then
damage_nearby_players(pos)
if not check_reactor_structure(pos) then
explode_reactor(pos)
end
burn_time = burn_time + 1
meta:set_int("burn_time", burn_time)
local percent = math.floor(burn_time / burn_ticks * 100)
meta:set_string("infotext", "Nuclear Reactor Core ("..percent.."%)")
meta:set_int("HV_EU_supply", power_supply)
end
end
})
technic.register_HV_machine ("technic:hv_nuclear_reactor_core","PR")
technic.register_HV_machine ("technic:hv_nuclear_reactor_core_active","PR")
technic.register_machine("HV", "technic:hv_nuclear_reactor_core", technic.producer)
technic.register_machine("HV", "technic:hv_nuclear_reactor_core_active", technic.producer)

View File

@ -0,0 +1,200 @@
minetest.register_craft({
recipe = {
{"default:steelblock", "pipeworks:filter", "default:steelblock"},
{"default:steelblock", "technic:motor", "default:steelblock"},
{"default:steelblock", "technic:diamond_drill_head", "default:steelblock"}},
output = "technic:quarry",
})
local quarry_dig_above_nodes = 3 -- How far above the quarry we will dig nodes
local quarry_max_depth = 100
local function get_quarry_formspec(size)
return "size[3,1.5]"..
"field[1,0.5;2,1;size;Radius;"..size.."]"..
"button[0,1;3,1;toggle;Enable/Disable]"
end
local function quarry_receive_fields(pos, formname, fields, sender)
local meta = minetest.get_meta(pos)
local size = tonumber(fields.size)
if fields.toggle then
if meta:get_int("enabled") == 0 then
meta:set_int("enabled", 1)
else
meta:set_int("enabled", 0)
end
end
-- Smallest size is 2. Anything less is asking for trouble.
-- Largest is 8. It is a matter of pratical node handling.
size = math.max(size, 2)
size = math.min(size, 8)
if meta:get_int("size") ~= size then
meta:set_int("size", size)
meta:set_string("formspec", get_quarry_formspec(size))
end
end
local function get_quarry_center(pos, size)
local node = minetest.get_node(pos)
local back_dir = minetest.facedir_to_dir(node.param2)
local relative_center = vector.multiply(back_dir, size + 1)
local center = vector.add(pos, relative_center)
return center
end
local function gen_next_digpos(center, digpos, size)
digpos.x = digpos.x + 1
if digpos.x > center.x + size then
digpos.x = center.x - size
digpos.z = digpos.z + 1
end
if digpos.z > center.z + size then
digpos.x = center.x - size
digpos.z = center.z - size
digpos.y = digpos.y - 1
end
end
local function find_next_digpos(data, area, center, dig_y, size)
local c_air = minetest.get_content_id("air")
for y = center.y + quarry_dig_above_nodes, dig_y - 1, -1 do
for z = center.z - size, center.z + size do
for x = center.x - size, center.x + size do
if data[area:index(x, y, z)] ~= c_air then
return vector.new(x, y, z)
end
end
end
end
end
local function quarry_dig(pos, center, size)
local meta = minetest.get_meta(pos)
local drops = {}
local dig_y = meta:get_int("dig_y")
local owner = meta:get_int("owner")
local vm = VoxelManip()
local p1 = vector.new(
center.x - size,
center.y + quarry_dig_above_nodes,
center.z - size)
local p2 = vector.new(
center.x + size,
dig_y - 1, -- One node lower in case we have finished the current layer
center.z + size)
local e1, e2 = vm:read_from_map(p1, p2)
local area = VoxelArea:new({MinEdge=e1, MaxEdge=e2})
local data = vm:get_data()
local digpos = find_next_digpos(data, area, center, dig_y, size)
if digpos then
if digpos.y < pos.y - quarry_max_depth then
meta:set_int("dig_y", digpos.y)
return drops
end
if minetest.is_protected and minetest.is_protected(digpos, owner) then
meta:set_int("enabled", 0)
return
end
dig_y = digpos.y
local node = minetest.get_node(digpos)
drops = minetest.get_node_drops(node.name, "")
minetest.dig_node(digpos)
if minetest.get_node(digpos).name == node.name then
-- We tried to dig something undigable like a
-- filled chest. Notice that we check for a node
-- change, not for air. This is so that we get drops
-- from things like concrete posts with platforms,
-- which turn into regular concrete posts when dug.
drops = {}
end
elseif not (dig_y < pos.y - quarry_max_depth) then
dig_y = dig_y - 16
end
meta:set_int("dig_y", dig_y)
return drops
end
local function send_items(items, pos, node)
for _, item in pairs(items) do
local tube_item = tube_item(vector.new(pos), item)
tube_item:get_luaentity().start_pos = vector.new(pos)
tube_item:setvelocity(vector.new(0, 1, 0))
tube_item:setacceleration({x=0, y=0, z=0})
end
end
minetest.register_node("technic:quarry", {
description = "Quarry",
tiles = {"default_steel_block.png", "default_steel_block.png",
"default_steel_block.png", "default_steel_block.png",
"default_steel_block.png^default_tool_mesepick.png", "default_steel_block.png"},
paramtype2 = "facedir",
groups = {cracky=2, tubedevice=1},
tube = {
connect_sides = {top = 1},
},
on_construct = function(pos)
local size = 4
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Quarry")
meta:set_string("formspec", get_quarry_formspec(4))
meta:set_int("size", size)
meta:set_int("dig_y", pos.y)
end,
after_place_node = function(pos, placer, itemstack)
local meta = minetest.get_meta(pos)
meta:set_string("owner", placer:get_player_name())
tube_scanforobjects(pos)
end,
after_dig_node = tube_scanforobjects,
on_receive_fields = quarry_receive_fields,
})
minetest.register_abm({
nodenames = {"technic:quarry"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local size = meta:get_int("size")
local eu_input = meta:get_int("HV_EU_input")
local demand = 10000
local center = get_quarry_center(pos, size)
local dig_y = meta:get_int("dig_y")
technic.switching_station_timeout_count(pos, "HV")
if meta:get_int("enabled") == 0 then
meta:set_string("infotext", "Quarry Disabled")
meta:set_int("HV_EU_demand", 0)
return
end
if eu_input < demand then
meta:set_string("infotext", "Quarry Unpowered")
elseif eu_input >= demand then
meta:set_string("infotext", "Quarry Active")
local items = quarry_dig(pos, center, size)
send_items(items, pos, node)
if dig_y < pos.y - quarry_max_depth then
meta:set_string("infotext", "Quarry Finished")
end
end
meta:set_int("HV_EU_demand", demand)
end
})
technic.register_machine("HV", "technic:quarry", technic.receiver)

View File

@ -0,0 +1,14 @@
-- The high voltage solar array is an assembly of medium voltage arrays.
-- Solar arrays are not able to store large amounts of energy.
minetest.register_craft({
output = 'technic:solar_array_hv 1',
recipe = {
{'technic:solar_array_mv', 'technic:solar_array_mv', 'technic:solar_array_mv'},
{'default:steel_ingot', 'technic:hv_transformer', 'default:steel_ingot'},
{'', 'technic:hv_cable0', ''},
}
})
technic.register_solar_array({tier="HV", power=100})

View File

@ -0,0 +1,14 @@
-- LV Alloy furnace
-- FIXME: kpoppel: I'd like to introduce an induction heating element here...
minetest.register_craft({
output = 'technic:lv_alloy_furnace',
recipe = {
{'default:brick', 'default:brick', 'default:brick'},
{'default:brick', '', 'default:brick'},
{'default:steel_ingot', 'default:copper_ingot', 'default:steel_ingot'},
}
})
technic.register_alloy_furnace({tier="LV", cook_time=6, demand={300}})

View File

@ -0,0 +1,46 @@
-- LV Battery box and some other nodes...
technic.register_power_tool("technic:battery", 10000)
technic.register_power_tool("technic:red_energy_crystal", 100000)
technic.register_power_tool("technic:green_energy_crystal", 250000)
technic.register_power_tool("technic:blue_energy_crystal", 500000)
minetest.register_craft({
output = 'technic:battery',
recipe = {
{'group:wood', 'default:copper_ingot', 'group:wood'},
{'group:wood', 'moreores:tin_ingot', 'group:wood'},
{'group:wood', 'default:copper_ingot', 'group:wood'},
}
})
minetest.register_tool("technic:battery", {
description = "RE Battery",
inventory_image = "technic_battery.png",
tool_capabilities = {
charge = 0,
max_drop_level = 0,
groupcaps = {
fleshy = {times={}, uses=10000, maxlevel=0}
}
}
})
minetest.register_craft({
output = 'technic:lv_battery_box0',
recipe = {
{'technic:battery', 'group:wood', 'technic:battery'},
{'technic:battery', 'default:copper_ingot', 'technic:battery'},
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
}
})
technic.register_battery_box({
tier = "LV",
max_charge = 50000,
charge_rate = 1000,
discharge_rate = 4000,
charge_step = 500,
discharge_step = 800,
})

View File

@ -0,0 +1,12 @@
minetest.register_alias("lv_cable", "technic:lv_cable0")
minetest.register_craft({
output = 'technic:lv_cable0 6',
recipe = {
{'default:copper_ingot', 'default:copper_ingot', 'default:copper_ingot'},
}
})
technic.register_cable("LV", 2/16)

254
technic/machines/LV/cnc.lua Normal file
View File

@ -0,0 +1,254 @@
-- Technic CNC v1.0 by kpoppel
-- Based on the NonCubic Blocks MOD v1.4 by yves_de_beck
-- Idea:
-- Somehow have a tabbed/paged panel if the number of shapes should expand
-- beyond what is available in the panel today.
-- 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.
local shape = {}
local onesize_products = {
slope = 2,
slope_edge = 1,
slope_inner_edge = 1,
pyramid = 2,
spike = 1,
cylinder = 2,
sphere = 1,
stick = 8,
slope_upsdown = 2,
slope_edge_upsdown = 1,
slope_inner_edge_upsdown = 1,
cylinder_horizontal = 2,
slope_lying = 2,
onecurvededge = 1,
twocurvededge = 1,
}
local twosize_products = {
element_straight = 4,
element_end = 2,
element_cross = 1,
element_t = 1,
element_edge = 2,
}
local cnc_formspec =
"invsize[9,11;]"..
"label[1,0;Choose Milling Program:]"..
"image_button[1,0.5;1,1;technic_cnc_slope.png;slope; ]"..
"image_button[2,0.5;1,1;technic_cnc_slope_edge.png;slope_edge; ]"..
"image_button[3,0.5;1,1;technic_cnc_slope_inner_edge.png;slope_inner_edge; ]"..
"image_button[4,0.5;1,1;technic_cnc_pyramid.png;pyramid; ]"..
"image_button[5,0.5;1,1;technic_cnc_spike.png;spike; ]"..
"image_button[6,0.5;1,1;technic_cnc_cylinder.png;cylinder; ]"..
"image_button[7,0.5;1,1;technic_cnc_sphere.png;sphere; ]"..
"image_button[8,0.5;1,1;technic_cnc_stick.png;stick; ]"..
"image_button[1,1.5;1,1;technic_cnc_slope_upsdwn.png;slope_upsdown; ]"..
"image_button[2,1.5;1,1;technic_cnc_slope_edge_upsdwn.png;slope_edge_upsdown; ]"..
"image_button[3,1.5;1,1;technic_cnc_slope_inner_edge_upsdwn.png;slope_inner_edge_upsdown; ]"..
"image_button[4,1.5;1,1;technic_cnc_cylinder_horizontal.png;cylinder_horizontal; ]"..
"image_button[1,2.5;1,1;technic_cnc_slope_lying.png;slope_lying; ]"..
"image_button[2,2.5;1,1;technic_cnc_onecurvededge.png;onecurvededge; ]"..
"image_button[3,2.5;1,1;technic_cnc_twocurvededge.png;twocurvededge; ]"..
"label[1,3.5;Slim Elements half / normal height:]"..
"image_button[1,4;1,0.5;technic_cnc_full.png;full; ]"..
"image_button[1,4.5;1,0.5;technic_cnc_half.png;half; ]"..
"image_button[2,4;1,1;technic_cnc_element_straight.png;element_straight; ]"..
"image_button[3,4;1,1;technic_cnc_element_end.png;element_end; ]"..
"image_button[4,4;1,1;technic_cnc_element_cross.png;element_cross; ]"..
"image_button[5,4;1,1;technic_cnc_element_t.png;element_t; ]"..
"image_button[6,4;1,1;technic_cnc_element_edge.png;element_edge; ]"..
"label[0, 5.5;In:]"..
"list[current_name;src;0.5,5.5;1,1;]"..
"label[4, 5.5;Out:]"..
"list[current_name;dst;5,5.5;4,1;]"..
"list[current_player;main;0,7;8,4;]"
local size = 1;
-- 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.
local function form_handler(pos, formname, fields, sender)
-- REGISTER MILLING PROGRAMS AND OUTPUTS:
------------------------------------------
-- Program for half/full size
if fields["full"] then
size = 1
return
end
if fields["half"] then
size = 2
return
end
-- Resolve the node name and the number of items to make
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local inputstack = inv:get_stack("src", 1)
local inputname = inputstack:get_name()
local multiplier = 0
for k, _ in pairs(fields) do
-- Set a multipier for the half/full size capable blocks
if twosize_products[k] ~= nil then
multiplier = size * twosize_products[k]
else
multiplier = onesize_products[k]
end
if onesize_products[k] ~= nil or twosize_products[k] ~= nil then
meta:set_float( "cnc_multiplier", multiplier)
meta:set_string("cnc_user", sender:get_player_name())
end
if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then
meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k)
--print(inputname .. "_technic_cnc_" .. k)
break
end
if twosize_products[k] ~= nil and size==1 then
meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double")
--print(inputname .. "_technic_cnc_" .. k .. "_double")
break
end
end
return
end
-- The actual block inactive state
minetest.register_node("technic:cnc", {
description = "CNC Milling Machine",
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"},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
},
groups = {cracky=2},
legacy_facedir_simple = true,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "CNC Machine")
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", cnc_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
end,
can_dig = function(pos,player)
local meta = minetest.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,
on_receive_fields = form_handler,
})
-- Active state block
minetest.register_node("technic:cnc_active", {
description = "CNC Machine",
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"},
paramtype2 = "facedir",
groups = {cracky=2, not_in_creative_inventory=1},
legacy_facedir_simple = true,
can_dig = function(pos,player)
local meta = minetest.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,
})
-- Action code performing the transformation
minetest.register_abm({
nodenames = {"technic:cnc","technic:cnc_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local eu_input = meta:get_int("LV_EU_input")
local machine_name = "CNC"
local machine_node = "technic:cnc"
local demand = 450
-- Setup meta data if it does not exist. state is used as an indicator of this
if not eu_input then
meta:set_int("LV_EU_demand", demand)
meta:set_int("LV_EU_input", 0)
return
end
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
local result = meta:get_string("cnc_product")
if inv:is_empty("src") or
(not minetest.registered_nodes[result]) or
(not inv:room_for_item("dst", result)) then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
meta:set_string("cnc_product", "")
return
end
if eu_input < demand then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
elseif eu_input >= demand then
hacky_swap_node(pos, machine_node.."_active")
meta:set_string("infotext", machine_name.." Active")
meta:set_int("src_time", meta:get_int("src_time") + 1)
if meta:get_int("src_time") >= 3 then -- 3 ticks per output
meta:set_int("src_time", 0)
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
inv:add_item("dst", result.." "..meta:get_int("cnc_multiplier"))
end
end
meta:set_int("LV_EU_demand", demand)
end
})
technic.register_machine("LV", "technic:cnc", technic.receiver)
technic.register_machine("LV", "technic:cnc_active", technic.receiver)
-------------------------
-- CNC Machine Recipe
-------------------------
minetest.register_craft({
output = 'technic:cnc',
recipe = {
{'default:glass', 'technic:diamond_drill_head', 'default:glass'},
{'technic:control_logic_unit', 'technic:motor', 'default:steel_ingot'},
{'default:steel_ingot', 'default:copper_ingot', 'default:steel_ingot'},
},
})

View File

@ -0,0 +1,354 @@
-- API for the technic CNC machine
-- Again code is adapted from the NonCubic Blocks MOD v1.4 by yves_de_beck
technic.cnc = {}
technic.cnc.detail_level = 16
-- REGISTER NONCUBIC FORMS, CREATE MODELS AND RECIPES:
------------------------------------------------------
local function cnc_sphere()
local nodebox = {}
local detail = technic.cnc.detail_level
local sehne
for i = 1, detail - 1 do
sehne = math.sqrt(0.25 - (((i / detail) - 0.5) ^ 2))
nodebox[i]={-sehne, (i/detail) - 0.5, -sehne, sehne, (i/detail)+(1/detail)-0.5, sehne}
end
return nodebox
end
local function cnc_cylinder_horizontal()
local nodebox = {}
local detail = technic.cnc.detail_level
local sehne
for i = 1, detail - 1 do
sehne = math.sqrt(0.25 - (((i / detail) - 0.5) ^ 2))
nodebox[i]={-0.5, (i/detail)-0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, sehne}
end
return nodebox
end
local function cnc_cylinder()
local nodebox = {}
local detail = technic.cnc.detail_level
local sehne
for i = 1, detail - 1 do
sehne = math.sqrt(0.25 - (((i / detail) - 0.5) ^ 2))
nodebox[i]={(i/detail) - 0.5, -0.5, -sehne, (i/detail)+(1/detail)-0.5, 0.5, sehne}
end
return nodebox
end
local function cnc_twocurvededge()
local nodebox = {}
local detail = technic.cnc.detail_level * 2
local sehne
for i = (detail / 2) - 1, detail - 1 do
sehne = math.sqrt(0.25 - (((i / detail) - 0.5) ^ 2))
nodebox[i]={-sehne, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5}
end
return nodebox
end
local function cnc_onecurvededge()
local nodebox = {}
local detail = technic.cnc.detail_level * 2
local sehne
for i = (detail / 2) - 1, detail - 1 do
sehne = math.sqrt(0.25 - (((i / detail) - 0.5) ^ 2))
nodebox[i]={-0.5, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5}
end
return nodebox
end
local function cnc_spike()
local nodebox = {}
local detail = technic.cnc.detail_level
for i = 0, detail - 1 do
nodebox[i+1] = {(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5,
0.5-(i/detail/2), (i/detail)-0.5+(1/detail), 0.5-(i/detail/2)}
end
return nodebox
end
local function cnc_pyramid()
local nodebox = {}
local detail = technic.cnc.detail_level / 2
for i = 0, detail - 1 do
nodebox[i+1] = {(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5, 0.5-(i/detail/2), (i/detail/2)-0.5+(1/detail), 0.5-(i/detail/2)}
end
return nodebox
end
local function cnc_slope_inner_edge_upsdown()
local nodebox = {}
local detail = technic.cnc.detail_level
for i = 0, detail-1 do
nodebox[i+1] = {0.5-(i/detail)-(1/detail), (i/detail)-0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
nodebox[i+detail+1] = {-0.5, (i/detail)-0.5, 0.5-(i/detail)-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
local function cnc_slope_edge_upsdown()
local nodebox = {}
local detail = technic.cnc.detail_level
for i = 0, detail-1 do
nodebox[i+1] = {(-1*(i/detail))+0.5-(1/detail), (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
local function cnc_slope_inner_edge()
local nodebox = {}
local detail = technic.cnc.detail_level
for i = 0, detail-1 do
nodebox[i+1] = {(i/detail)-0.5, -0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
nodebox[i+detail+1] = {-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
local function cnc_slope_edge()
local nodebox = {}
local detail = technic.cnc.detail_level
for i = 0, detail-1 do
nodebox[i+1] = {(i/detail)-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
local function cnc_slope_upsdown()
local nodebox = {}
local detail = technic.cnc.detail_level
for i = 0, detail-1 do
nodebox[i+1] = {-0.5, (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
local function cnc_slope_lying()
local nodebox = {}
local detail = technic.cnc.detail_level
for i = 0, detail-1 do
nodebox[i+1] = {(i/detail)-0.5, -0.5, (i/detail)-0.5, (i/detail)-0.5+(1/detail), 0.5 , 0.5}
end
return nodebox
end
local function cnc_slope()
local nodebox = {}
local detail = technic.cnc.detail_level
for i = 0, detail-1 do
nodebox[i+1] = {-0.5, (i/detail)-0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
-- Define slope boxes for the various nodes
-------------------------------------------
technic.cnc.programs = {
{suffix = "technic_cnc_stick",
nodebox = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15},
desc = "Stick"},
{suffix = "technic_cnc_element_end_double",
nodebox = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.5},
desc = "Element End Double"},
{suffix = "technic_cnc_element_cross_double",
nodebox = {
{0.3, -0.5, -0.3, 0.5, 0.5, 0.3},
{-0.3, -0.5, -0.5, 0.3, 0.5, 0.5},
{-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}},
desc = "Element Cross Double"},
{suffix = "technic_cnc_element_t_double",
nodebox = {
{-0.3, -0.5, -0.5, 0.3, 0.5, 0.3},
{-0.5, -0.5, -0.3, -0.3, 0.5, 0.3},
{0.3, -0.5, -0.3, 0.5, 0.5, 0.3}},
desc = "Element T Double"},
{suffix = "technic_cnc_element_edge_double",
nodebox = {
{-0.3, -0.5, -0.5, 0.3, 0.5, 0.3},
{-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}},
desc = "Element Edge Double"},
{suffix = "technic_cnc_element_straight_double",
nodebox = {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5},
desc = "Element Straight Double"},
{suffix = "technic_cnc_element_end",
nodebox = {-0.3, -0.5, -0.3, 0.3, 0, 0.5},
desc = "Element End"},
{suffix = "technic_cnc_element_cross",
nodebox = {
{0.3, -0.5, -0.3, 0.5, 0, 0.3},
{-0.3, -0.5, -0.5, 0.3, 0, 0.5},
{-0.5, -0.5, -0.3, -0.3, 0, 0.3}},
desc = "Element Cross"},
{suffix = "technic_cnc_element_t",
nodebox = {
{-0.3, -0.5, -0.5, 0.3, 0, 0.3},
{-0.5, -0.5, -0.3, -0.3, 0, 0.3},
{0.3, -0.5, -0.3, 0.5, 0, 0.3}},
desc = "Element T"},
{suffix = "technic_cnc_element_edge",
nodebox = {
{-0.3, -0.5, -0.5, 0.3, 0, 0.3},
{-0.5, -0.5, -0.3, -0.3, 0, 0.3}},
desc = "Element Edge"},
{suffix = "technic_cnc_element_straight",
nodebox = {-0.3, -0.5, -0.5, 0.3, 0, 0.5},
desc = "Element Straight"},
{suffix = "technic_cnc_sphere",
nodebox = cnc_sphere(),
desc = "Sphere"},
{suffix = "technic_cnc_cylinder_horizontal",
nodebox = cnc_cylinder_horizontal(),
desc = "Cylinder Horizontal"},
{suffix = "technic_cnc_cylinder",
nodebox = cnc_cylinder(),
desc = ""},
{suffix = "technic_cnc_twocurvededge",
nodebox = cnc_twocurvededge(),
desc = "One Curved Edge Block"},
{suffix = "technic_cnc_onecurvededge",
nodebox = cnc_onecurvededge(),
desc = "Two Curved Edge Block"},
{suffix = "technic_cnc_spike",
nodebox = cnc_spike(),
desc = "Spike"},
{suffix = "technic_cnc_pyramid",
nodebox = cnc_pyramid(),
desc = "Pyramid"},
{suffix = "technic_cnc_slope_inner_edge_upsdown",
nodebox = cnc_slope_inner_edge_upsdown(),
desc = "Slope Upside Down Inner Edge"},
{suffix = "technic_cnc_slope_edge_upsdown",
nodebox = cnc_slope_edge_upsdown(),
desc = "Slope Upside Down Edge"},
{suffix = "technic_cnc_slope_inner_edge",
nodebox = cnc_slope_inner_edge(),
desc = "Slope Inner Edge"},
{suffix = "technic_cnc_slope_edge",
nodebox = cnc_slope_edge(),
desc = "Slope Edge"},
{suffix = "technic_cnc_slope_upsdown",
nodebox = cnc_slope_upsdown(),
desc = "Slope Upside Down"},
{suffix = "technic_cnc_slope_lying",
nodebox = cnc_slope_lying(),
desc = "Slope Lying"},
{suffix = "technic_cnc_slope",
nodebox = cnc_slope(),
desc = "Slope"},
}
-- Allow disabling certain programs for some node. Default is allowing all types for all nodes
technic.cnc.programs_disable = {
-- ["default:brick"] = {"technic_cnc_stick"}, -- Example: Disallow the stick for brick
-- ...
["default:dirt"] = {"technic_cnc_sphere", "technic_cnc_slope_upsdown", "technic_cnc_edge",
"technic_cnc_inner_edge", "technic_cnc_slope_edge_upsdown",
"technic_cnc_slope_inner_edge_upsdown", "technic_cnc_stick",
"technic_cnc_cylinder_horizontal"}
}
-- Generic function for registering all the different node types
function technic.cnc.register_program(recipeitem, suffix, nodebox, groups, images, description)
minetest.register_node(":"..recipeitem.."_"..suffix, {
description = description,
drawtype = "nodebox",
tiles = images,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
node_box = {
type = "fixed",
fixed = nodebox
},
groups = groups,
})
end
-- function to iterate over all the programs the CNC machine knows
function technic.cnc.register_all(recipeitem, groups, images, description)
for _, data in ipairs(technic.cnc.programs) do
-- Disable node creation for disabled node types for some material
local do_register = true
if technic.cnc.programs_disable[recipeitem] ~= nil then
for __, disable in ipairs(technic.cnc.programs_disable[recipeitem]) do
if disable == data.suffix then
do_register = false
end
end
end
-- Create the node if it passes the test
if do_register then
technic.cnc.register_program(recipeitem, data.suffix, data.nodebox, groups, images, description.." "..data.desc)
end
end
end
-- REGISTER NEW TECHNIC_CNC_API's PART 2: technic.cnc..register_element_end(subname, recipeitem, groups, images, desc_element_xyz)
-----------------------------------------------------------------------------------------------------------------------
function technic.cnc.register_slope_edge_etc(recipeitem, groups, images, desc_slope, desc_slope_lying, desc_slope_upsdown, desc_slope_edge, desc_slope_inner_edge, desc_slope_upsdwn_edge, desc_slope_upsdwn_inner_edge, desc_pyramid, desc_spike, desc_onecurvededge, desc_twocurvededge, desc_cylinder, desc_cylinder_horizontal, desc_sphere, desc_element_straight, desc_element_edge, desc_element_t, desc_element_cross, desc_element_end)
technic.cnc.register_slope(recipeitem, groups, images, desc_slope)
technic.cnc.register_slope_lying(recipeitem, groups, images, desc_slope_lying)
technic.cnc.register_slope_upsdown(recipeitem, groups, images, desc_slope_upsdown)
technic.cnc.register_slope_edge(recipeitem, groups, images, desc_slope_edge)
technic.cnc.register_slope_inner_edge(recipeitem, groups, images, desc_slope_inner_edge)
technic.cnc.register_slope_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_edge)
technic.cnc.register_slope_inner_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_inner_edge)
technic.cnc.register_pyramid(recipeitem, groups, images, desc_pyramid)
technic.cnc.register_spike(recipeitem, groups, images, desc_spike)
technic.cnc.register_onecurvededge(recipeitem, groups, images, desc_onecurvededge)
technic.cnc.register_twocurvededge(recipeitem, groups, images, desc_twocurvededge)
technic.cnc.register_cylinder(recipeitem, groups, images, desc_cylinder)
technic.cnc.register_cylinder_horizontal(recipeitem, groups, images, desc_cylinder_horizontal)
technic.cnc.register_sphere(recipeitem, groups, images, desc_sphere)
technic.cnc.register_element_straight(recipeitem, groups, images, desc_element_straight)
technic.cnc.register_element_edge(recipeitem, groups, images, desc_element_edge)
technic.cnc.register_element_t(recipeitem, groups, images, desc_element_t)
technic.cnc.register_element_cross(recipeitem, groups, images, desc_element_cross)
technic.cnc.register_element_end(recipeitem, groups, images, desc_element_end)
end
-- REGISTER STICKS: noncubic.register_xyz(recipeitem, groups, images, desc_element_xyz)
------------------------------------------------------------------------------------------------------------
function technic.cnc.register_stick_etc(recipeitem, groups, images, desc_stick)
technic.cnc.register_stick(recipeitem, groups, images, desc_stick)
end
function technic.cnc.register_elements(recipeitem, groups, images, desc_element_straight_double, desc_element_edge_double, desc_element_t_double, desc_element_cross_double, desc_element_end_double)
technic.cnc.register_element_straight_double(recipeitem, groups, images, desc_element_straight_double)
technic.cnc.register_element_edge_double(recipeitem, groups, images, desc_element_edge_double)
technic.cnc.register_element_t_double(recipeitem, groups, images, desc_element_t_double)
technic.cnc.register_element_cross_double(recipeitem, groups, images, desc_element_cross_double)
technic.cnc.register_element_end_double(recipeitem, groups, images, desc_element_end_double)
end

View File

@ -0,0 +1,71 @@
-- REGISTER MATERIALS AND PROPERTIES FOR NONCUBIC ELEMENTS:
-----------------------------------------------------------
-- DIRT
-------
technic.cnc.register_all("default:dirt",
{snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1},
{"default_grass.png", "default_dirt.png", "default_grass.png"},
"Dirt")
technic.cnc.programs_disable["default:dirt"] = {"technic_cnc_sphere", "technic_cnc_slope_upsdown",
"technic_cnc_edge", "technic_cnc_inner_edge",
"technic_cnc_slope_edge_upsdown", "technic_cnc_slope_inner_edge_upsdown",
"technic_cnc_stick", "technic_cnc_cylinder_horizontal"}
-- TREE
-------
technic.cnc.register_all("default:tree",
{snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
{"default_tree.png"},
"Wooden")
-- WOOD
-------
technic.cnc.register_all("default:wood",
{snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
{"default_wood.png"},
"Wooden")
-- STONE
--------
technic.cnc.register_all("default:stone",
{cracky=3, not_in_creative_inventory=1},
{"default_stone.png"},
"Stone")
-- COBBLE
---------
technic.cnc.register_all("default:cobble",
{cracky=3, not_in_creative_inventory=1},
{"default_cobble.png"},
"Cobble")
-- BRICK
--------
technic.cnc.register_all("default:brick",
{cracky=3, not_in_creative_inventory=1},
{"default_brick.png"},
"Brick")
-- SANDSTONE
------------
technic.cnc.register_all("default:sandstone",
{crumbly=2, cracky=2, not_in_creative_inventory=1},
{"default_sandstone.png"},
"Sandstone")
-- LEAVES
---------
technic.cnc.register_all("default:leaves",
{snappy=2, choppy=2, oddly_breakable_by_hand=3, not_in_creative_inventory=1},
{"default_leaves.png"},
"Leaves")
-- TREE
-------
technic.cnc.register_all("default:tree",
{snappy=1, choppy=2, oddly_breakable_by_hand=2, flammable=3, wood=1, not_in_creative_inventory=1},
{"default_tree.png"},
"Tree")
-- STEEL
--------
technic.cnc.register_all("default:steel",
{snappy=1, bendy=2, cracky=1, melty=2, level=2, not_in_creative_inventory=1},
{"default_steel_block.png"},
"Steel")

View File

@ -0,0 +1,181 @@
-- Coal driven alloy furnace. This uses no EUs:
minetest.register_craft({
output = 'technic:coal_alloy_furnace',
recipe = {
{'default:brick', 'default:brick', 'default:brick'},
{'default:brick', '', 'default:brick'},
{'default:brick', 'default:brick', 'default:brick'},
}
})
minetest.register_node("technic:coal_alloy_furnace", {
description = "Alloy Furnace",
tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", "technic_coal_alloy_furnace_side.png",
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front.png"},
paramtype2 = "facedir",
groups = {cracky=2},
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", coal_alloy_furnace_formspec)
meta:set_string("infotext", "Alloy Furnace")
local inv = meta:get_inventory()
inv:set_size("fuel", 1)
inv:set_size("src", 1)
inv:set_size("src2", 1)
inv:set_size("dst", 4)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not (inv:is_empty("fuel") or inv:is_empty("dst") or inv:is_empty("src") or inv:is_empty("src2") )then
return false
end
return true
end,
})
minetest.register_node("technic:coal_alloy_furnace_active", {
description = "Alloy Furnace",
tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", "technic_coal_alloy_furnace_side.png",
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front_active.png"},
paramtype2 = "facedir",
light_source = 8,
drop = "technic:coal_alloy_furnace",
groups = {cracky=2, not_in_creative_inventory=1},
legacy_facedir_simple = true,
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("fuel") or inv:is_empty("dst") or
inv:is_empty("src") or inv:is_empty("src2")) then
return false
end
return true
end,
})
minetest.register_abm({
nodenames = {"technic:coal_alloy_furnace", "technic:coal_alloy_furnace_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local recipe = nil
local formspec =
"size[8,9]"..
"label[0,0;Alloy Furnace]"..
"image[2,2;1,1;default_furnace_fire_bg.png]"..
"list[current_name;fuel;2,3;1,1;]"..
"list[current_name;src;2,1;1,1;]"..
"list[current_name;src2;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"
for i, name in pairs({
"fuel_totaltime",
"fuel_time",
"src_totaltime",
"src_time"}) do
if not meta:get_float(name) then
meta:set_float(name, 0.0)
end
end
-- Get what to cook if anything
local srcstack = inv:get_stack("src", 1)
local src2stack = inv:get_stack("src2", 1)
local recipe = technic.get_alloy_recipe(srcstack, src2stack)
if srcstack:get_name() > src2stack:get_name() then
local temp = srcstack
srcstack = src2stack
src2stack = temp
end
local was_active = false
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
was_active = true
meta:set_int("fuel_time", meta:get_int("fuel_time") + 1)
if recipe then
meta:set_int("src_time", meta:get_int("src_time") + 1)
if meta:get_int("src_time") == 6 then
-- check if there's room for output in "dst" list
local dst_stack = ItemStack(recipe.output)
if inv:room_for_item("dst", dst_stack) then
srcstack:take_item(recipe.input[1].count)
inv:set_stack("src", 1, srcstack)
src2stack:take_item(recipe.input[2].count)
inv:set_stack("src2", 1, src2stack)
inv:add_item("dst", dst_stack)
end
meta:set_int("src_time", 0)
end
else
meta:set_int("src_time", 0)
end
end
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
local percent = math.floor(meta:get_float("fuel_time") /
meta:get_float("fuel_totaltime") * 100)
meta:set_string("infotext","Furnace active: "..percent.."%")
hacky_swap_node(pos, "technic:coal_alloy_furnace_active")
meta:set_string("formspec",
"size[8,9]"..
"label[0,0;Electric Alloy Furnace]"..
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
(100-percent)..":default_furnace_fire_fg.png]"..
"list[current_name;fuel;2,3;1,1;]"..
"list[current_name;src;2,1;1,1;]"..
"list[current_name;src2;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]")
return
end
-- FIXME: Make this look more like the electrical version.
-- 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("src2", 1)
local recipe = technic.get_alloy_recipe(srcstack, src2stack)
if recipe then
if was_active then
meta:set_string("infotext", "Furnace is empty")
hacky_swap_node(pos, "technic:coal_alloy_furnace")
meta:set_string("formspec", 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
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
end
if fuel.time <= 0 then
meta:set_string("infotext", "Furnace out of fuel")
hacky_swap_node(pos, "technic:coal_alloy_furnace")
meta:set_string("formspec", formspec)
return
end
meta:set_string("fuel_totaltime", fuel.time)
meta:set_string("fuel_time", 0)
local stack = inv:get_stack("fuel", 1)
stack:take_item()
inv:set_stack("fuel", 1, stack)
end,
})

View File

@ -0,0 +1,169 @@
technic.compressor_recipes ={}
technic.register_compressor_recipe = function(src, src_count, dst, dst_count)
technic.compressor_recipes[src] = {src_count = src_count, dst_name = dst, dst_count = dst_count}
if unified_inventory then
unified_inventory.register_craft(
{
type = "compressing",
output = dst.." "..dst_count,
items = {src.." "..src_count},
width = 0,
})
end
end
technic.get_compressor_recipe = function(item)
if technic.compressor_recipes[item.name] and
item.count >= technic.compressor_recipes[item.name].src_count then
return technic.compressor_recipes[item.name]
else
return nil
end
end
technic.register_compressor_recipe("default:snowblock", 1, "default:ice", 1)
technic.register_compressor_recipe("default:sand", 1, "default:sandstone", 1)
technic.register_compressor_recipe("default:desert_sand", 1, "default:desert_stone", 1)
technic.register_compressor_recipe("technic:mixed_metal_ingot", 1, "technic:composite_plate", 1)
technic.register_compressor_recipe("default:copper_ingot", 5, "technic:copper_plate", 1)
technic.register_compressor_recipe("technic:coal_dust", 4, "technic:graphite", 1)
technic.register_compressor_recipe("technic:carbon_cloth", 1, "technic:carbon_plate", 1)
technic.register_compressor_recipe("technic:enriched_uranium", 4, "technic:uranium_fuel", 1)
minetest.register_alias("compressor", "technic:compressor")
minetest.register_craft({
output = 'technic:compressor',
recipe = {
{'default:stone', 'default:stone', 'default:stone'},
{'mesecons:piston', 'technic:motor', 'mesecons:piston'},
{'default:stone', 'technic:lv_cable0', 'default:stone'},
}
})
local compressor_formspec =
"invsize[8,9;]"..
"label[0,0;Compressor]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:compressor", {
description = "Compressor",
tiles = {"technic_compressor_top.png", "technic_compressor_bottom.png",
"technic_compressor_side.png", "technic_compressor_side.png",
"technic_compressor_back.png", "technic_compressor_front.png"},
paramtype2 = "facedir",
groups = {cracky=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Compressor")
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", compressor_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
end,
can_dig = function(pos,player)
local meta = minetest.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:compressor_active", {
description = "Compressor",
tiles = {"technic_compressor_top.png", "technic_compressor_bottom.png",
"technic_compressor_side.png", "technic_compressor_side.png",
"technic_compressor_back.png", "technic_compressor_front_active.png"},
paramtype2 = "facedir",
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.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_abm({
nodenames = {"technic:compressor","technic:compressor_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local eu_input = meta:get_int("LV_EU_input")
local machine_name = "Compressor"
local machine_node = "technic:compressor"
local demand = 300
-- Setup meta data if it does not exist.
if not eu_input then
meta:set_int("LV_EU_demand", demand)
meta:set_int("LV_EU_input", 0)
return
end
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
local inv = meta:get_inventory()
local empty = inv:is_empty("src")
local srcstack = inv:get_stack("src", 1)
local src_item, recipe, result = nil, nil, nil
if srcstack then
src_item = srcstack:to_table()
end
if src_item then
recipe = technic.get_compressor_recipe(src_item)
end
if recipe then
result = {name=recipe.dst_name, count=recipe.dst_count}
end
if empty or (not result) or
(not inv:room_for_item("dst", result)) then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
meta:set_int("LV_EU_demand", 0)
meta:set_int("src_time", 0)
return
end
if eu_input < demand then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
elseif eu_input >= demand then
hacky_swap_node(pos, machine_node.."_active")
meta:set_string("infotext", machine_name.." Active")
meta:set_int("src_time", meta:get_int("src_time") + 1)
if meta:get_int("src_time") >= 4 then
meta:set_int("src_time", 0)
srcstack:take_item(recipe.src_count)
inv:set_stack("src", 1, srcstack)
inv:add_item("dst", result)
end
end
meta:set_int("LV_EU_demand", demand)
end
})
technic.register_machine("LV", "technic:compressor", technic.receiver)
technic.register_machine("LV", "technic:compressor_active", technic.receiver)

View File

@ -0,0 +1,16 @@
-- LV Electric Furnace
-- This is a faster version of the stone furnace which runs on EUs
-- 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'},
}
})
technic.register_electric_furnace({tier="LV", demand={300}, speed = 2})

View File

@ -0,0 +1,175 @@
technic.extractor_recipes ={}
technic.register_extractor_recipe = function(src, src_count, dst, dst_count)
technic.extractor_recipes[src] = {src_count = src_count, dst_name = dst, dst_count = dst_count}
if unified_inventory then
unified_inventory.register_craft({
type = "extracting",
output = dst.." "..dst_count,
items = {src.." "..src_count},
width = 0,
})
end
end
-- Receive an ItemStack of result by an ItemStack input
technic.get_extractor_recipe = function(item)
if technic.extractor_recipes[item.name] and
item.count >= technic.extractor_recipes[item.name].src_count then
return technic.extractor_recipes[item.name]
else
return nil
end
end
technic.register_extractor_recipe("technic:coal_dust", 1, "dye:black", 2)
technic.register_extractor_recipe("default:cactus", 1, "dye:green", 2)
technic.register_extractor_recipe("default:dry_shrub", 1, "dye:brown", 2)
technic.register_extractor_recipe("flowers:geranium", 1, "dye:blue", 2)
technic.register_extractor_recipe("flowers:dandelion_white", 1, "dye:white", 2)
technic.register_extractor_recipe("flowers:dandelion_yellow", 1, "dye:yellow", 2)
technic.register_extractor_recipe("flowers:tulip", 1, "dye:orange", 2)
technic.register_extractor_recipe("flowers:rose", 1, "dye:red", 2)
technic.register_extractor_recipe("flowers:viola", 1, "dye:violet", 2)
technic.register_extractor_recipe("technic:raw_latex", 1, "technic:rubber", 3)
technic.register_extractor_recipe("moretrees:rubber_tree_trunk_empty", 1, "technic:rubber", 1)
technic.register_extractor_recipe("moretrees:rubber_tree_trunk", 1, "technic:rubber", 1)
technic.register_extractor_recipe("technic:uranium", 5, "technic:enriched_uranium", 1)
minetest.register_alias("extractor", "technic:extractor")
minetest.register_craft({
output = 'technic:extractor',
recipe = {
{'technic:treetap', 'technic:motor', 'technic:treetap'},
{'technic:treetap', 'technic:lv_cable0', 'technic:treetap'},
{'', '', ''},
}
})
local extractor_formspec =
"invsize[8,9;]"..
"label[0,0;Extractor]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:extractor", {
description = "Extractor",
tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png",
"technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front.png"},
paramtype2 = "facedir",
groups = {cracky=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Extractor")
meta:set_string("formspec", extractor_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
end,
can_dig = function(pos,player)
local meta = minetest.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:extractor_active", {
description = "Extractor",
tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png",
"technic_lv_grinder_side.png", "technic_lv_grinder_side.png",
"technic_lv_grinder_side.png", "technic_lv_grinder_front_active.png"},
paramtype2 = "facedir",
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.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_abm({
nodenames = {"technic:extractor", "technic:extractor_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- The machine will automatically shut down if disconnected from power in some fashion.
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local srcstack = inv:get_stack("src", 1)
local eu_input = meta:get_int("LV_EU_input")
-- Machine information
local machine_name = "Extractor"
local machine_node = "technic:extractor"
local demand = 300
-- Setup meta data if it does not exist.
if not eu_input then
meta:set_int("LV_EU_demand", demand)
meta:set_int("LV_EU_input", 0)
return
end
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
if srcstack then
src_item = srcstack:to_table()
end
if src_item then
recipe = technic.get_extractor_recipe(src_item)
end
if recipe then
result = {name=recipe.dst_name, count=recipe.dst_count}
end
if inv:is_empty("src") or (not recipe) or (not result) or
(not inv:room_for_item("dst", result)) then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
meta:set_int("LV_EU_demand", 0)
return
end
if eu_input < demand then
-- unpowered - go idle
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
elseif eu_input >= demand then
-- Powered
hacky_swap_node(pos, machine_node.."_active")
meta:set_string("infotext", machine_name.." 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_int("src_time", 0)
srcstack:take_item(recipe.src_count)
inv:set_stack("src", 1, srcstack)
inv:add_item("dst", result)
end
end
meta:set_int("LV_EU_demand", demand)
end
})
technic.register_machine("LV", "technic:extractor", technic.receiver)
technic.register_machine("LV", "technic:extractor_active", technic.receiver)

View File

@ -0,0 +1,139 @@
-- The electric generator.
-- A simple device to get started on the electric machines.
-- Inefficient and expensive in fuel (200EU per tick)
-- Also only allows for LV machinery to run.
minetest.register_alias("generator", "technic:generator")
minetest.register_alias("generator", "technic:generator_active")
minetest.register_craft({
output = 'technic:generator',
recipe = {
{'default:stone', 'default:stone', 'default:stone'},
{'default:stone', '', 'default:stone'},
{'default:stone', 'default:copper_ingot', 'default:stone'},
}
})
local generator_formspec =
"invsize[8,9;]"..
"label[0,0;Generator]"..
"list[current_name;src;3,1;1,1;]"..
"image[4,1;1,1;default_furnace_fire_bg.png]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:generator", {
description = "Electric Generator",
tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png",
"technic_generator_side.png", "technic_generator_side.png", "technic_generator_front.png"},
paramtype2 = "facedir",
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Electric Generator")
meta:set_int("LV_EU_supply", 0)
-- Signal to the switching station that this device burns some
-- sort of fuel and needs special handling
meta:set_int("LV_EU_from_fuel", 1)
meta:set_int("burn_time", 0)
meta:set_string("formspec", generator_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
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
else
return true
end
end,
})
minetest.register_node("technic:generator_active", {
description = "Electric Generator",
tiles = {"technic_generator_top.png", "technic_machine_bottom.png",
"technic_generator_side.png", "technic_generator_side.png",
"technic_generator_side.png", "technic_generator_front_active.png"},
paramtype2 = "facedir",
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2,
not_in_creative_inventory=1},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
drop = "technic:generator",
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
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
else
return true
end
end,
})
minetest.register_abm({
nodenames = {"technic:generator", "technic:generator_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local burn_time = meta:get_int("burn_time")
local burn_totaltime = meta:get_int("burn_totaltime")
-- If more to burn and the energy produced was used: produce some more
if burn_time > 0 then
meta:set_int("LV_EU_supply", 200) -- Give 200EUs
burn_time = burn_time - 1
meta:set_int("burn_time", burn_time)
end
-- Burn another piece of fuel
if burn_time == 0 then
local inv = meta:get_inventory()
if not inv:is_empty("src") then
local fuellist = inv:get_list("src")
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
if not fuel or fuel.time == 0 then
meta:set_string("infotext", "Generator out of fuel")
hacky_swap_node(pos, "technic:generator")
return
end
meta:set_int("burn_time", fuel.time)
meta:set_int("burn_totaltime", fuel.time)
local stack = inv:get_stack("src", 1)
stack:take_item()
inv:set_stack("src", 1, stack)
hacky_swap_node(pos, "technic:generator_active")
meta:set_int("LV_EU_supply", 200) -- Give 200EUs
else
hacky_swap_node(pos, "technic:generator")
meta:set_int("LV_EU_supply", 0)
end
end
local percent = math.floor((burn_time / burn_totaltime) * 100)
meta:set_string("infotext", "Electric Generator ("..percent.."%)")
meta:set_string("formspec",
"size[8,9]"..
"label[0,0;Generator]"..
"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;]")
end
})
technic.register_machine("LV", "technic:generator", technic.producer)
technic.register_machine("LV", "technic:generator_active", technic.producer)

View File

@ -0,0 +1,123 @@
-- 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_craft({
output = 'technic:geothermal',
recipe = {
{'default:stone', 'default:stone', 'default:stone'},
{'default:copper_ingot', 'default:diamond', 'default:copper_ingot'},
{'default:stone', 'default:copper_ingot', 'default:stone'},
}
})
minetest.register_craftitem("technic:geothermal", {
description = "Geothermal Generator",
stack_max = 99,
})
local geothermal_formspec =
"invsize[8,4;]"..
"label[0,0;Geothermal Generator]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:geothermal", {
description = "Geothermal Generator",
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"},
paramtype2 = "facedir",
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Geothermal Generator")
meta:set_float("technic_power_machine", 1)
meta:set_int("LV_EU_supply", 0)
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",
})
local check_node_around = function(pos)
local node = minetest.get_node(pos)
if node.name == "default:water_source" or node.name == "default:water_flowing" then return 1 end
if node.name == "default:lava_source" or node.name == "default:lava_flowing" then return 2 end
return 0
end
minetest.register_abm({
nodenames = {"technic:geothermal","technic:geothermal_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local water_nodes = 0
local lava_nodes = 0
local production_level = 0
local eu_supply = 0
-- Correct positioning is water on one side and lava on the other.
-- The two cannot be adjacent because the lava the turns into obsidian or rock.
-- To get to 100% production stack the water and lava one extra block down as well:
-- WGL (W=Water, L=Lava, G=the generator, |=an LV cable)
-- W|L
local positions = {
{x=pos.x+1, y=pos.y, z=pos.z},
{x=pos.x+1, y=pos.y-1, z=pos.z},
{x=pos.x-1, y=pos.y, z=pos.z},
{x=pos.x-1, y=pos.y-1, z=pos.z},
{x=pos.x, y=pos.y, z=pos.z+1},
{x=pos.x, y=pos.y-1, z=pos.z+1},
{x=pos.x, y=pos.y, z=pos.z-1},
{x=pos.x, y=pos.y-1, z=pos.z-1},
}
for _, p in pairs(positions) do
local check = check_node_around(p)
if check == 1 then water_nodes = water_nodes + 1 end
if check == 2 then lava_nodes = lava_nodes + 1 end
end
if water_nodes == 1 and lava_nodes == 1 then production_level = 25; eu_supply = 50 end
if water_nodes == 2 and lava_nodes == 1 then production_level = 50; eu_supply = 100 end
if water_nodes == 1 and lava_nodes == 2 then production_level = 75; eu_supply = 200 end
if water_nodes == 2 and lava_nodes == 2 then production_level = 100; eu_supply = 300 end
if production_level > 0 then
meta:set_int("LV_EU_supply", eu_supply)
end
meta:set_string("formspec",
"invsize[8,4;]"..
"label[0,0;Geothermal Generator]"..
"label[4,0;Production at "..tostring(production_level).."%]")
if production_level > 0 and minetest.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_machine("LV", "technic:geothermal", technic.producer)
technic.register_machine("LV", "technic:geothermal_active", technic.producer)

View File

@ -0,0 +1,13 @@
minetest.register_alias("grinder", "technic:grinder")
minetest.register_craft({
output = 'technic:grinder',
recipe = {
{'default:desert_stone', 'default:desert_stone', 'default:desert_stone'},
{'default:desert_stone', 'default:diamond', 'default:desert_stone'},
{'default:stone', 'moreores:copper_ingot', 'default:stone'},
}
})
technic.register_grinder({tier="LV", demand={200}, speed=1})

View File

@ -1,15 +1,18 @@
local path = technic.modpath.."/machines/lv"
dofile(path.."/wires.lua")
technic.register_tier("LV", "Low Voltage")
local path = technic.modpath.."/machines/LV"
dofile(path.."/cables.lua")
dofile(path.."/battery_box.lua")
dofile(path.."/alloy_furnace.lua")
dofile(path.."/coal_alloy_furnace.lua")
dofile(path.."/solar_panel.lua")
dofile(path.."/solar_array.lua")
dofile(path.."/geothermal.lua")
dofile(path.."/water_mill.lua")
dofile(path.."/generator.lua")
dofile(path.."/electric_furnace.lua")
dofile(path.."/tool_workshop.lua")
dofile(path.."/music_player.lua")
dofile(path.."/grinder.lua")
dofile(path.."/cnc.lua")
@ -17,3 +20,4 @@ dofile(path.."/cnc_api.lua")
dofile(path.."/cnc_nodes.lua")
dofile(path.."/extractor.lua")
dofile(path.."/compressor.lua")

View File

@ -0,0 +1,138 @@
-- LV Music player.
-- The player can play music. But it is high ampage!
minetest.register_alias("music_player", "technic:music_player")
minetest.register_craft({
output = 'technic:music_player',
recipe = {
{'group:wood', 'group:wood', 'group:wood'},
{'default:diamond', 'default:diamond', 'default:diamond'},
{'default:stone', 'default:copper_ingot', 'default:stone'},
}
})
local music_player_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 --]"
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.get_meta(pos)
meta:set_string("infotext", "Music Player")
meta:set_int("active", 0)
meta:set_int("current_track", 1)
meta:set_string("formspec", music_player_formspec)
end,
on_receive_fields = function(pos, formanme, fields, sender)
local meta = minetest.get_meta(pos)
local music_handle = meta:get_int("music_handle")
local current_track = meta:get_int("current_track")
if fields.track1 then current_track = 1 end
if fields.track2 then current_track = 2 end
if fields.track3 then current_track = 3 end
if fields.track4 then current_track = 4 end
if fields.track5 then current_track = 5 end
if fields.track6 then current_track = 6 end
if fields.track7 then current_track = 7 end
if fields.track8 then current_track = 8 end
if fields.track9 then current_track = 9 end
meta:set_int("current_track", 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 "
..current_track.."]")
if fields.play then
if music_handle then
minetest.sound_stop(music_handle)
end
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_abm({
nodenames = {"technic:music_player"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local eu_input = meta:get_int("LV_EU_input")
local machine_name = "Music Player"
local machine_node = "technic:music_player"
local demand = 150
local music_handle = meta:get_int("music_handle")
local current_track = meta:get_int("current_track")
-- Setup meta data if it does not exist.
if not eu_input then
meta:set_int("LV_EU_demand", demand)
meta:set_int("LV_EU_input", 0)
return
end
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
if meta:get_int("active") == 0 then
meta:set_string("infotext", machine_name.." Idle")
meta:set_int("LV_EU_demand", 0)
if music_handle then
minetest.sound_stop(music_handle)
end
return
end
if eu_input < demand then
meta:set_string("infotext", machine_name.." Unpowered")
if music_handle then
minetest.sound_stop(music_handle)
end
elseif eu_input >= demand then
meta:set_string("infotext", machine_name.." Active")
music_handle = minetest.sound_play("technic_track"..current_track,
{pos = pos, gain = 1.0, loop = true, max_hear_distance = 72,})
meta:set_int("music_handle", music_handle)
end
meta:set_int("LV_EU_demand", demand)
end
})
technic.register_machine("LV", "technic:music_player", technic.receiver)

View File

@ -0,0 +1,18 @@
-- The solar array is an assembly of panels into a powerful array
-- The assembly can deliver more energy than the individual panel because
-- of the transformer unit which converts the panel output variations into
-- a stable supply.
-- Solar arrays are not able to store large amounts of energy.
-- The LV arrays are used to make medium voltage arrays.
minetest.register_craft({
output = 'technic:solar_array_lv 1',
recipe = {
{'technic:solar_panel', 'technic:solar_panel', 'technic:solar_panel'},
{'default:steel_ingot', 'technic:lv_transformer', 'default:steel_ingot'},
{'', 'technic:lv_cable0', ''},
}
})
technic.register_solar_array({tier="LV", power=10})

View File

@ -0,0 +1,70 @@
-- Solar panels are the building blocks of LV solar arrays
-- They can however also be used separately but with reduced efficiency due to the missing transformer.
-- Individual panels are less efficient than when the panels are combined into full arrays.
minetest.register_node("technic:solar_panel", {
tiles = {"technic_solar_panel_top.png", "technic_solar_panel_bottom.png", "technic_solar_panel_side.png",
"technic_solar_panel_side.png", "technic_solar_panel_side.png", "technic_solar_panel_side.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
description="Solar Panel",
active = false,
drawtype = "nodebox",
paramtype = "light",
is_ground_content = true,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("LV_EU_supply", 0)
meta:set_string("infotext", "LV Solar Panel")
end,
})
minetest.register_craft({
output = 'technic:solar_panel',
recipe = {
{'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer'},
{'default:steel_ingot', 'technic:lv_cable0', 'default:steel_ingot'},
}
})
minetest.register_abm({
nodenames = {"technic:solar_panel"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- The action here is to make the solar panel prodice power
-- Power is dependent on the light level and the height above ground
-- 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 26EU.
-- 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.
-- To take care of some of it solar panels do not work outside daylight hours or if
-- built below -10m
local pos1 = {x=pos.x, y=pos.y+1, z=pos.z}
local light = minetest.get_node_light(pos1, nil)
local time_of_day = minetest.get_timeofday()
local meta = minetest.get_meta(pos)
if light == nil then light = 0 end
-- 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.
if light >= 12 and time_of_day >= 0.24 and time_of_day <= 0.76 and pos.y > -10 then
local charge_to_give = math.floor((light + pos1.y) * 3)
charge_to_give = math.max(charge_to_give, 0)
charge_to_give = math.min(charge_to_give, 200)
meta:set_string("infotext", "Solar Panel is active ("..charge_to_give.."EU)")
meta:set_int("LV_EU_supply", charge_to_give)
else
meta:set_string("infotext", "Solar Panel is inactive");
meta:set_int("LV_EU_supply", 0)
end
end,
})
technic.register_machine("LV", "technic:solar_panel", technic.producer)

View File

@ -0,0 +1,101 @@
-- 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_craft({
output = 'technic:water_mill',
recipe = {
{'default:stone', 'default:stone', 'default:stone'},
{'group:wood', 'default:diamond', 'group:wood'},
{'default:stone', 'default:copper_ingot', 'default:stone'},
}
})
minetest.register_node("technic:water_mill", {
description = "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"},
paramtype2 = "facedir",
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Water Mill")
meta:set_int("LV_EU_supply", 0)
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",
})
local function check_node_around_mill(pos)
local node = minetest.get_node(pos)
if node.name == "default:water_flowing" or
node.name == "default:water_source" then
return true
end
return false
end
minetest.register_abm({
nodenames = {"technic:water_mill", "technic:water_mill_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local water_nodes = 0
local lava_nodes = 0
local production_level = 0
local eu_supply = 0
local positions = {
{x=pos.x+1, y=pos.y, z=pos.z},
{x=pos.x-1, y=pos.y, z=pos.z},
{x=pos.x, y=pos.y, z=pos.z+1},
{x=pos.x, y=pos.y, z=pos.z-1},
}
for _, p in pairs(positions) do
local check = check_node_around_mill(p)
if check then
water_nodes = water_nodes + 1
end
end
production_level = 25 * water_nodes
eu_supply = 30 * water_nodes
if production_level > 0 then
meta:set_int("LV_EU_supply", eu_supply)
end
meta:set_string("infotext",
"Water Mill ("..production_level.."%)")
if production_level > 0 and
minetest.get_node(pos).name == "technic:water_mill" then
hacky_swap_node (pos, "technic:water_mill_active")
meta:set_int("LV_EU_supply", 0)
return
end
if production_level == 0 then
hacky_swap_node(pos, "technic:water_mill")
end
end
})
technic.register_machine("LV", "technic:water_mill", technic.producer)
technic.register_machine("LV", "technic:water_mill_active", technic.producer)

View File

@ -0,0 +1,14 @@
-- MV alloy furnace
minetest.register_craft({
output = 'technic:mv_alloy_furnace',
recipe = {
{'technic:stainless_steel_ingot', 'technic:lv_alloy_furnace', 'technic:stainless_steel_ingot'},
{'pipeworks:tube_000000', 'technic:mv_transformer', 'pipeworks:tube_000000'},
{'technic:stainless_steel_ingot', 'technic:mv_cable0', 'technic:stainless_steel_ingot'},
}
})
technic.register_alloy_furnace({tier="MV", cook_time=4, upgrade=1, tube=1, demand={3000, 2000, 1000}})

View File

@ -0,0 +1,20 @@
-- MV Battery box
minetest.register_craft({
output = 'technic:mv_battery_box0',
recipe = {
{'technic:lv_battery_box0', 'technic:lv_battery_box0', 'technic:lv_battery_box0'},
{'technic:lv_battery_box0', 'technic:mv_transformer', 'technic:lv_battery_box0'},
{'', 'technic:mv_cable0', ''},
}
})
technic.register_battery_box({
tier = "MV",
max_charge = 300000,
charge_rate = 20000,
discharge_rate = 80000,
charge_step = 2000,
discharge_step = 8000,
})

View File

@ -0,0 +1,14 @@
minetest.register_alias("mv_cable", "technic:mv_cable0")
minetest.register_craft({
output = 'technic:mv_cable0 3',
recipe ={
{'technic:rubber', 'technic:rubber', 'technic:rubber'},
{'technic:lv_cable0', 'technic:lv_cable0', 'technic:lv_cable0'},
{'technic:rubber', 'technic:rubber', 'technic:rubber'},
}
})
technic.register_cable("MV", 2.5/16)

View File

@ -0,0 +1,18 @@
-- MV Electric Furnace
-- This is a faster version of the stone furnace which runs on EUs
-- In addition to this it can be upgraded with microcontrollers and batteries
-- This new version uses the batteries to lower the power consumption of the machine
-- Also in addition this furnace can be attached to the pipe system from the pipeworks mod.
-- 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:lv_electric_furnace', 'technic:stainless_steel_ingot'},
{'pipeworks:tube_000000', 'technic:mv_transformer', 'pipeworks:tube_000000'},
{'technic:stainless_steel_ingot', 'technic:mv_cable0', 'technic:stainless_steel_ingot'},
}
})
technic.register_electric_furnace({tier="MV", upgrade=1, tube=1, demand={2000, 1000, 500}, speed=4})

View File

@ -0,0 +1,13 @@
-- MV grinder
minetest.register_craft({
output = 'technic:mv_grinder',
recipe = {
{'technic:stainless_steel_ingot', 'technic:lv_grinder', 'technic:stainless_steel_ingot'},
{'pipeworks:tube_000000', 'technic:mv_transformer', 'pipeworks:tube_000000'},
{'technic:stainless_steel_ingot', 'technic:mv_cable0', 'technic:stainless_steel_ingot'},
}
})
technic.register_grinder({tier="MV", demand={600, 450, 300}, speed=2, upgrade=1, tube=1})

View File

@ -1,11 +1,16 @@
local path = technic.modpath.."/machines/mv"
dofile(path.."/wires.lua")
dofile(path.."/battery_box.lua")
dofile(path.."/solar_array.lua")
dofile(path.."/electric_furnace.lua")
technic.register_tier("MV", "Medium Voltage")
local path = technic.modpath.."/machines/MV"
dofile(path.."/alloy_furnace.lua")
dofile(path.."/battery_box.lua")
dofile(path.."/cables.lua")
dofile(path.."/electric_furnace.lua")
dofile(path.."/grinder.lua")
dofile(path.."/solar_array.lua")
dofile(path.."/tool_workshop.lua")
dofile(path.."/wind_mill.lua")
-- The power radiator supplies appliances with inductive coupled power:
-- Lighting and associated textures is taken directly from VanessaE's homedecor and made electric.

View File

@ -6,20 +6,20 @@
-- 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())
dofile(minetest.get_modpath("intllib").."/intllib.lua")
S = intllib.Getter(minetest.get_current_modname())
else
S = function ( s ) return s end
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 type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
if HasOwner(pos, placer) then
if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
if type(getLastOwner) == "function" then -- ...is an old version
if type(getLastOwner) == "function" then -- ...is an old version
ownername = getLastOwner(pos)
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
ownername = GetNodeOwnerName(pos)
else
ownername = S("someone")
@ -27,38 +27,38 @@ function technic_homedecor_node_is_owned(pos, placer)
end
end
elseif type(isprotect)=="function" then -- glomie's protection mod
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
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) )
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 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)
local node = minetest.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 pname = minetest.get_node(under).name
local node = minetest.get_node(above)
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
local wield_name = itemstack:get_name()
@ -74,14 +74,14 @@ local technic_homedecor_rotate_and_place = function(itemstack, placer, pointed_t
iswall = false
end
if not minetest.registered_nodes[minetest.env:get_node(pos1).name]["buildable_to"] then return end
if not minetest.registered_nodes[minetest.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
minetest.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
minetest.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
minetest.add_node(pos1, {name = wield_name, param2 = 0 }) -- place right side up
end
if not homedecor_expect_infinite_stacks then

View File

@ -0,0 +1,220 @@
-- 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.06
-- Using inductive power transfer is very inefficient so this is
-- set to the factor 0.06.
--
-- Punching the radiator will toggle the power state of all attached appliances.
local power_radius = 12
------------------------------------------------------------------
-- 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.get_meta(pos)
meta:set_string("infotext", infotext)
meta:set_int("technic_inductive_power_machine", 1)
meta:set_int("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.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("EU_charge: "..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.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("EU_charge: "..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 = power_radius
-- 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.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 pairs(positions) do
local meta1 = minetest.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.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
local toggle_on_off_inductive_appliances = function(pos, node, puncher)
if pos == nil then return end
-- The supply radius
local rad = power_radius
local positions = minetest.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 pairs(positions) do
local meta1 = minetest.get_meta(pos1)
if meta1:get_string("has_supply") == pos.x..pos.y..pos.z then
minetest.punch_node(pos1)
end
end
end
minetest.register_node("technic:power_radiator", {
description = "Power Radiator",
tiles = {"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png",
"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.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},
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
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")
end,
on_dig = function(pos, node, digger)
shutdown_inductive_appliances(pos)
return minetest.node_dig(pos, node, digger)
end,
on_punch = function(pos, node, puncher)
toggle_on_off_inductive_appliances(pos, node, puncher)
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_cable0', '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)
meta:set_int("connected_EU_demand", 0)
meta:set_int("MV_EU_demand",1)
elseif eu_input == eu_demand then
-- Powered and ready
-- The maximum EU sourcing a single radiator can provide.
local max_charge = 30000 -- == the max EU demand of the radiator
local connected_EU_demand = meta:get_int("connected_EU_demand")
-- Efficiency factor
local eff_factor = 0.06
-- The supply radius
local rad = power_radius
local meta1 = nil
local pos1 = {}
local used_charge = 0
-- Index all nodes within supply range
local positions = minetest.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 pairs(positions) do
local meta1 = minetest.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 = math.floor(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)
--Always 0: 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 = used_charge + math.floor(meta1:get_int("EU_charge") / eff_factor)
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
end
-- Save state
meta:set_int("connected_EU_demand", connected_EU_demand)
end
end,
})
technic.register_machine("MV", "technic:power_radiator", technic.receiver)

View File

@ -0,0 +1,12 @@
minetest.register_craft({
output = 'technic:solar_array_mv 1',
recipe = {
{'technic:solar_array_lv', 'technic:solar_array_lv', 'technic:solar_array_lv'},
{'default:steel_ingot', 'technic:mv_transformer', 'default:steel_ingot'},
{'', 'technic:mv_cable0', ''},
}
})
technic.register_solar_array({tier="MV", power=30})

View File

@ -0,0 +1,90 @@
-- LV Tool workshop
-- This machine repairs tools.
minetest.register_alias("tool_workshop", "technic:tool_workshop")
minetest.register_craft({
output = 'technic:tool_workshop',
recipe = {
{'group:wood', 'group:wood', 'group:wood'},
{'group:wood', 'default:diamond', 'group:wood'},
{'default:stone', 'default:copper_ingot', 'default:stone'},
}
})
local workshop_formspec =
"invsize[8,9;]"..
"list[current_name;src;3,1;1,1;]"..
"label[0,0;Tool Workshop]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:tool_workshop", {
description = "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"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Tool Workshop")
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", workshop_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
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,
})
minetest.register_abm({
nodenames = {"technic:tool_workshop"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local eu_input = meta:get_int("MV_EU_input")
local machine_name = "Tool Workshop"
local machine_node = "technic:tool_workshop"
local demand = 5000
-- Setup meta data if it does not exist.
if not eu_input then
meta:set_int("MV_EU_demand", demand)
meta:set_int("MV_EU_input", 0)
return
end
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "MV")
srcstack = inv:get_stack("src", 1)
if inv:is_empty("src") or
srcstack:get_wear() == 0 or
srcstack:get_name() == "technic:water_can" or
srcstack:get_name() == "technic:lava_can" then
meta:set_string("infotext", machine_name.." Idle")
meta:set_int("MV_EU_demand", 0)
return
end
if eu_input < demand then
meta:set_string("infotext", machine_name.." Unpowered")
elseif eu_input >= demand then
meta:set_string("infotext", machine_name.." Active")
srcstack:add_wear(-1000)
inv:set_stack("src", 1, srcstack)
end
meta:set_int("MV_EU_demand", demand)
end
})
technic.register_machine("MV", "technic:tool_workshop", technic.receiver)

View File

@ -0,0 +1,88 @@
minetest.register_craft({
output = 'technic:wind_mill_frame 5',
recipe = {
{'default:steel_ingot', '', 'default:steel_ingot'},
{'', 'default:steel_ingot', ''},
{'default:steel_ingot', '', 'default:steel_ingot'},
}
})
minetest.register_craft({
output = 'technic:wind_mill',
recipe = {
{'', 'default:steel_ingot', ''},
{'default:steel_ingot', 'technic:motor', 'default:steel_ingot'},
{'', 'default:steelblock', ''},
}
})
minetest.register_node("technic:wind_mill_frame", {
description = "Wind Mill Frame",
drawtype = "glasslike_framed",
tiles = {"default_steel_block.png", "default_glass.png"},
sunlight_propagates = true,
groups = {cracky=3},
sounds = default.node_sound_stone_defaults(),
paramtype = "light",
})
minetest.register_node("technic:wind_mill", {
description = "Wind Mill",
tiles = {"default_steel_block.png"},
paramtype2 = "facedir",
groups = {cracky=1},
sounds = default.node_sound_stone_defaults(),
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {
{-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, -- Main box
{-0.1, -0.1, -0.5, 0.1, 0.1, -0.6}, -- Shaft
{-0.1, -1, -0.6, 0.1, 1, -0.7}, -- Vertical blades
{-1, -0.1, -0.6, 1, 0.1, -0.7}, -- Horizontal blades
}
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Wind Mill")
meta:set_int("MV_EU_supply", 0)
end,
})
local function check_wind_mill(pos)
if pos.y < 30 then
return false
end
for i = 1, 20 do
local node = minetest.get_node({x=pos.x, y=pos.y-i, z=pos.z})
if node.name ~= "technic:wind_mill_frame" then
return false
end
end
return true
end
minetest.register_abm({
nodenames = {"technic:wind_mill"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.get_meta(pos)
local power = math.min(pos.y * 100, 5000)
if not check_wind_mill(pos) then
meta:set_int("MV_EU_supply", 0)
meta:set_string("infotext", "Wind Mill Inproperly Placed")
return
else
meta:set_int("MV_EU_supply", power)
end
meta:set_string("infotext", "Wind Mill ("..power.."EU)")
end
})
technic.register_machine("MV", "technic:wind_mill", technic.producer)

View File

@ -1,85 +0,0 @@
-- Register alloy recipes
technic.alloy_recipes = {}
-- 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)
alloy_recipes[registered_recipes_count]={}
alloy_recipes[registered_recipes_count].src1_name=string1
alloy_recipes[registered_recipes_count].src1_count=count1
alloy_recipes[registered_recipes_count].src2_name=string2
alloy_recipes[registered_recipes_count].src2_count=count2
alloy_recipes[registered_recipes_count].dst_name=string3
alloy_recipes[registered_recipes_count].dst_count=count3
registered_recipes_count=registered_recipes_count+1
alloy_recipes[registered_recipes_count]={}
alloy_recipes[registered_recipes_count].src1_name=string2
alloy_recipes[registered_recipes_count].src1_count=count2
alloy_recipes[registered_recipes_count].src2_name=string1
alloy_recipes[registered_recipes_count].src2_count=count1
alloy_recipes[registered_recipes_count].dst_name=string3
alloy_recipes[registered_recipes_count].dst_count=count3
registered_recipes_count=registered_recipes_count+1
if unified_inventory then
unified_inventory.register_craft({
type = "alloy",
output = string3.." "..count3,
items = {string1.." "..count1,string2.." "..count2},
width = 2,
})
end
end
register_alloy_recipe ("technic:copper_dust",3, "technic:tin_dust",1, "technic:bronze_dust",4)
register_alloy_recipe ("default:copper_ingot",3, "moreores:tin_ingot",1, "default:bronze_ingot",4)
register_alloy_recipe ("technic:iron_dust",3, "technic:chromium_dust",1, "technic:stainless_steel_dust",4)
register_alloy_recipe ("default:steel_ingot",3, "technic:chromium_ingot",1, "technic:stainless_steel_ingot",4)
register_alloy_recipe ("technic:copper_dust",2, "technic:zinc_dust",1, "technic:brass_dust",3)
register_alloy_recipe ("default:copper_ingot",2, "technic:zinc_ingot",1, "technic:brass_ingot",3)
register_alloy_recipe ("default:sand",2, "technic:coal_dust",2, "technic:silicon_wafer",1)
register_alloy_recipe ("technic:silicon_wafer",1, "technic:gold_dust",1, "technic:doped_silicon_wafer",1)

View File

@ -1,80 +0,0 @@
charge_tools = function(meta, charge, step)
--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 technic.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 charging
local item_max_charge = technic.power_tools[toolname]
local load = src_meta["charge"]
local load_step = step -- 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
discharge_tools = function(meta, charge, max_charge, step)
-- 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 technic.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 = technic.power_tools[toolname]
local load = src_meta["charge"]
local load_step = step -- 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

View File

@ -1,55 +0,0 @@
technic.register_grinder_recipe("glooptest:alatro_lump","technic:alatro_dust 2")
technic.register_grinder_recipe("glooptest:kalite_lump","technic:kalite_dust 2")
technic.register_grinder_recipe("glooptest:arol_lump","technic:arol_dust 2")
technic.register_grinder_recipe("glooptest:talinite_lump","technic:talinite_dust 2")
technic.register_grinder_recipe("glooptest:akalin_lump","technic:akalin_dust 2")
 
minetest.register_craftitem("technic:alatro_dust", {
        description = "Alatro Dust",
        inventory_image = "technic_alatro_dust.png",
})
 
minetest.register_craft({
    type = "cooking",
    output = "glooptest:alatro_ingot",
    recipe = "technic:alatro_dust",
})
 
minetest.register_craftitem("technic:arol_dust", {
        description = "Arol Dust",
        inventory_image = "technic_arol_dust.png",
})
 
minetest.register_craft({
    type = "cooking",
    output = "glooptest:arol_ingot",
    recipe = "technic:arol_dust",
})
 
minetest.register_craftitem("technic:talinite_dust", {
        description = "Talinite Dust",
        inventory_image = "technic_talinite_dust.png",
})
 
minetest.register_craft({
    type = "cooking",
    output = "glooptest:talinite_ingot",
    recipe = "technic:talinite_dust",
})
 
minetest.register_craftitem("technic:akalin_dust", {
        description = "Akalin Dust",
        inventory_image = "technic_akalin_dust.png",
})
 
minetest.register_craft({
    type = "cooking",
    output = "glooptest:akalin_ingot",
    recipe = "technic:akalin_dust",
})
 
minetest.register_craftitem("technic:kalite_dust", {
        description = "Kalite Dust",
        inventory_image = "technic_kalite_dust.png",
        on_use = minetest.item_eat(2)
})

View File

@ -1,157 +0,0 @@
local max_charge = 1500000
local max_charge_rate = 3000
local max_discharge_rate = 5000
-- HV battery box
minetest.register_craft({
output = 'technic:hv_battery_box 1',
recipe = {
{'technic:mv_battery_box', 'technic:mv_battery_box', 'technic:mv_battery_box'},
{'technic:mv_battery_box', 'technic:hv_transformer', 'technic:mv_battery_box'},
{'', 'technic:hv_cable', ''},
}
})
local battery_box_formspec =
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;1,1;]"..
"label[0,0;HV Battery Box]"..
"label[3,0;Charge]"..
"label[5,0;Discharge]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]"..
"background[-0.19,-0.25;8.4,9.75;ui_form_bg.png]"..
"background[0,0;8,4;ui_hv_battery_box.png]"..
"background[0,5;8,4;ui_main_inventory.png]"
minetest.register_node("technic:hv_battery_box", {
description = "HV Battery Box",
tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png",
"technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png",
"technic_hv_battery_box_side0.png", "technic_hv_battery_box_side0.png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
drop = "technic:hv_battery_box",
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
meta:set_string("infotext", "HV Battery Box")
meta:set_float("technic_hv_power_machine", 1)
meta:set_string("formspec", battery_box_formspec)
meta:set_int("HV_EU_demand", 0) -- How much this node can charge
meta:set_int("HV_EU_supply", 0) -- How much this node can discharge
meta:set_int("HV_EU_input", 0) -- How much power this machine is getting.
meta:set_float("internal_EU_charge", 0)
inv:set_size("src", 1)
inv:set_size("dst", 1)
end,
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,
})
for i = 1,8,1 do
minetest.register_node("technic:hv_battery_box"..i, {
description = "HV Battery Box",
tiles = {"technic_hv_battery_box_top.png", "technic_hv_battery_box_bottom.png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_hv_battery_box_side0.png^technic_power_meter"..i..".png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
paramtype="light",
light_source=9,
drop="technic:hv_battery_box",
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_abm({
nodenames = {"technic:hv_battery_box", "technic:hv_battery_box1", "technic:hv_battery_box2",
"technic:hv_battery_box3", "technic:hv_battery_box4", "technic:hv_battery_box5",
"technic:hv_battery_box6", "technic:hv_battery_box7", "technic:hv_battery_box8"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local 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_tools(meta, current_charge, 16000)
current_charge = discharge_tools(meta, current_charge, max_charge, 16000)
-- 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)
-- Select node textures
local charge_count = math.ceil((current_charge / max_charge) * 8)
if charge_count > 8 then
charge_count = 8
end
local last_count = meta:get_float("last_side_shown")
if charge_count ~= last_count then
if charge_count > 0 then
hacky_swap_node(pos,"technic:hv_battery_box"..charge_count)
else
hacky_swap_node(pos,"technic:hv_battery_box")
end
meta:set_float("last_side_shown", charge_count)
end
local charge_percent = math.floor(current_charge / max_charge * 100)
meta:set_string("formspec",
battery_box_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"
..charge_percent..":technic_power_meter_fg.png]")
if eu_input == 0 then
meta:set_string("infotext", "HV Battery box: "..current_charge.."/"..max_charge.." (idle)")
else
meta:set_string("infotext", "HV Battery box: "..current_charge.."/"..max_charge)
end
end
})
-- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power
technic.register_HV_machine("technic:hv_battery_box","BA")
for i=1,8,1 do
technic.register_HV_machine("technic:hv_battery_box"..i,"BA")
end

View File

@ -1,228 +0,0 @@
-- Forcefield mod by ShadowNinja
-- Modified by kpoppel
--
-- Forcefields are powerful barriers but they consume huge amounts of power.
-- Forcefield Generator is a HV machine.
-- How expensive is the generator? Leaves room for upgrades lowering the power drain?
local forcefield_power_drain = 10
local forcefield_step_interval = 1
minetest.register_craft({
output = 'technic:forcefield_emitter_off',
recipe = {
{'default:mese', 'technic:deployer_off', 'default:mese' },
{'technic:deployer_off', 'technic:motor', 'technic:deployer_off'},
{'default:mese', 'technic:deployer_off', 'default:mese' },
}
})
-- Idea: Let forcefields have different colors by upgrade slot.
-- Idea: Let forcefields add up by detecting if one hits another.
-- ___ __
-- / \/ \
-- | |
-- \___/\___/
local function update_forcefield(pos, range, active)
local vm = VoxelManip()
local p1 = {x = pos.x-range, y = pos.y-range, z = pos.z-range}
local p2 = {x = pos.x+range, y = pos.y+range, z = pos.z+range}
local MinEdge, MaxEdge = vm:read_from_map(p1, p2)
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
local data = vm:get_data()
local c_air = minetest.get_content_id("air")
local c_field = minetest.get_content_id("technic:forcefield")
for z=-range, range do
for y=-range, range do
local vi = area:index(pos.x+(-range), pos.y+y, pos.z+z)
for x=-range, range do
if x*x+y*y+z*z <= range * range + range and
x*x+y*y+z*z >= (range-1) * (range-1) + (range-1) and
((active and data[vi] == c_air) or ((not active) and data[vi] == c_field)) then
if active then
data[vi] = c_field
else
data[vi] = c_air
end
end
vi = vi + 1
end
end
end
vm:set_data(data)
vm:update_liquids()
vm:write_to_map()
vm:update_map()
end
local get_forcefield_formspec = function(range)
return "invsize[3,4;]"..
"label[0,0;Forcefield emitter]"..
"label[1,1;Range]"..
"label[1,2;"..range.."]"..
"button[0,2;1,1;subtract;-]"..
"button[2,2;1,1;add;+]"..
"button[0,3;3,1;toggle;Enable/Disable]"
end
local forcefield_receive_fields = function(pos, formname, fields, sender)
local meta = minetest.env:get_meta(pos)
local range = meta:get_int("range")
if fields.add then range = range + 1 end
if fields.subtract then range = range - 1 end
if fields.toggle then
if meta:get_int("enabled") == 1 then
meta:set_int("enabled", 0)
else
meta:set_int("enabled", 1)
end
end
-- Smallest field is 5. Anything less is asking for trouble.
-- Largest is 20. It is a matter of pratical node handling.
if range < 5 then range = 5 end
if range > 20 then range = 20 end
if range <= 20 and range >= 5 and meta:get_int("range") ~= range then
update_forcefield(pos, meta:get_int("range"), false)
meta:set_int("range", range)
meta:set_string("formspec", get_forcefield_formspec(range))
end
end
local function forcefield_step(pos)
local meta = minetest.env:get_meta(pos)
local node = minetest.env:get_node(pos)
local eu_input = meta:get_int("HV_EU_input")
local eu_demand = meta:get_int("HV_EU_demand")
local enabled = meta:get_int("enabled")
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "HV")
local power_requirement = 0
if enabled == 1 then
power_requirement = math.floor(
4 * math.pi * math.pow(meta:get_int("range"), 2)
) * forcefield_power_drain
else
power_requirement = eu_demand
end
if meta:get_int("enabled") == 0 then
if node.name == "technic:forcefield_emitter_on" then
update_forcefield(pos, meta:get_int("range"), false)
hacky_swap_node(pos, "technic:forcefield_emitter_off")
meta:set_int("HV_EU_demand", 100)
meta:set_string("infotext", "Forcefield Generator Disabled")
end
elseif eu_input < power_requirement then
meta:set_string("infotext", "Forcefield Generator Unpowered")
if node.name == "technic:forcefield_emitter_on" then
update_forcefield(pos, meta:get_int("range"), false)
hacky_swap_node(pos, "technic:forcefield_emitter_off")
end
elseif eu_input >= power_requirement then
if node.name == "technic:forcefield_emitter_off" then
hacky_swap_node(pos, "technic:forcefield_emitter_on")
meta:set_string("infotext", "Forcefield Generator Active")
end
update_forcefield(pos, meta:get_int("range"), true)
end
meta:set_int("HV_EU_demand", power_requirement)
return true
end
local mesecons = {
effector = {
action_on = function(pos, node)
minetest.env:get_meta(pos):set_int("enabled", 0)
end,
action_off = function(pos, node)
minetest.env:get_meta(pos):set_int("enabled", 1)
end
}
}
minetest.register_node("technic:forcefield_emitter_off", {
description = "Forcefield emitter",
inventory_image = minetest.inventorycube("technic_forcefield_emitter_off.png"),
tiles = {"technic_forcefield_emitter_off.png"},
is_ground_content = true,
groups = {cracky = 1},
on_timer = forcefield_step,
on_receive_fields = forcefield_receive_fields,
on_construct = function(pos)
minetest.env:get_node_timer(pos):start(forcefield_step_interval)
local meta = minetest.env:get_meta(pos)
meta:set_float("technic_hv_power_machine", 1)
meta:set_int("HV_EU_input", 0)
meta:set_int("HV_EU_demand", 0)
meta:set_int("range", 10)
meta:set_int("enabled", 0)
meta:set_string("formspec", get_forcefield_formspec(meta:get_int("range")))
meta:set_string("infotext", "Forcefield emitter");
end,
mesecons = mesecons
})
minetest.register_node("technic:forcefield_emitter_on", {
description = "Forcefield emitter on (you hacker you)",
tiles = {"technic_forcefield_emitter_on.png"},
is_ground_content = true,
groups = {cracky = 1, not_in_creative_inventory=1},
drop='"technic:forcefield_emitter_off" 1',
on_timer = forcefield_step,
on_receive_fields = forcefield_receive_fields,
on_construct = function(pos)
minetest.env:get_node_timer(pos):start(forcefield_step_interval)
local meta = minetest.env:get_meta(pos)
-- meta:set_float("technic_hv_power_machine", 1)
-- meta:set_float("HV_EU_input", 0)
-- meta:set_float("HV_EU_demand", 0)
-- meta:set_int("range", 10)
-- meta:set_int("enabled", 1)
meta:set_string("formspec", get_forcefield_formspec(meta:get_int("range")))
-- meta:set_string("infotext", "Forcefield emitter");
end,
on_dig = function(pos, node, digger)
update_forcefield(pos, minetest.env:get_meta(pos):get_int("range"), false)
return minetest.node_dig(pos, node, digger)
end,
mesecons = mesecons
})
minetest.register_node("technic:forcefield", {
description = "Forcefield (you hacker you)",
sunlight_propagates = true,
drop = '',
light_source = 8,
tiles = {{
name = "technic_forcefield_animated.png",
animation = {
type = "vertical_frames",
aspect_w=16,
aspect_h=16,
length=2.0,
},
}},
is_ground_content = true,
groups = { not_in_creative_inventory=1, unbreakable=1 },
paramtype = "light",
drawtype = "nodebox",
node_box = { --hacky way to get the field blue and not see through the ground
type = "fixed",
fixed={
{-.5,-.5,-.5,.5,.5,.5},
},
},
})
technic.register_HV_machine("technic:forcefield_emitter_on", "RE")
technic.register_HV_machine("technic:forcefield_emitter_off", "RE")

View File

@ -1,8 +0,0 @@
local path = technic.modpath.."/machines/hv"
dofile(path.."/forcefield.lua")
dofile(path.."/wires.lua")
dofile(path.."/battery_box.lua")
dofile(path.."/solar_array.lua")
dofile(path.."/nuclear_reactor.lua")

View File

@ -1,78 +0,0 @@
-- The high voltage solar array is an assembly of medium voltage arrays.
-- The assembly can deliver high voltage levels and is a 20% less efficient
-- compared to 5 individual medium voltage arrays due to losses in the transformer.
-- However high voltage is supplied.
-- Solar arrays are not able to store large amounts of energy.
minetest.register_node("technic:solar_array_hv", {
tiles = {"technic_hv_solar_array_top.png", "technic_hv_solar_array_bottom.png", "technic_hv_solar_array_side.png",
"technic_hv_solar_array_side.png", "technic_hv_solar_array_side.png", "technic_hv_solar_array_side.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
description="HV Solar Array",
active = false,
drawtype = "nodebox",
paramtype = "light",
is_ground_content = true,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_float("technic_hv_power_machine", 1)
meta:set_int("HV_EU_supply", 0)
meta:set_string("infotext", "HV Solar Array")
end,
})
minetest.register_craft(
{output = 'technic:solar_array_hv 1',
recipe = {
{'technic:solar_array_mv', 'technic:solar_array_mv','technic:solar_array_mv'},
{'technic:solar_array_mv', 'technic:hv_transformer','technic:solar_array_mv'},
{'default:steel_ingot', 'technic:hv_cable', 'default:steel_ingot'},
}
})
minetest.register_abm(
{nodenames = {"technic:solar_array_hv"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- The action here is to make the solar array produce power
-- Power is dependent on the light level and the height above ground
-- 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 2880EU for the array.
-- 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.
-- To take care of some of it solar panels do not work outside daylight hours or if
-- built below -10m
local pos1={}
pos1.y=pos.y+1
pos1.x=pos.x
pos1.z=pos.z
local light = minetest.env:get_node_light(pos1, nil)
local time_of_day = minetest.env:get_timeofday()
local meta = minetest.env:get_meta(pos)
if light == nil then light = 0 end
-- turn on array only during day time and if sufficient light
-- 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
local charge_to_give = math.floor(light*(light*9.6+pos1.y/130*48))
if charge_to_give<0 then charge_to_give=0 end
if charge_to_give>2880 then charge_to_give=2880 end
meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
meta:set_int("HV_EU_supply", charge_to_give)
else
meta:set_string("infotext", "Solar Array is inactive");
meta:set_int("HV_EU_supply", 0)
end
end,
})
technic.register_HV_machine ("technic:solar_array_hv","PR")

View File

@ -1,398 +0,0 @@
--HV cable node boxes
minetest.register_craft({
output = 'technic:hv_cable 3',
recipe ={
{'technic:rubber','technic:rubber','technic:rubber'},
{'technic:mv_cable','technic:mv_cable','technic:mv_cable'},
{'technic:rubber','technic:rubber','technic:rubber'},
}
})
minetest.register_craftitem("technic:hv_cable", {
description = "Gigh Voltage Copper Cable",
stack_max = 99,
})
minetest.register_node("technic:hv_cable", {
description = "High Voltage Copper Cable",
tiles = {"technic_hv_cable.png"},
inventory_image = "technic_hv_cable_wield.png",
wield_image = "technic_hv_cable_wield.png",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
drop = "technic:hv_cable",
hv_cablelike=1,
rules_x1=0,
rules_x2=0,
rules_y1=0,
rules_y2=0,
rules_z1=0,
rules_z2=0,
paramtype = "light",
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {
{ -0.1 , -0.1 , -0.1 , 0.1 , 0.1 , 0.1 },
}},
node_box = {
type = "fixed",
fixed = {
{ -0.125 , -0.125 , -0.125 , 0.125 , 0.125 , 0.125 },
}},
on_construct = function(pos)
meta=minetest.env:get_meta(pos)
meta:set_float("hv_cablelike",1)
meta:set_float("x1",0)
meta:set_float("x2",0)
meta:set_float("y1",0)
meta:set_float("y2",0)
meta:set_float("z1",0)
meta:set_float("z2",0)
HV_check_connections (pos)
end,
after_dig_node = function (pos, oldnode, oldmetadata, digger)
HV_check_connections_on_destroy (pos)
end,
})
str_y1= { -0.125 , -0.125 , -0.125 , 0.125 , 0.5, 0.125 } --0 y+
str_x1= { -0.125 , -0.125 , -0.125 , 0.5, 0.125 , 0.125 } --0 x+
str_z1= { -0.125 , -0.125 , 0.125 , 0.125 , 0.125 , 0.5 } --0 z+
str_z2= { -0.125 , -0.125, -0.5 , 0.125 , 0.125 , 0.125 } --0 z-
str_y2= { -0.125 , -0.5, -0.125 , 0.125 , 0.125 , 0.125 } --0 y-
str_x2= { -0.5 , -0.125, -0.125 , 0.125 , 0.125 , 0.125 } --0 x-
local x1,x2,y1,y2,z1,z2
local count=0
for x1 = 0, 1, 1 do --x-
for x2 = 0, 1, 1 do --x+
for y1 = 0, 1, 1 do --y-
for y2 = 0, 1, 1 do --y-
for z1 = 0, 1, 1 do --z-
for z2 = 0, 1, 1 do --z+
temp_x1={} temp_x2={} temp_y1={} temp_y2={} temp_z1={} temp_z2={}
if x1==1 then temp_x1=str_x1 end
if x2==1 then temp_x2=str_x2 end
if y1==1 then temp_y1=str_y1 end
if y2==1 then temp_y2=str_y2 end
if z1==1 then temp_z1=str_z1 end
if z2==1 then temp_z2=str_z2 end
minetest.register_node("technic:hv_cable"..count, {
description = "High Voltage Copper Cable",
tiles = {"technic_hv_cable.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
drop = "technic:hv_cable",
rules_x1=0,
rules_x2=0,
rules_y1=0,
rules_y2=0,
rules_z1=0,
rules_z2=0,
cablelike=1,
paramtype = "light",
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {
temp_x1,temp_x2,temp_y1,temp_y2,temp_z1,temp_z2,
}},
node_box = {
type = "fixed",
fixed = {
temp_x1,temp_x2,temp_y1,temp_y2,temp_z1,temp_z2,
}},
after_dig_node = function (pos, oldnode, oldmetadata, digger)
HV_check_connections_on_destroy (pos)
end,
})
count=count+1 end end end end end end
HV_check_connections = function(pos)
local pos1={}
pos1.x=pos.x
pos1.y=pos.y
pos1.z=pos.z
pos1.x=pos1.x+1
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
x2=1
x1=minetest.env:get_meta(pos1):get_float("x1")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:hv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("x2",x2)
meta=minetest.env:get_meta(pos)
x1=1
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("x1",x1)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:hv_cable"..rule)
end
pos1.x=pos1.x-2
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
x1=1
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:hv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("x1",x1)
meta=minetest.env:get_meta(pos)
x2=1
x1=minetest.env:get_meta(pos):get_float("x1")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("x2",x2)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:hv_cable"..rule)
end
pos1.x=pos1.x+1
pos1.y=pos1.y+1
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
y2=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:hv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("y2",y2)
meta=minetest.env:get_meta(pos)
y1=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("y1",y1)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:hv_cable"..rule)
end
if minetest.env:get_meta(pos1):get_float("technic_hv_power_machine")==1 then
y1=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:hv_cable"..rule)
meta=minetest.env:get_meta(pos)
meta:set_float("y1",y1)
end
pos1.y=pos1.y-2
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
y1=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:hv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("y1",y1)
meta=minetest.env:get_meta(pos)
y2=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("y2",y2)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:hv_cable"..rule)
end
pos1.y=pos1.y+1
pos1.z=pos1.z+1
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
z2=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:hv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("z2",z2)
meta=minetest.env:get_meta(pos)
z1=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("z1",z1)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:hv_cable"..rule)
end
pos1.z=pos1.z-2
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
z1=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:hv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("z1",z1)
meta=minetest.env:get_meta(pos)
z2=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
meta:set_float("z2",z2)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:hv_cable"..rule)
end
pos1.z=pos1.z+1
end
HV_check_connections_on_destroy = function(pos)
local pos1={}
pos1.x=pos.x
pos1.y=pos.y
pos1.z=pos.z
pos1.x=pos1.x+1
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
x2=0
x1=minetest.env:get_meta(pos1):get_float("x1")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("x2",x2)
end
pos1.x=pos1.x-2
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
x1=0
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("x1",x1)
end
pos1.x=pos1.x+1
pos1.y=pos1.y+1
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
y2=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("y2",y2)
end
pos1.y=pos1.y-2
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
y1=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("y1",y1)
end
pos1.y=pos1.y+1
pos1.z=pos1.z+1
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
z2=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("z2",z2)
end
pos1.z=pos1.z-2
if minetest.env:get_meta(pos1):get_float("hv_cablelike")==1 then
z1=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:hv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:hv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("z1",z1)
end
pos1.y=pos1.y+1
end

View File

@ -1,11 +1,14 @@
local path = technic.modpath.."/machines"
dofile(path.."/register/init.lua")
-- Tiers
dofile(path.."/LV/init.lua")
dofile(path.."/MV/init.lua")
dofile(path.."/HV/init.lua")
dofile(path.."/switching_station.lua")
dofile(path.."/supply_converter.lua")
dofile(path.."/alloy_furnaces_commons.lua")
dofile(path.."/battery_boxes_commons.lua")
dofile(path.."/lv/init.lua")
dofile(path.."/mv/init.lua")
dofile(path.."/hv/init.lua")
dofile(path.."/other/init.lua")

View File

@ -1,367 +0,0 @@
-- LV Alloy furnace
minetest.register_craft({
output = 'technic:coal_alloy_furnace',
recipe = {
{'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({
output = 'technic:alloy_furnace',
recipe = {
{'default:brick', 'default:brick', 'default:brick'},
{'default:brick', '', 'default:brick'},
{'default:steel_ingot', 'default:copper_ingot', 'default:steel_ingot'},
}
})
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]"
minetest.register_node(
"technic:alloy_furnace",
{
description = "Electric alloy furnace",
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.png"},
paramtype2 = "facedir",
groups = {cracky=2},
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Electric Alloy furnace")
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", alloy_furnace_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("src2", 1)
inv:set_size("dst", 4)
end,
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("src2") 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:alloy_furnace_active",
{
description = "Alloy Furnace",
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"},
paramtype2 = "facedir",
light_source = 8,
drop = "technic:alloy_furnace",
groups = {cracky=2,not_in_creative_inventory=1},
legacy_facedir_simple = true,
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("src2") 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_abm(
{ nodenames = {"technic:alloy_furnace","technic:alloy_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("LV_EU_input")
local state = meta:get_int("state")
local next_state = state
-- Machine information
local machine_name = "Electric Alloy Furnace"
local machine_node = "technic:alloy_furnace"
local machine_state_demand = { 50, 600 }
-- 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)
meta:set_int("tube_time", 0)
return
end
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
-- 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
-- Execute always if powered logic
local inv = meta:get_inventory()
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("src2", 1)
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 recipe then
print("recipe "..recipe.dst_name.." : result "..result.name.." : empty "..empty.." : src_item1 "..src_item1.name.." : src_item2 "..src_item2.name)
end
if state == 1 then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
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
elseif state == 2 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
-- 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,
})
technic.register_LV_machine ("technic:alloy_furnace","RE")
technic.register_LV_machine ("technic:alloy_furnace_active","RE")
--------------------------------------------------
-- coal driven alloy furnace. This uses no EUs:
--------------------------------------------------
coal_alloy_furnace_formspec =
"size[8,9]"..
"label[0,0;Alloy Furnace]"..
"image[2,2;1,1;default_furnace_fire_bg.png]"..
"list[current_name;fuel;2,3;1,1;]"..
"list[current_name;src;2,1;1,1;]"..
"list[current_name;src2;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:coal_alloy_furnace", {
description = "Alloy Furnace",
tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", "technic_coal_alloy_furnace_side.png",
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front.png"},
paramtype2 = "facedir",
groups = {cracky=2},
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("formspec", coal_alloy_furnace_formspec)
meta:set_string("infotext", "Alloy Furnace")
local inv = meta:get_inventory()
inv:set_size("fuel", 1)
inv:set_size("src", 1)
inv:set_size("src2", 1)
inv:set_size("dst", 4)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not (inv:is_empty("fuel") or inv:is_empty("dst") or inv:is_empty("src") or inv:is_empty("src2") )then
return false
end
return true
end,
})
minetest.register_node("technic:coal_alloy_furnace_active", {
description = "Alloy Furnace",
tiles = {"technic_coal_alloy_furnace_top.png", "technic_coal_alloy_furnace_bottom.png", "technic_coal_alloy_furnace_side.png",
"technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_side.png", "technic_coal_alloy_furnace_front_active.png"},
paramtype2 = "facedir",
light_source = 8,
drop = "technic:coal_alloy_furnace",
groups = {cracky=2, not_in_creative_inventory=1},
legacy_facedir_simple = true,
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("fuel") or inv:is_empty("dst") or inv:is_empty("src") or inv:is_empty("src2") )then
return false
end
return true
end,
})
minetest.register_abm({
nodenames = {"technic:coal_alloy_furnace","technic:coal_alloy_furnace_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
for i, name in pairs({
"fuel_totaltime",
"fuel_time",
"src_totaltime",
"src_time"
}) do
if meta:get_string(name) == "" then
meta:set_float(name, 0.0)
end
end
local inv = meta:get_inventory()
local recipe = nil
-- Get what to cook if anything
local srcstack = inv:get_stack("src", 1)
if srcstack then src_item1=srcstack:to_table() end
local src2stack = inv:get_stack("src2", 1)
if src2stack then src_item2=src2stack:to_table() end
if src_item1 and src_item2 then
recipe = technic.get_alloy_recipe(src_item1,src_item2)
end
local was_active = false
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
was_active = true
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
meta:set_float("src_time", meta:get_float("src_time") + 1)
if recipe and meta:get_float("src_time") == 6 then
-- check if there's room for output in "dst" list
local dst_stack = { name=recipe.dst_name, count=recipe.dst_count}
if inv:room_for_item("dst",dst_stack) 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",dst_stack)
else
print("Furnace inventory full!") -- Silly code...
end
meta:set_string("src_time", 0)
end
end
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
local percent = math.floor(meta:get_float("fuel_time") /
meta:get_float("fuel_totaltime") * 100)
meta:set_string("infotext","Furnace active: "..percent.."%")
hacky_swap_node(pos,"technic:coal_alloy_furnace_active")
meta:set_string("formspec",
"size[8,9]"..
"label[0,0;Electric Alloy Furnace]"..
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
(100-percent)..":default_furnace_fire_fg.png]"..
"list[current_name;fuel;2,3;1,1;]"..
"list[current_name;src;2,1;1,1;]"..
"list[current_name;src2;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]")
return
end
-- FIXME: Make this look more like the electrical version.
-- This code refetches the recipe to see if it can be done again after the iteration
srcstack = inv:get_stack("src", 1)
if srcstack then src_item1=srcstack:to_table() end
srcstack = inv:get_stack("src2", 1)
if srcstack then src_item2=srcstack:to_table() end
if src_item1 and src_item2 then
recipe = technic.get_alloy_recipe(src_item1,src_item2)
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
fuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
end
if fuel.time <= 0 then
meta:set_string("infotext","Furnace out of fuel")
hacky_swap_node(pos,"technic:coal_alloy_furnace")
meta:set_string("formspec", coal_alloy_furnace_formspec)
return
end
meta:set_string("fuel_totaltime", fuel.time)
meta:set_string("fuel_time", 0)
local stack = inv:get_stack("fuel", 1)
stack:take_item()
inv:set_stack("fuel", 1, stack)
end,
})

View File

@ -1,188 +0,0 @@
-- LV Battery box and some other nodes...
technic.register_power_tool("technic:battery",10000)
technic.register_power_tool("technic:red_energy_crystal",100000)
technic.register_power_tool("technic:green_energy_crystal",250000)
technic.register_power_tool("technic:blue_energy_crystal",500000)
minetest.register_craft({
output = 'technic:battery 1',
recipe = {
{'default:wood', 'default:copper_ingot', 'default:wood'},
{'default:wood', 'moreores:tin_ingot', 'default:wood'},
{'default:wood', 'default:copper_ingot', 'default:wood'},
}
})
minetest.register_tool("technic:battery", {
description = "RE Battery",
inventory_image = "technic_battery.png",
tool_capabilities = {
load=0,
max_drop_level=0,
groupcaps={
fleshy={times={}, uses=10000, maxlevel=0}
}
}
})
--------------------------------------------
-- The Battery box
--------------------------------------------
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', 'default:copper_ingot', 'technic:battery'},
{'default:steel_ingot', 'default:steel_ingot', 'default:steel_ingot'},
}
})
local battery_box_formspec =
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;1,1;]"..
"label[0,0;LV Battery Box]"..
"label[3,0;Charge]"..
"label[5,0;Discharge]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]"..
"background[-0.19,-0.25;8.4,9.75;ui_form_bg.png]"..
"background[0,0;8,4;ui_lv_battery_box.png]"..
"background[0,5;8,4;ui_main_inventory.png]"
minetest.register_node("technic:battery_box", {
description = "LV Battery Box",
tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png",
"technic_battery_box_side0.png", "technic_battery_box_side0.png",
"technic_battery_box_side0.png", "technic_battery_box_side0.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
drop="technic:battery_box",
on_construct = function(pos)
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_int("LV_EU_demand", 0) -- How much can this node charge
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("dst", 1)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") 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,
})
for i=1,8,1 do
minetest.register_node(
"technic:battery_box"..i, {
description = "LV Battery Box",
tiles = {"technic_battery_box_top.png", "technic_battery_box_bottom.png",
"technic_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_battery_box_side0.png^technic_power_meter"..i..".png",
"technic_battery_box_side0.png^technic_power_meter"..i..".png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
drop="technic:battery_box",
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_abm(
{nodenames = {"technic:battery_box","technic:battery_box1","technic:battery_box2","technic:battery_box3","technic:battery_box4",
"technic:battery_box5","technic:battery_box6","technic:battery_box7","technic:battery_box8"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local max_charge = 60000 -- Set maximum charge for the device here
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_tools(meta, current_charge, 1000)
current_charge = discharge_tools(meta, current_charge, max_charge, 1000)
-- 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
local i=math.ceil((current_charge/max_charge)*8)
if i > 8 then i = 8 end
local j = meta:get_float("last_side_shown")
if i~=j then
if i>0 then hacky_swap_node(pos,"technic:battery_box"..i)
elseif i==0 then hacky_swap_node(pos,"technic:battery_box") end
meta:set_float("last_side_shown",i)
end
local load = math.floor(current_charge/max_charge * 100)
meta:set_string("formspec",
battery_box_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"
)
if eu_input == 0 then
meta:set_string("infotext", "LV Battery box: "..current_charge.."/"..max_charge.." (idle)")
else
meta:set_string("infotext", "LV Battery box: "..current_charge.."/"..max_charge)
end
end
})
-- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power
technic.register_LV_machine("technic:battery_box","BA")
for i=1,8,1 do
technic.register_LV_machine("technic:battery_box"..i,"BA")
end

View File

@ -1,293 +0,0 @@
-- Technic CNC v1.0 by kpoppel
-- Based on the NonCubic Blocks MOD v1.4 by yves_de_beck
-- Idea:
-- Somehow have a tabbed/paged panel if the number of shapes should expand
-- beyond what is available in the panel today.
-- 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.
local shape = {}
local onesize_products = {
slope = 2,
slope_edge = 1,
slope_inner_edge = 1,
pyramid = 2,
spike = 1,
cylinder = 2,
sphere = 1,
stick = 8,
slope_upsdown = 2,
slope_edge_upsdown = 1,
slope_inner_edge_upsdown = 1,
cylinder_horizontal = 2,
slope_lying = 2,
onecurvededge = 1,
twocurvededge = 1,
}
local twosize_products = {
element_straight = 4,
element_end = 2,
element_cross = 1,
element_t = 1,
element_edge = 2,
}
local cnc_formspec =
"invsize[9,11;]"..
"label[1,0;Choose Milling Program:]"..
"image_button[1,0.5;1,1;technic_cnc_slope.png;slope; ]"..
"image_button[2,0.5;1,1;technic_cnc_slope_edge.png;slope_edge; ]"..
"image_button[3,0.5;1,1;technic_cnc_slope_inner_edge.png;slope_inner_edge; ]"..
"image_button[4,0.5;1,1;technic_cnc_pyramid.png;pyramid; ]"..
"image_button[5,0.5;1,1;technic_cnc_spike.png;spike; ]"..
"image_button[6,0.5;1,1;technic_cnc_cylinder.png;cylinder; ]"..
"image_button[7,0.5;1,1;technic_cnc_sphere.png;sphere; ]"..
"image_button[8,0.5;1,1;technic_cnc_stick.png;stick; ]"..
"image_button[1,1.5;1,1;technic_cnc_slope_upsdwn.png;slope_upsdown; ]"..
"image_button[2,1.5;1,1;technic_cnc_slope_edge_upsdwn.png;slope_edge_upsdown; ]"..
"image_button[3,1.5;1,1;technic_cnc_slope_inner_edge_upsdwn.png;slope_inner_edge_upsdown; ]"..
"image_button[4,1.5;1,1;technic_cnc_cylinder_horizontal.png;cylinder_horizontal; ]"..
"image_button[1,2.5;1,1;technic_cnc_slope_lying.png;slope_lying; ]"..
"image_button[2,2.5;1,1;technic_cnc_onecurvededge.png;onecurvededge; ]"..
"image_button[3,2.5;1,1;technic_cnc_twocurvededge.png;twocurvededge; ]"..
"label[1,3.5;Slim Elements half / normal height:]"..
"image_button[1,4;1,0.5;technic_cnc_full.png;full; ]"..
"image_button[1,4.5;1,0.5;technic_cnc_half.png;half; ]"..
"image_button[2,4;1,1;technic_cnc_element_straight.png;element_straight; ]"..
"image_button[3,4;1,1;technic_cnc_element_end.png;element_end; ]"..
"image_button[4,4;1,1;technic_cnc_element_cross.png;element_cross; ]"..
"image_button[5,4;1,1;technic_cnc_element_t.png;element_t; ]"..
"image_button[6,4;1,1;technic_cnc_element_edge.png;element_edge; ]"..
"label[0, 5.5;In:]"..
"list[current_name;src;0.5,5.5;1,1;]"..
"label[4, 5.5;Out:]"..
"list[current_name;dst;5,5.5;4,1;]"..
"list[current_player;main;0,7;8,4;]"
local size = 1;
-- 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.
local form_handler = function(pos, formname, fields, sender)
-- REGISTER MILLING PROGRAMS AND OUTPUTS:
------------------------------------------
-- Program for half/full size
if fields["full"] then
size = 1
return
end
if fields["half"] then
size = 2
return
end
-- Resolve the node name and the number of items to make
local meta = minetest.env:get_meta(pos)
local inv = meta:get_inventory()
local inputstack = inv:get_stack("src", 1)
local inputname = inputstack:get_name()
local multiplier = 0
for k, _ in pairs(fields) do
-- Set a multipier for the half/full size capable blocks
if twosize_products[k] ~= nil then
multiplier = size*twosize_products[k]
else
multiplier = onesize_products[k]
end
if onesize_products[k] ~= nil or twosize_products[k] ~= nil then
meta:set_float( "cnc_multiplier", multiplier)
meta:set_string("cnc_user", sender:get_player_name())
end
if onesize_products[k] ~= nil or (twosize_products[k] ~= nil and size==2) then
meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k)
--print(inputname .. "_technic_cnc_" .. k)
break
end
if twosize_products[k] ~= nil and size==1 then
meta:set_string("cnc_product", inputname .. "_technic_cnc_" .. k .. "_double")
--print(inputname .. "_technic_cnc_" .. k .. "_double")
break
end
end
return
end -- callback function
-- The actual block inactive state
minetest.register_node(
"technic:cnc",
{
description = "CNC Milling Machine",
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"},
drawtype = "nodebox",
paramtype = "light",
paramtype2 = "facedir",
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},
},
groups = {cracky=2},
legacy_facedir_simple = true,
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "CNC Machine")
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", cnc_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
end,
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,
on_receive_fields = form_handler,
})
-- Active state block
minetest.register_node("technic:cnc_active", {
description = "CNC Machine",
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"},
paramtype2 = "facedir",
groups = {cracky=2,not_in_creative_inventory=1},
legacy_facedir_simple = true,
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,
})
-- Action code performing the transformation
minetest.register_abm(
{ nodenames = {"technic:cnc","technic:cnc_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("LV_EU_input")
local state = meta:get_int("state")
local next_state = state
-- Machine information
local machine_name = "CNC"
local machine_node = "technic:cnc"
local machine_state_demand = { 50, 450 }
-- 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
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
-- 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()
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
-------------------------
minetest.register_craft({
output = 'technic:cnc',
recipe = {
{'default:glass', 'technic:diamond_drill_head', 'default:glass'},
{'technic:control_logic_unit', 'technic:motor', 'default:steel_ingot'},
{'default:steel_ingot', 'default:copper_ingot', 'default:steel_ingot'},
},
})

View File

@ -1,372 +0,0 @@
-- API for the technic CNC machine
-- Again code is adapted from the NonCubic Blocks MOD v1.4 by yves_de_beck
technic_cnc_api = {}
-- HERE YOU CAN CHANGE THE DETAIL-LEVEL:
----------------------------------------
technic_cnc_api.detail_level = 16 -- 16; 1-32
-- REGISTER NONCUBIC FORMS, CREATE MODELS AND RECIPES:
------------------------------------------------------
local cnc_sphere =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level
local sehne
for i = 1, detail-1 do
sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
nodebox[i]={-sehne, (i/detail)-0.5, -sehne, sehne, (i/detail)+(1/detail)-0.5, sehne}
end
return nodebox
end
local cnc_cylinder_horizontal =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level
local sehne
for i = 1, detail-1 do
sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
nodebox[i]={-0.5, (i/detail)-0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, sehne}
end
return nodebox
end
local cnc_cylinder =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level
local sehne
for i = 1, detail-1 do
sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
nodebox[i]={(i/detail)-0.5, -0.5, -sehne, (i/detail)+(1/detail)-0.5, 0.5, sehne}
end
return nodebox
end
local cnc_twocurvededge =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level*2
local sehne
for i = (detail/2)-1, detail-1 do
sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
nodebox[i]={-sehne, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5}
end
return nodebox
end
local cnc_onecurvededge =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level*2
local sehne
for i = (detail/2)-1, detail-1 do
sehne = math.sqrt(0.25 - (((i/detail)-0.5)^2))
nodebox[i]={-0.5, -0.5, -sehne, 0.5, (i/detail)+(1/detail)-0.5, 0.5}
end
return nodebox
end
local cnc_spike =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level
for i = 0, detail-1 do
nodebox[i+1]={(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5, 0.5-(i/detail/2), (i/detail)-0.5+(1/detail), 0.5-(i/detail/2)}
end
return nodebox
end
local cnc_pyramid =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level/2
for i = 0, detail-1 do
nodebox[i+1]={(i/detail/2)-0.5, (i/detail/2)-0.5, (i/detail/2)-0.5, 0.5-(i/detail/2), (i/detail/2)-0.5+(1/detail), 0.5-(i/detail/2)}
end
return nodebox
end
local cnc_slope_inner_edge_upsdown =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level
for i = 0, detail-1 do
nodebox[i+1]={0.5-(i/detail)-(1/detail), (i/detail)-0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
nodebox[i+detail+1]={-0.5, (i/detail)-0.5, 0.5-(i/detail)-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
local cnc_slope_edge_upsdown =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level
for i = 0, detail-1 do
nodebox[i+1]={(-1*(i/detail))+0.5-(1/detail), (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
local cnc_slope_inner_edge =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level
for i = 0, detail-1 do
nodebox[i+1]={(i/detail)-0.5, -0.5, -0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
nodebox[i+detail+1]={-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
local cnc_slope_edge =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level
for i = 0, detail-1 do
nodebox[i+1]={(i/detail)-0.5, -0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
local cnc_slope_upsdown =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level
for i = 0, detail-1 do
nodebox[i+1]={-0.5, (i/detail)-0.5, (-1*(i/detail))+0.5-(1/detail), 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
local cnc_slope_lying =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level
for i = 0, detail-1 do
nodebox[i+1]={(i/detail)-0.5, -0.5, (i/detail)-0.5, (i/detail)-0.5+(1/detail), 0.5 , 0.5}
end
return nodebox
end
local cnc_slope =
function()
local nodebox = {}
local detail = technic_cnc_api.detail_level
for i = 0, detail-1 do
nodebox[i+1]={-0.5, (i/detail)-0.5, (i/detail)-0.5, 0.5, (i/detail)-0.5+(1/detail), 0.5}
end
return nodebox
end
-- Define slope boxes for the various nodes
-------------------------------------------
technic_cnc_api.cnc_programs = {
{suffix = "technic_cnc_stick",
nodebox = {-0.15, -0.5, -0.15, 0.15, 0.5, 0.15},
desc = "Stick"},
{suffix = "technic_cnc_element_end_double",
nodebox = {-0.3, -0.5, -0.3, 0.3, 0.5, 0.5},
desc = "Element End Double"},
{suffix = "technic_cnc_element_cross_double",
nodebox = {
{0.3, -0.5, -0.3, 0.5, 0.5, 0.3},
{-0.3, -0.5, -0.5, 0.3, 0.5, 0.5},
{-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}},
desc = "Element Cross Double"},
{suffix = "technic_cnc_element_t_double",
nodebox = {
{-0.3, -0.5, -0.5, 0.3, 0.5, 0.3},
{-0.5, -0.5, -0.3, -0.3, 0.5, 0.3},
{0.3, -0.5, -0.3, 0.5, 0.5, 0.3}},
desc = "Element T Double"},
{suffix = "technic_cnc_element_edge_double",
nodebox = {
{-0.3, -0.5, -0.5, 0.3, 0.5, 0.3},
{-0.5, -0.5, -0.3, -0.3, 0.5, 0.3}},
desc = "Element Edge Double"},
{suffix = "technic_cnc_element_straight_double",
nodebox = {-0.3, -0.5, -0.5, 0.3, 0.5, 0.5},
desc = "Element Straight Double"},
{suffix = "technic_cnc_element_end",
nodebox = {-0.3, -0.5, -0.3, 0.3, 0, 0.5},
desc = "Element End"},
{suffix = "technic_cnc_element_cross",
nodebox = {
{0.3, -0.5, -0.3, 0.5, 0, 0.3},
{-0.3, -0.5, -0.5, 0.3, 0, 0.5},
{-0.5, -0.5, -0.3, -0.3, 0, 0.3}},
desc = "Element Cross"},
{suffix = "technic_cnc_element_t",
nodebox = {
{-0.3, -0.5, -0.5, 0.3, 0, 0.3},
{-0.5, -0.5, -0.3, -0.3, 0, 0.3},
{0.3, -0.5, -0.3, 0.5, 0, 0.3}},
desc = "Element T"},
{suffix = "technic_cnc_element_edge",
nodebox = {
{-0.3, -0.5, -0.5, 0.3, 0, 0.3},
{-0.5, -0.5, -0.3, -0.3, 0, 0.3}},
desc = "Element Edge"},
{suffix = "technic_cnc_element_straight",
nodebox = {-0.3, -0.5, -0.5, 0.3, 0, 0.5},
desc = "Element Straight"},
{suffix = "technic_cnc_sphere",
nodebox = cnc_sphere(),
desc = "Sphere"},
{suffix = "technic_cnc_cylinder_horizontal",
nodebox = cnc_cylinder_horizontal(),
desc = "Cylinder Horizontal"},
{suffix = "technic_cnc_cylinder",
nodebox = cnc_cylinder(),
desc = ""},
{suffix = "technic_cnc_twocurvededge",
nodebox = cnc_twocurvededge(),
desc = "One Curved Edge Block"},
{suffix = "technic_cnc_onecurvededge",
nodebox = cnc_onecurvededge(),
desc = "Two Curved Edge Block"},
{suffix = "technic_cnc_spike",
nodebox = cnc_spike(),
desc = "Spike"},
{suffix = "technic_cnc_pyramid",
nodebox = cnc_pyramid(),
desc = "Pyramid"},
{suffix = "technic_cnc_slope_inner_edge_upsdown",
nodebox = cnc_slope_inner_edge_upsdown(),
desc = "Slope Upside Down Inner Edge"},
{suffix = "technic_cnc_slope_edge_upsdown",
nodebox = cnc_slope_edge_upsdown(),
desc = "Slope Upside Down Edge"},
{suffix = "technic_cnc_slope_inner_edge",
nodebox = cnc_slope_inner_edge(),
desc = "Slope Inner Edge"},
{suffix = "technic_cnc_slope_edge",
nodebox = cnc_slope_edge(),
desc = "Slope Edge"},
{suffix = "technic_cnc_slope_upsdown",
nodebox = cnc_slope_upsdown(),
desc = "Slope Upside Down"},
{suffix = "technic_cnc_slope_lying",
nodebox = cnc_slope_lying(),
desc = "Slope Lying"},
{suffix = "technic_cnc_slope",
nodebox = cnc_slope(),
desc = "Slope"},
-- {suffix = "",
-- nodebox =},
}
-- Allow disabling certain programs for some node. Default is allowing all types for all nodes
technic_cnc_api.cnc_programs_disable = {
-- ["default:brick"] = {"technic_cnc_stick"}, -- Example: Disallow the stick for brick
-- ...
["default:dirt"] = {"technic_cnc_sphere", "technic_cnc_slope_upsdown", "technic_cnc_edge",
"technic_cnc_inner_edge", "technic_cnc_slope_edge_upsdown", "technic_cnc_slope_inner_edge_upsdown",
"technic_cnc_stick", "technic_cnc_cylinder_horizontal"}
}
-- Generic function for registering all the different node types
function technic_cnc_api.register_cnc_program(recipeitem, suffix, nodebox, groups, images, description)
minetest.register_node(":" .. recipeitem .. "_" .. suffix, {
description = description,
drawtype = "nodebox",
tiles = images,
paramtype = "light",
paramtype2 = "facedir",
walkable = true,
selection_box = {
type = "fixed",
fixed = nodebox
},
node_box = {
type = "fixed",
fixed = nodebox
},
groups = groups,
})
end
-- function to iterate over all the programs the CNC machine knows
function technic_cnc_api.register_all(recipeitem, groups, images, description)
for _, data in ipairs(technic_cnc_api.cnc_programs) do
-- Disable node creation for disabled node types for some material
local do_register = true
if technic_cnc_api.cnc_programs_disable[recipeitem] ~= nil then
for __, disable in ipairs(technic_cnc_api.cnc_programs_disable[recipeitem]) do
if disable == data.suffix then
do_register = false
end
end
end
-- Create the node if it passes the test
if do_register then
technic_cnc_api.register_cnc_program(recipeitem, data.suffix, data.nodebox, groups, images, description.." "..data.desc)
end
end
end
-- REGISTER NEW TECHNIC_CNC_API's PART 2: technic_cnc_api.register_element_end(subname, recipeitem, groups, images, desc_element_xyz)
-----------------------------------------------------------------------------------------------------------------------
function technic_cnc_api.register_slope_edge_etc(recipeitem, groups, images, desc_slope, desc_slope_lying, desc_slope_upsdown, desc_slope_edge, desc_slope_inner_edge, desc_slope_upsdwn_edge, desc_slope_upsdwn_inner_edge, desc_pyramid, desc_spike, desc_onecurvededge, desc_twocurvededge, desc_cylinder, desc_cylinder_horizontal, desc_sphere, desc_element_straight, desc_element_edge, desc_element_t, desc_element_cross, desc_element_end)
technic_cnc_api.register_slope(recipeitem, groups, images, desc_slope)
technic_cnc_api.register_slope_lying(recipeitem, groups, images, desc_slope_lying)
technic_cnc_api.register_slope_upsdown(recipeitem, groups, images, desc_slope_upsdown)
technic_cnc_api.register_slope_edge(recipeitem, groups, images, desc_slope_edge)
technic_cnc_api.register_slope_inner_edge(recipeitem, groups, images, desc_slope_inner_edge)
technic_cnc_api.register_slope_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_edge)
technic_cnc_api.register_slope_inner_edge_upsdown(recipeitem, groups, images, desc_slope_upsdwn_inner_edge)
technic_cnc_api.register_pyramid(recipeitem, groups, images, desc_pyramid)
technic_cnc_api.register_spike(recipeitem, groups, images, desc_spike)
technic_cnc_api.register_onecurvededge(recipeitem, groups, images, desc_onecurvededge)
technic_cnc_api.register_twocurvededge(recipeitem, groups, images, desc_twocurvededge)
technic_cnc_api.register_cylinder(recipeitem, groups, images, desc_cylinder)
technic_cnc_api.register_cylinder_horizontal(recipeitem, groups, images, desc_cylinder_horizontal)
technic_cnc_api.register_sphere(recipeitem, groups, images, desc_sphere)
technic_cnc_api.register_element_straight(recipeitem, groups, images, desc_element_straight)
technic_cnc_api.register_element_edge(recipeitem, groups, images, desc_element_edge)
technic_cnc_api.register_element_t(recipeitem, groups, images, desc_element_t)
technic_cnc_api.register_element_cross(recipeitem, groups, images, desc_element_cross)
technic_cnc_api.register_element_end(recipeitem, groups, images, desc_element_end)
end
-- REGISTER STICKS: noncubic.register_xyz(recipeitem, groups, images, desc_element_xyz)
------------------------------------------------------------------------------------------------------------
function technic_cnc_api.register_stick_etc(recipeitem, groups, images, desc_stick)
technic_cnc_api.register_stick(recipeitem, groups, images, desc_stick)
end
function technic_cnc_api.register_elements(recipeitem, groups, images, desc_element_straight_double, desc_element_edge_double, desc_element_t_double, desc_element_cross_double, desc_element_end_double)
technic_cnc_api.register_element_straight_double(recipeitem, groups, images, desc_element_straight_double)
technic_cnc_api.register_element_edge_double(recipeitem, groups, images, desc_element_edge_double)
technic_cnc_api.register_element_t_double(recipeitem, groups, images, desc_element_t_double)
technic_cnc_api.register_element_cross_double(recipeitem, groups, images, desc_element_cross_double)
technic_cnc_api.register_element_end_double(recipeitem, groups, images, desc_element_end_double)
end

View File

@ -1,70 +0,0 @@
-- REGISTER MATERIALS AND PROPERTIES FOR NONCUBIC ELEMENTS:
-----------------------------------------------------------
-- DIRT
-------
technic_cnc_api.register_all("default:dirt",
{snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1},
{"default_grass.png", "default_dirt.png", "default_grass.png"},
"Dirt")
technic_cnc_api.cnc_programs_disable["default:dirt"] = {"technic_cnc_sphere", "technic_cnc_slope_upsdown",
"technic_cnc_edge", "technic_cnc_inner_edge",
"technic_cnc_slope_edge_upsdown", "technic_cnc_slope_inner_edge_upsdown",
"technic_cnc_stick", "technic_cnc_cylinder_horizontal"}
-- TREE
-------
technic_cnc_api.register_all("default:tree",
{snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
{"default_tree.png"},
"Wooden")
-- WOOD
-------
technic_cnc_api.register_all("default:wood",
{snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
{"default_wood.png"},
"Wooden")
-- STONE
--------
technic_cnc_api.register_all("default:stone",
{cracky=3,not_in_creative_inventory=1},
{"default_stone.png"},
"Stone")
-- COBBLE
---------
technic_cnc_api.register_all("default:cobble",
{cracky=3,not_in_creative_inventory=1},
{"default_cobble.png"},
"Cobble")
-- BRICK
--------
technic_cnc_api.register_all("default:brick",
{cracky=3,not_in_creative_inventory=1},
{"default_brick.png"},
"Brick")
-- SANDSTONE
------------
technic_cnc_api.register_all("default:sandstone",
{crumbly=2,cracky=2,not_in_creative_inventory=1},
{"default_sandstone.png"},
"Sandstone")
-- LEAVES
---------
technic_cnc_api.register_all("default:leaves",
{snappy=2,choppy=2,oddly_breakable_by_hand=3,not_in_creative_inventory=1},
{"default_leaves.png"},
"Leaves")
-- TREE
-------
technic_cnc_api.register_all("default:tree",
{snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1,not_in_creative_inventory=1},
{"default_tree.png"},
"Tree")
-- STEEL
--------
technic_cnc_api.register_all("default:steel",
{snappy=1,bendy=2,cracky=1,melty=2,level=2,not_in_creative_inventory=1},
{"default_steel_block.png"},
"Steel")

View File

@ -1,207 +0,0 @@
technic.compressor_recipes ={}
technic.register_compressor_recipe = function(src, src_count, dst, dst_count)
technic.compressor_recipes[src] = {src_count = src_count, dst_name = dst, dst_count = dst_count}
if unified_inventory then
unified_inventory.register_craft(
{
type = "compressing",
output = dst.." "..dst_count,
items = {src.." "..src_count},
width = 0,
})
end
end
technic.get_compressor_recipe = function(item)
if technic.compressor_recipes[item.name] and
item.count >= technic.compressor_recipes[item.name].src_count then
return technic.compressor_recipes[item.name]
else
return nil
end
end
technic.register_compressor_recipe("default:snowblock", 1, "default:ice", 1)
technic.register_compressor_recipe("default:sand", 1, "default:sandstone", 1)
technic.register_compressor_recipe("default:desert_sand", 1, "default:desert_stone", 1)
technic.register_compressor_recipe("technic:mixed_metal_ingot", 1, "technic:composite_plate", 1)
technic.register_compressor_recipe("default:copper_ingot", 5, "technic:copper_plate", 1)
technic.register_compressor_recipe("technic:coal_dust", 4, "technic:graphite", 1)
technic.register_compressor_recipe("technic:carbon_cloth", 1, "technic:carbon_plate", 1)
minetest.register_alias("compressor", "technic:compressor")
minetest.register_craft({
output = 'technic:compressor',
recipe = {
{'default:stone', 'default:stone', 'default:stone'},
{'mesecons:piston', 'technic:motor', 'mesecons:piston'},
{'default:stone', 'technic:lv_cable', 'default:stone'},
}
})
minetest.register_craftitem("technic:compressor", {
description = "Compressor",
stack_max = 99,
})
local compressor_formspec =
"invsize[8,9;]"..
"label[0,0;Compressor]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node("technic:compressor", {
description = "Compressor",
tiles = {"technic_compressor_top.png", "technic_compressor_bottom.png", "technic_compressor_side.png",
"technic_compressor_side.png", "technic_compressor_back.png", "technic_compressor_front.png"},
paramtype2 = "facedir",
groups = {cracky=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Compressor")
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", compressor_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
end,
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:compressor_active", {
description = "Compressor",
tiles = {"technic_compressor_top.png", "technic_compressor_bottom.png", "technic_compressor_side.png",
"technic_compressor_side.png", "technic_compressor_back.png", "technic_compressor_front_active.png"},
paramtype2 = "facedir",
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,
})
minetest.register_abm({
nodenames = {"technic:compressor","technic:compressor_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- Run a machine through its states. Takes the same arguments as the ABM action
-- and adds the machine's states and any extra data which is needed by the machine.
-- A machine is characterized by running through a set number of states (usually 2:
-- Idle and active) in some order. A state decides when to move to the next one
-- and the machine only changes state if it is powered correctly.
-- The machine will automatically shut down if disconnected from power in some fashion.
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
-- Machine information
local machine_name = "Compressor"
local machine_node = "technic:compressor"
local machine_state_demand = { 50, 300 }
-- 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
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
-- 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()
local empty = inv:is_empty("src")
local srcstack = inv:get_stack("src", 1)
local src_item = nil
local recipe = nil
local result = nil
if srcstack then
src_item = srcstack:to_table()
end
if src_item then
recipe = technic.get_compressor_recipe(src_item)
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")
if not empty and result and inv:room_for_item("dst",result) then
meta:set_int("src_time", 0)
next_state = 2
end
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") == 4 then
-- 4 ticks per output
-- check if there's room for output in "dst" list
meta:set_int("src_time", 0)
if recipe and inv:room_for_item("dst",result) then
-- take stuff from "src" list
srcstack:take_item(recipe.src_count)
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:compressor","RE")
technic.register_LV_machine ("technic:compressor_active","RE")

View File

@ -1,160 +0,0 @@
-- LV Electric Furnace
-- This is a faster version of the stone furnace which runs on EUs
-- 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'},
}
})
local electric_furnace_formspec =
"invsize[8,9;]"..
"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]"
minetest.register_node(
"technic:electric_furnace",
{description = "Electric furnace",
tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png",
"technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front.png"},
paramtype2 = "facedir",
groups = {cracky=2},
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Electric Furnace")
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", electric_furnace_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
end,
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",
{description = "Electric Furnace",
tiles = {"technic_electric_furnace_top.png", "technic_electric_furnace_bottom.png", "technic_electric_furnace_side.png",
"technic_electric_furnace_side.png", "technic_electric_furnace_side.png", "technic_electric_furnace_front_active.png"},
paramtype2 = "facedir",
light_source = 8,
drop = "technic:electric_furnace",
groups = {cracky=2, not_in_creative_inventory=1},
legacy_facedir_simple = true,
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_abm(
{ nodenames = {"technic:electric_furnace","technic: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("LV_EU_input")
local state = meta:get_int("state")
local next_state = state
-- Machine information
local machine_name = "Electric furnace"
local machine_node = "technic:electric_furnace"
local machine_state_demand = { 50, 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("LV_EU_demand", machine_state_demand[1])
meta:set_int("LV_EU_input", 0)
return
end
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
-- 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
-- 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 result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")})
if not empty and result and inv:room_for_item("dst",result) then
next_state = 2
end
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") + 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,
})
technic.register_LV_machine ("technic:electric_furnace","RE")
technic.register_LV_machine ("technic:electric_furnace_active","RE")

View File

@ -1,220 +0,0 @@
technic.extractor_recipes ={}
technic.register_extractor_recipe = function(src, src_count, dst, dst_count)
technic.extractor_recipes[src] = {src_count = src_count, dst_name = dst, dst_count = dst_count}
if unified_inventory then
unified_inventory.register_craft(
{
type = "extracting",
output = dst.." "..dst_count,
items = {src.." "..src_count},
width = 0,
})
end
end
-- Receive an ItemStack of result by an ItemStack input
technic.get_extractor_recipe = function(item)
if technic.extractor_recipes[item.name]
and item.count >= technic.extractor_recipes[item.name].src_count then
return technic.extractor_recipes[item.name]
else
return nil
end
end
technic.register_extractor_recipe("technic:coal_dust", 1, "dye:black", 2)
technic.register_extractor_recipe("default:cactus", 1, "dye:green", 2)
technic.register_extractor_recipe("default:dry_shrub", 1, "dye:brown", 2)
technic.register_extractor_recipe("flowers:geranium", 1, "dye:blue", 2)
technic.register_extractor_recipe("flowers:dandelion_white", 1, "dye:white", 2)
technic.register_extractor_recipe("flowers:dandelion_yellow", 1, "dye:yellow", 2)
technic.register_extractor_recipe("flowers:tulip", 1, "dye:orange", 2)
technic.register_extractor_recipe("flowers:rose", 1, "dye:red", 2)
technic.register_extractor_recipe("flowers:viola", 1, "dye:violet", 2)
technic.register_extractor_recipe("technic:raw_latex", 1, "technic:rubber", 3)
technic.register_extractor_recipe("moretrees:rubber_tree_trunk_empty", 1, "technic:rubber", 1)
technic.register_extractor_recipe("moretrees:rubber_tree_trunk", 1, "technic:rubber", 1)
technic.register_extractor_recipe("technic:uranium", 5, "technic:enriched_uranium", 1)
minetest.register_alias("extractor", "technic:extractor")
minetest.register_craft({
output = 'technic:extractor',
recipe = {
{'technic:treetap', 'technic:motor', 'technic:treetap'},
{'technic:treetap', 'technic:lv_cable', 'technic:treetap'},
{'','',''},
}
})
minetest.register_craftitem("technic:extractor", {
description = "Extractor",
stack_max = 99,
})
local extractor_formspec =
"invsize[8,9;]"..
"label[0,0;Extractor]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node(
"technic:extractor",
{
description = "Extractor",
tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png",
"technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front.png"},
paramtype2 = "facedir",
groups = {cracky=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Extractor")
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", extractor_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
end,
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:extractor_active",
{
description = "Extractor",
tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png",
"technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front_active.png"},
paramtype2 = "facedir",
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,
})
minetest.register_abm(
{ nodenames = {"technic:extractor","technic:extractor_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- Run a machine through its states. Takes the same arguments as the ABM action
-- and adds the machine's states and any extra data which is needed by the machine.
-- A machine is characterized by running through a set number of states (usually 2:
-- Idle and active) in some order. A state decides when to move to the next one
-- and the machine only changes state if it is powered correctly.
-- The machine will automatically shut down if disconnected from power in some fashion.
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
-- Machine information
local machine_name = "Extractor"
local machine_node = "technic:extractor"
local machine_state_demand = { 50, 300 }
-- 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
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
-- 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()
local empty = inv:is_empty("src")
local srcstack = inv:get_stack("src", 1)
local src_item = nil
local recipe = nil
local result = nil
if srcstack then
src_item = srcstack:to_table()
end
if src_item then
recipe = technic.get_extractor_recipe(src_item)
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")
if not empty and result and inv:room_for_item("dst",result) then
meta:set_int("src_time", 0)
next_state = 2
end
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") == 4 then -- 4 ticks per output
-- check if there's room for output in "dst" list
meta:set_int("src_time", 0)
if recipe and inv:room_for_item("dst",result) then
-- take stuff from "src" list
srcstack:take_item(recipe.src_count)
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:extractor","RE")
technic.register_LV_machine ("technic:extractor_active","RE")

View File

@ -1,150 +0,0 @@
-- The 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_active")
minetest.register_craft({
output = 'technic:generator',
recipe = {
{'default:stone', 'default:stone', 'default:stone'},
{'default:stone', '', 'default:stone'},
{'default:stone', 'default:copper_ingot', 'default:stone'},
}
})
minetest.register_craftitem("technic:generator", {
description = "Coal Driven Generator",
stack_max = 99,
})
local generator_formspec =
"invsize[8,9;]"..
"image[0,0;5,5;technic_generator_menu.png]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
-- "label[0,0;Generator]"..
"label[1,3;Power level]"..
"list[current_name;src;3,1;1,1;]"..
"image[4,1;1,1;default_furnace_fire_bg.png]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node(
"technic:generator",
{
description = "Coal Driven Generator",
tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png",
"technic_generator_side.png", "technic_generator_side.png", "technic_generator_front.png"},
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Coal Electric Generator")
meta:set_float("technic_power_machine", 1)
meta:set_int("LV_EU_supply", 0)
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_int("burn_time", 0)
meta:set_string("formspec", generator_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") then
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:generator_active",
{
description = "Coal Driven Generator",
tiles = {"technic_generator_top.png", "technic_machine_bottom.png", "technic_generator_side.png",
"technic_generator_side.png", "technic_generator_side.png", "technic_generator_front_active.png"},
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
drop="technic:generator",
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
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
else
return true
end
end,
})
minetest.register_abm(
{
nodenames = {"technic:generator","technic:generator_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local burn_time= meta:get_int("burn_time")
-- If more to burn and the energy produced was used: produce some more
if burn_time>0 then
if meta:get_int("LV_EU_supply") == 0 then
-- We did not use the power
meta:set_int("LV_EU_supply", 200) -- Give 200EUs
else
burn_time = burn_time - 1
meta:set_int("burn_time",burn_time)
meta:set_string("infotext", "Coal Electric Generator ("..math.floor(burn_time/16*100).."%)")
end
end
-- Burn another piece of coal
if burn_time==0 then
local inv = meta:get_inventory()
if inv:is_empty("src") == false then
local srcstack = inv:get_stack("src", 1)
src_item=srcstack:to_table()
if src_item["name"] == "default:coal_lump" then
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
burn_time=16
meta:set_int("burn_time",burn_time)
hacky_swap_node (pos,"technic:generator_active")
meta:set_int("LV_EU_supply", 200) -- Give 200EUs
else
meta:set_int("LV_EU_supply", 0)
end
end
end
local load = 8 -- math.floor((charge/max_charge)*100)
local percent = math.floor((burn_time/16)*100)
meta:set_string("formspec",
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"..
"label[0,0;Generator]"..
"label[1,3;Power level]"..
"list[current_name;src;3,1;1,1;]"..
"image[4,1;1,1;default_furnace_fire_bg.png^[lowpart:"..
(percent)..":default_furnace_fire_fg.png]"..
"list[current_player;main;0,5;8,4;]"
)
if burn_time==0 then
hacky_swap_node (pos,"technic:generator")
end
end
})
technic.register_LV_machine ("technic:generator","PR")
technic.register_LV_machine ("technic:generator_active","PR")

View File

@ -1,156 +0,0 @@
-- 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_craft({
output = 'technic:geothermal',
recipe = {
{'default:stone', 'default:stone', 'default:stone'},
{'default:copper_ingot', 'default:diamond', 'default:copper_ingot'},
{'default:stone', 'default:copper_ingot', 'default:stone'},
}
})
minetest.register_craftitem("technic:geothermal", {
description = "Geothermal Generator",
stack_max = 99,
})
local geothermal_formspec =
"invsize[8,4;]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"label[0,0;Geothermal Generator]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node(
"technic:geothermal",
{
description = "Geothermal Generator",
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"},
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Geothermal Generator")
meta:set_float("technic_power_machine", 1)
meta:set_int("LV_EU_supply", 0)
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",
})
local check_node_around = function(pos)
local node=minetest.env:get_node(pos)
if node.name=="default:water_source" or node.name=="default:water_flowing" then return 1 end
if node.name=="default:lava_source" or node.name=="default:lava_flowing" then return 2 end
return 0
end
minetest.register_abm(
{
nodenames = {"technic:geothermal","technic:geothermal_active"},
interval = 1,
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
-- Correct positioning is water on one side and lava on the other.
-- The two cannot be adjacent because the lava the turns into obsidian or rock.
-- To get to 100% production stack the water and lava one extra block down as well:
-- WGL (W=Water, L=Lava, G=the generator, |=an LV cable)
-- W|L
pos.x=pos.x+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.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-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.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
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.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
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.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
-- Back to (0,0,0)
pos.z=pos.z+1
if water_nodes==1 and lava_nodes==1 then production_level = 25; eu_supply = 50 end
if water_nodes==2 and lava_nodes==1 then production_level = 50; eu_supply = 100 end
if water_nodes==1 and lava_nodes==2 then production_level = 75; eu_supply = 200 end
if water_nodes==2 and lava_nodes==2 then production_level = 100; eu_supply = 300 end
if production_level>0 then
meta:set_int("LV_EU_supply", eu_supply)
end
local load = 1 -- math.floor((charge/max_charge)*100)
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 +0,0 @@
technic.grinder_recipes ={}
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
-- Receive an ItemStack of result by an ItemStack input
technic.get_grinder_recipe = function(itemstack)
local src_item = itemstack:to_table()
if src_item == nil then
return nil
end
local item_name = src_item["name"]
if technic.grinder_recipes[item_name] then
return ItemStack(technic.grinder_recipes[item_name])
else
return nil
end
end
technic.register_grinder_recipe("default:stone","default:sand")
technic.register_grinder_recipe("default:cobble","default:gravel")
technic.register_grinder_recipe("default:gravel","default:dirt")
technic.register_grinder_recipe("default:desert_stone","default:desert_sand")
technic.register_grinder_recipe("default:iron_lump","technic:iron_dust 2")
technic.register_grinder_recipe("default:steel_ingot","technic:iron_dust 1")
technic.register_grinder_recipe("default:coal_lump","technic:coal_dust 2")
technic.register_grinder_recipe("default:copper_lump","technic:copper_dust 2")
technic.register_grinder_recipe("default:copper_ingot","technic:copper_dust 1")
technic.register_grinder_recipe("default:gold_lump","technic:gold_dust 2")
technic.register_grinder_recipe("default:gold_ingot","technic:gold_dust 1")
--technic.register_grinder_recipe("default:bronze_ingot","technic:bronze_dust 1") -- Dust does not exist yet
--technic.register_grinder_recipe("home_decor:brass_ingot","technic:brass_dust 1") -- needs check for the mod
technic.register_grinder_recipe("moreores:tin_lump","technic:tin_dust 2")
technic.register_grinder_recipe("moreores:tin_ingot","technic:tin_dust 1")
technic.register_grinder_recipe("moreores:silver_lump","technic:silver_dust 2")
technic.register_grinder_recipe("moreores:silver_ingot","technic:silver_dust 1")
technic.register_grinder_recipe("moreores:mithril_lump","technic:mithril_dust 2")
technic.register_grinder_recipe("moreores:mithril_ingot","technic:mithril_dust 1")
technic.register_grinder_recipe("technic:chromium_lump","technic:chromium_dust 2")
technic.register_grinder_recipe("technic:chromium_ingot","technic:chromium_dust 1")
technic.register_grinder_recipe("technic:stainless_steel_ingot","stainless_steel_dust 1")
technic.register_grinder_recipe("technic:brass_ingot","technic:brass_dust 1")
technic.register_grinder_recipe("technic:zinc_lump","technic:zinc_dust 2")
technic.register_grinder_recipe("technic:zinc_ingot","technic:zinc_dust 1")
minetest.register_craftitem( "technic:coal_dust", {
description = "Coal Dust",
inventory_image = "technic_coal_dust.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craftitem( "technic:iron_dust", {
description = "Iron Dust",
inventory_image = "technic_iron_dust.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
type = "cooking",
output = "default:steel_ingot",
recipe = "technic:iron_dust",
})
minetest.register_craftitem( "technic:copper_dust", {
description = "Copper Dust",
inventory_image = "technic_copper_dust.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
type = "cooking",
output = "moreores:copper_ingot",
recipe = "technic:copper_dust",
})
minetest.register_craftitem( "technic:tin_dust", {
description = "Tin Dust",
inventory_image = "technic_tin_dust.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
type = "cooking",
output = "moreores:tin_ingot",
recipe = "technic:tin_dust",
})
minetest.register_craftitem( "technic:silver_dust", {
description = "Silver Dust",
inventory_image = "technic_silver_dust.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
type = "cooking",
output = "moreores:silver_ingot",
recipe = "technic:silver_dust",
})
minetest.register_craftitem( "technic:gold_dust", {
description = "Gold Dust",
inventory_image = "technic_gold_dust.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
type = "cooking",
output = "default:gold_ingot",
recipe = "technic:gold_dust",
})
minetest.register_craftitem( "technic:mithril_dust", {
description = "Mithril Dust",
inventory_image = "technic_mithril_dust.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
type = "cooking",
output = "moreores:mithril_ingot",
recipe = "technic:mithril_dust",
})
minetest.register_craftitem( "technic:chromium_dust", {
description = "Chromium Dust",
inventory_image = "technic_chromium_dust.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
type = "cooking",
output = "technic:chromium_ingot",
recipe = "technic:chromium_dust",
})
minetest.register_craftitem( "technic:bronze_dust", {
description = "Bronze Dust",
inventory_image = "technic_bronze_dust.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
type = "cooking",
output = "default:bronze_ingot",
recipe = "technic:bronze_dust",
})
minetest.register_craftitem( "technic:brass_dust", {
description = "Brass Dust",
inventory_image = "technic_brass_dust.png",
on_place_on_ground = minetest.craftitem_place_item,
})
minetest.register_craft({
type = "cooking",
output = "technic:brass_ingot",
recipe = "technic:brass_dust",
})
minetest.register_craftitem( "technic:stainless_steel_dust", {
description = "Stainless Steel Dust",
inventory_image = "technic_stainless_steel_dust.png",
})
minetest.register_craft({
type = "cooking",
output = "technic:stainless_steel_ingot",
recipe = "technic:stainless_steel_dust",
})
minetest.register_craftitem( "technic:zinc_dust", {
description = "Zinc Dust",
inventory_image = "technic_zinc_dust.png",
})
minetest.register_craft({
type = "cooking",
output = "technic:zinc_ingot",
recipe = "technic:zinc_dust",
})
minetest.register_alias("grinder", "technic:grinder")
minetest.register_craft({
output = 'technic:grinder',
recipe = {
{'default:desert_stone', 'default:desert_stone', 'default:desert_stone'},
{'default:desert_stone', 'default:diamond', 'default:desert_stone'},
{'default:stone', 'moreores:copper_ingot', 'default:stone'},
}
})
minetest.register_craftitem("technic:grinder", {
description = "Grinder",
stack_max = 99,
})
local grinder_formspec =
"invsize[8,9;]"..
"label[0,0;Grinder]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node(
"technic:grinder",
{
description = "Grinder",
tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png",
"technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front.png"},
paramtype2 = "facedir",
groups = {cracky=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Grinder")
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", grinder_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
end,
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:grinder_active",
{
description = "Grinder",
tiles = {"technic_lv_grinder_top.png", "technic_lv_grinder_bottom.png", "technic_lv_grinder_side.png",
"technic_lv_grinder_side.png", "technic_lv_grinder_side.png", "technic_lv_grinder_front_active.png"},
paramtype2 = "facedir",
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,
})
minetest.register_abm(
{ nodenames = {"technic:grinder","technic:grinder_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- Run a machine through its states. Takes the same arguments as the ABM action
-- and adds the machine's states and any extra data which is needed by the machine.
-- A machine is characterized by running through a set number of states (usually 2:
-- Idle and active) in some order. A state decides when to move to the next one
-- and the machine only changes state if it is powered correctly.
-- The machine will automatically shut down if disconnected from power in some fashion.
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
-- Machine information
local machine_name = "Grinder"
local machine_node = "technic:grinder"
local machine_state_demand = { 50, 300 }
-- 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
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
-- 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()
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 = technic.get_grinder_recipe(inv:get_stack("src", 1))
if not empty and result and inv:room_for_item("dst",result) then
meta:set_int("src_time", 0)
next_state = 2
end
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") == 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,156 +0,0 @@
-- LV Music player.
-- The playe can play music. But it is high ampage!
minetest.register_alias("music_player", "technic:music_player")
minetest.register_craft({
output = 'technic:music_player',
recipe = {
{'default:wood', 'default:wood', 'default:wood'},
{'default:diamond', 'default:diamond', 'default:diamond'},
{'default:stone', 'default:copper_ingot', 'default:stone'},
}
})
minetest.register_craftitem("technic:music_player", {
description = "Music Player",
stack_max = 99,
})
local music_player_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 --]"
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_abm(
{ nodenames = {"technic:music_player"},
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("LV_EU_input")
local state = meta:get_int("state")
local next_state = state
-- Machine information
local machine_name = "Music Player"
local machine_node = "technic:music_player"
local machine_state_demand = { 10, 150 }
local music_handle = meta:get_int("music_handle")
-- 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
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
-- 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")

View File

@ -1,78 +0,0 @@
-- The solar array is an assembly of panels into a powerful array
-- The assembly can deliver more energy than the individual panel because
-- of the transformer unit which converts the panel output variations into
-- a stable supply.
-- Solar arrays are not able to store large amounts of energy.
-- The LV arrays are used to make medium voltage arrays.
minetest.register_node("technic:solar_array_lv", {
tiles = {"technic_lv_solar_array_top.png", "technic_lv_solar_array_bottom.png", "technic_lv_solar_array_side.png",
"technic_lv_solar_array_side.png", "technic_lv_solar_array_side.png", "technic_lv_solar_array_side.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
description="LV Solar Array",
drawtype = "nodebox",
paramtype = "light",
is_ground_content = true,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_int("technic_power_machine", 1)
meta:set_int("LV_EU_supply", 0)
meta:set_string("infotext", "LV Solar Array")
end,
})
minetest.register_craft(
{output = 'technic:solar_array_lv 1',
recipe = {
{'technic:solar_panel', 'technic:solar_panel', 'technic:solar_panel'},
{'technic:solar_panel', 'technic:lv_transformer', 'technic:solar_panel'},
{'default:steel_ingot', 'technic:lv_cable', 'default:steel_ingot'},
}
})
minetest.register_abm(
{nodenames = {"technic:solar_array_lv"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- The action here is to make the solar array produce power
-- Power is dependent on the light level and the height above ground
-- 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.
-- 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.
-- To take care of some of it solar arrays do not work outside daylight hours or if
-- built below -10m
local pos1={}
pos1.y=pos.y+1
pos1.x=pos.x
pos1.z=pos.z
local light = minetest.env:get_node_light(pos1, nil)
local time_of_day = minetest.env:get_timeofday()
local meta = minetest.env:get_meta(pos)
if light == nil then light = 0 end
-- turn on array only during day time and if sufficient light
-- 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
local charge_to_give = math.floor(light*(light*0.5333+pos1.y/130*2.6667))
if charge_to_give<0 then charge_to_give=0 end
if charge_to_give>160 then charge_to_give=160 end
meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
meta:set_int("LV_EU_supply", charge_to_give)
else
meta:set_string("infotext", "Solar Array is inactive");
meta:set_int("LV_EU_supply", 0)
end
end,
})
technic.register_LV_machine ("technic:solar_array_lv","PR")

View File

@ -1,78 +0,0 @@
-- Solar panels are the building blocks of LV solar arrays
-- They can however also be used separately but with reduced efficiency due to the missing transformer.
-- Individual panels are 20% less efficient than when the panels are combined into full arrays.
minetest.register_node("technic:solar_panel", {
tiles = {"technic_solar_panel_top.png", "technic_solar_panel_bottom.png", "technic_solar_panel_side.png",
"technic_solar_panel_side.png", "technic_solar_panel_side.png", "technic_solar_panel_side.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
description="Solar Panel",
active = false,
drawtype = "nodebox",
paramtype = "light",
is_ground_content = true,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_int("technic_power_machine", 1)
meta:set_int("LV_EU_supply", 0)
meta:set_string("infotext", "LV Solar Panel")
end,
})
minetest.register_craft({
output = 'technic:solar_panel 1',
recipe = {
{'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'},
{'technic:doped_silicon_wafer', 'technic:lv_cable', 'technic:doped_silicon_wafer'},
{'technic:doped_silicon_wafer', 'technic:doped_silicon_wafer','technic:doped_silicon_wafer'},
}
})
minetest.register_abm(
{nodenames = {"technic:solar_panel"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- The action here is to make the solar panel prodice power
-- Power is dependent on the light level and the height above ground
-- 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 26EU.
-- 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.
-- To take care of some of it solar panels do not work outside daylight hours or if
-- built below -10m
local pos1={}
pos1.y=pos.y+1
pos1.x=pos.x
pos1.z=pos.z
local light = minetest.env:get_node_light(pos1, nil)
local time_of_day = minetest.env:get_timeofday()
local meta = minetest.env:get_meta(pos)
if light == nil then light = 0 end
-- 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.
if light >= 12 and time_of_day>=0.24 and time_of_day<=0.76 and pos.y > -10 then
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>26 then charge_to_give=26 end
meta:set_string("infotext", "Solar Panel is active ("..charge_to_give.."EU)")
meta:set_int("LV_EU_supply", charge_to_give)
else
meta:set_string("infotext", "Solar Panel is inactive");
meta:set_int("LV_EU_supply", 0)
end
end,
})
technic.register_LV_machine ("technic:solar_panel","PR")

View File

@ -1,122 +0,0 @@
-- LV Tool workshop
-- This machine repairs tools.
minetest.register_alias("tool_workshop", "technic:tool_workshop")
minetest.register_craft({
output = 'technic:tool_workshop',
recipe = {
{'default:wood', 'default:wood', 'default:wood'},
{'default:wood', 'default:diamond', 'default:wood'},
{'default:stone', 'default:copper_ingot', 'default:stone'},
}
})
minetest.register_craftitem("technic:tool_workshop", {
description = "Tool Workshop",
stack_max = 99,
})
local workshop_formspec =
"invsize[8,9;]"..
"list[current_name;src;3,1;1,1;]"..
"label[0,0;Tool Workshop]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node(
"technic:tool_workshop",
{
description = "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"},
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", "Tool Workshop")
meta:set_float("technic_power_machine", 1)
meta:set_string("formspec", workshop_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") then
minetest.chat_send_player(player:get_player_name(), "Machine cannot be removed because it is not empty");
return false
end
return true
end,
})
minetest.register_abm(
{ nodenames = {"technic:tool_workshop"},
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("LV_EU_input")
local state = meta:get_int("state")
local next_state = state
-- 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
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "LV")
-- 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,122 +0,0 @@
-- 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_craft({
output = 'technic:water_mill',
recipe = {
{'default:stone', 'default:stone', 'default:stone'},
{'default:wood', 'default:diamond', 'default:wood'},
{'default:stone', 'default:copper_ingot', 'default:stone'},
}
})
minetest.register_craftitem("technic:water_mill", {
description = "Water Mill",
stack_max = 99,
})
local water_mill_formspec =
"invsize[8,4;]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"label[0,0;Water Mill]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]"
minetest.register_node(
"technic:water_mill",
{
description = "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"},
paramtype2 = "facedir",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "Water Mill")
meta:set_float("technic_power_machine", 1)
meta:set_int("LV_EU_supply", 0)
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",
})
local check_node_around_mill = function(pos)
local node=minetest.env:get_node(pos)
if node.name=="default:water_flowing" then return 1 end
return 0
end
minetest.register_abm(
{
nodenames = {"technic:water_mill","technic:water_mill_active"},
interval = 1,
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
pos.x=pos.x+1
local check=check_node_around_mill (pos)
if check==1 then water_nodes=water_nodes+1 end
pos.x=pos.x-2
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; eu_supply = 30 end
if water_nodes==2 then production_level = 50; eu_supply = 60 end
if water_nodes==3 then production_level = 75; eu_supply = 90 end
if water_nodes==4 then production_level = 100; eu_supply = 120 end
if production_level>0 then
meta:set_int("LV_EU_supply", eu_supply)
end
local load = 1 -- math.floor((charge/max_charge)*100)
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;Water Mill]"..
"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:water_mill" then
hacky_swap_node (pos,"technic:water_mill_active")
meta:set_int("LV_EU_supply", 0)
return
end
if production_level==0 then hacky_swap_node (pos,"technic:water_mill") end
end
})
technic.register_LV_machine ("technic:water_mill","PR")
technic.register_LV_machine ("technic:water_mill_active","PR")

View File

@ -1,401 +0,0 @@
--LV cable node boxes
minetest.register_alias("lv_cable", "technic:lv_cable")
minetest.register_craft({
output = 'technic:lv_cable 6',
recipe = {
{'default:copper_ingot', 'default:copper_ingot', 'default:copper_ingot'},
}
})
minetest.register_craftitem("technic:lv_cable", {
description = "Low Voltage Copper Cable",
stack_max = 99,
})
minetest.register_node("technic:lv_cable", {
description = "Low Voltage Copper Cable",
tiles = {"technic_lv_cable.png"},
inventory_image = "technic_lv_cable_wield.png",
wield_image = "technic_lv_cable_wield.png",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
drop = "technic:lv_cable",
cablelike=1,
rules_x1=0,
rules_x2=0,
rules_y1=0,
rules_y2=0,
rules_z1=0,
rules_z2=0,
paramtype = "light",
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {
{ -0.1 , -0.1 , -0.1 , 0.1 , 0.1 , 0.1 },
}},
node_box = {
type = "fixed",
fixed = {
{ -0.1 , -0.1 , -0.1 , 0.1 , 0.1 , 0.1 },
}},
on_construct = function(pos)
meta=minetest.env:get_meta(pos)
meta:set_float("cablelike",1)
meta:set_float("x1",0)
meta:set_float("x2",0)
meta:set_float("y1",0)
meta:set_float("y2",0)
meta:set_float("z1",0)
meta:set_float("z2",0)
check_connections (pos)
end,
after_dig_node = function (pos, oldnode, oldmetadata, digger)
check_connections_on_destroy (pos)
end,
})
str_y1= { -0.1 , -0.1 , -0.1 , 0.1 , 0.5, 0.1 } --0 y+
str_x1= { -0.1 , -0.1 , -0.1 , 0.5, 0.1 , 0.1 } --0 x+
str_z1= { -0.1 , -0.1 , 0.1 , 0.1 , 0.1 , 0.5 } --0 z+
str_z2= { -0.1 , -0.1, -0.5 , 0.1 , 0.1 , 0.1 } --0 z-
str_y2= { -0.1 , -0.5, -0.1 , 0.1 , 0.1 , 0.1 } --0 y-
str_x2= { -0.5 , -0.1, -0.1 , 0.1 , 0.1 , 0.1 } --0 x-
local x1,x2,y1,y2,z1,z2
local count=0
for x1 = 0, 1, 1 do --x-
for x2 = 0, 1, 1 do --x+
for y1 = 0, 1, 1 do --y-
for y2 = 0, 1, 1 do --y-
for z1 = 0, 1, 1 do --z-
for z2 = 0, 1, 1 do --z+
temp_x1={} temp_x2={} temp_y1={} temp_y2={} temp_z1={} temp_z2={}
if x1==1 then temp_x1=str_x1 end
if x2==1 then temp_x2=str_x2 end
if y1==1 then temp_y1=str_y1 end
if y2==1 then temp_y2=str_y2 end
if z1==1 then temp_z1=str_z1 end
if z2==1 then temp_z2=str_z2 end
minetest.register_node("technic:lv_cable"..count, {
description = "Low Voltage Copper Cable",
tiles = {"technic_lv_cable.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
drop = "technic:lv_cable",
rules_x1=0,
rules_x2=0,
rules_y1=0,
rules_y2=0,
rules_z1=0,
rules_z2=0,
cablelike=1,
paramtype = "light",
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {
temp_x1,temp_x2,temp_y1,temp_y2,temp_z1,temp_z2,
}},
node_box = {
type = "fixed",
fixed = {
temp_x1,temp_x2,temp_y1,temp_y2,temp_z1,temp_z2,
}},
after_dig_node = function (pos, oldnode, oldmetadata, digger)
check_connections_on_destroy (pos)
end,
})
count=count+1 end end end end end end
check_connections = function(pos)
local pos1={}
pos1.x=pos.x
pos1.y=pos.y
pos1.z=pos.z
pos1.x=pos1.x+1
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
x2=1
x1=minetest.env:get_meta(pos1):get_float("x1")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:lv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("x2",x2)
meta=minetest.env:get_meta(pos)
x1=1
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("x1",x1)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:lv_cable"..rule)
end
pos1.x=pos1.x-2
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
x1=1
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:lv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("x1",x1)
meta=minetest.env:get_meta(pos)
x2=1
x1=minetest.env:get_meta(pos):get_float("x1")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("x2",x2)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:lv_cable"..rule)
end
pos1.x=pos1.x+1
pos1.y=pos1.y+1
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
y2=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:lv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("y2",y2)
meta=minetest.env:get_meta(pos)
y1=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("y1",y1)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:lv_cable"..rule)
end
if minetest.env:get_meta(pos1):get_float("technic_power_machine")==1 then
y1=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:lv_cable"..rule)
meta=minetest.env:get_meta(pos)
meta:set_float("y1",y1)
end
pos1.y=pos1.y-2
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
y1=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:lv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("y1",y1)
meta=minetest.env:get_meta(pos)
y2=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("y2",y2)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:lv_cable"..rule)
end
pos1.y=pos1.y+1
pos1.z=pos1.z+1
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
z2=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:lv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("z2",z2)
meta=minetest.env:get_meta(pos)
z1=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("z1",z1)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:lv_cable"..rule)
end
pos1.z=pos1.z-2
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
z1=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:lv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("z1",z1)
meta=minetest.env:get_meta(pos)
z2=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
meta:set_float("z2",z2)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:lv_cable"..rule)
end
pos1.z=pos1.z+1
end
function make_rule_number (x1,x2,y1,y2,z1,z2)
local temp= z2+z1*2+y2*4+y1*8+x2*16+x1*32
return temp
end
check_connections_on_destroy = function(pos)
local pos1={}
pos1.x=pos.x
pos1.y=pos.y
pos1.z=pos.z
pos1.x=pos1.x+1
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
x2=0
x1=minetest.env:get_meta(pos1):get_float("x1")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:lv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:lv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("x2",x2)
end
pos1.x=pos1.x-2
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
x1=0
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:lv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:lv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("x1",x1)
end
pos1.x=pos1.x+1
pos1.y=pos1.y+1
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
y2=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:lv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:lv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("y2",y2)
end
pos1.y=pos1.y-2
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
y1=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:lv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:lv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("y1",y1)
end
pos1.y=pos1.y+1
pos1.z=pos1.z+1
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
z2=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:lv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:lv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("z2",z2)
end
pos1.z=pos1.z-2
if minetest.env:get_meta(pos1):get_float("cablelike")==1 then
z1=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:lv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:lv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("z1",z1)
end
pos1.y=pos1.y+1
end

View File

@ -1,460 +0,0 @@
-- MV alloy furnace
minetest.register_craft({
output = 'technic:mv_alloy_furnace',
recipe = {
{'technic:stainless_steel_ingot', 'technic:alloy_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'},
}
})
local mv_alloy_furnace_formspec =
"invsize[8,10;]"..
"label[0,0;MV Alloy Furnace]"..
"list[current_name;src;3,1;1,2;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,6;8,4;]"..
"list[current_name;upgrade1;1,4;1,1;]"..
"list[current_name;upgrade2;2,4;1,1;]"..
"label[1,5;Upgrade Slots]"
minetest.register_node(
"technic:mv_alloy_furnace",
{description = "MV Alloy Furnace",
tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png",
"technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front.png"},
paramtype2 = "facedir",
groups = {cracky=2, tubedevice=1,tubedevice_receiver=1},
tube={insert_object=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:add_item("src",stack)
end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:room_for_item("src",stack)
end,
connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
},
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "MV Alloy furnace")
meta:set_float("technic_mv_power_machine", 1)
meta:set_int("tube_time", 0)
meta:set_string("formspec", mv_alloy_furnace_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 2)
inv:set_size("dst", 4)
inv:set_size("upgrade1", 1)
inv:set_size("upgrade2", 1)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") 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:mv_alloy_furnace_active",
{description = "MV Alloy Furnace",
tiles = {"technic_mv_alloy_furnace_top.png", "technic_mv_alloy_furnace_bottom.png", "technic_mv_alloy_furnace_side_tube.png",
"technic_mv_alloy_furnace_side_tube.png", "technic_mv_alloy_furnace_side.png", "technic_mv_alloy_furnace_front_active.png"},
paramtype2 = "facedir",
light_source = 8,
drop = "technic:mv_alloy_furnace",
groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1},
tube={insert_object=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:add_item("src",stack)
end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:room_for_item("src",stack)
end,
connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
},
legacy_facedir_simple = true,
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") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") 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,
-- These three makes sure upgrades are not moved in or out while the furnace is active.
allow_metadata_inventory_put = 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_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,
})
local send_cooked_items = function(pos,x_velocity,z_velocity)
-- Send items on their way in the pipe system.
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
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 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_alloy_furnace","technic:mv_alloy_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 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
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "MV")
-- Execute always logic
-- CODE HERE --
-- 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
-- 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 since we tube stuff
-- out while being idle.
if inv:is_empty("src") 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
------------------------------------
-- 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,152 +0,0 @@
-- MV Battery box
minetest.register_craft(
{output = 'technic:mv_battery_box 1',
recipe = {
{'technic:battery_box', 'technic:battery_box', 'technic:battery_box'},
{'technic:battery_box', 'technic:mv_transformer', 'technic:battery_box'},
{'', 'technic:mv_cable', ''},
}
})
local battery_box_formspec =
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]"..
"list[current_name;dst;5,1;1,1;]"..
"label[0,0;MV Battery Box]"..
"label[3,0;Charge]"..
"label[5,0;Discharge]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]"..
"background[-0.19,-0.25;8.4,9.75;ui_form_bg.png]"..
"background[0,0;8,4;ui_mv_battery_box.png]"..
"background[0,5;8,4;ui_main_inventory.png]"
minetest.register_node(
"technic: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_mv_battery_box_side0.png", "technic_mv_battery_box_side0.png", "technic_mv_battery_box_side0.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
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_int("MV_EU_demand", 0) -- How much can this node charge
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("dst", 1)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") 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,
})
for i=1,8,1 do
minetest.register_node(
"technic:mv_battery_box"..i,
{
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",
"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},
sounds = default.node_sound_wood_defaults(),
drop = "technic:mv_battery_box",
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_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"
},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local meta = minetest.env:get_meta(pos)
local max_charge = 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_tools(meta, current_charge, 4000)
current_charge = discharge_tools(meta, current_charge, max_charge, 4000)
-- 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
local i=math.ceil((current_charge/max_charge)*8)
if i > 8 then i = 8 end
local j = meta:get_float("last_side_shown")
if i~=j then
if i>0 then hacky_swap_node(pos,"technic:mv_battery_box"..i)
elseif i==0 then hacky_swap_node(pos,"technic:mv_battery_box") end
meta:set_float("last_side_shown",i)
end
local load = math.floor(current_charge/max_charge * 100)
meta:set_string("formspec",
battery_box_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"..
(load)..":technic_power_meter_fg.png]"
)
if eu_input == 0 then
meta:set_string("infotext", "MV Battery box: "..current_charge.."/"..max_charge.." (idle)")
else
meta:set_string("infotext", "MV Battery box: "..current_charge.."/"..max_charge)
end
end
})
-- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power
technic.register_MV_machine("technic:mv_battery_box","BA")
for i=1,8,1 do
technic.register_MV_machine("technic:mv_battery_box"..i,"BA")
end

View File

@ -1,305 +0,0 @@
-- MV Electric Furnace
-- This is a faster version of the stone furnace which runs on EUs
-- In addition to this it can be upgraded with microcontrollers and batteries
-- This new version uses the batteries to lower the power consumption of the machine
-- Also in addition this furnace can be attached to the pipe system from the pipeworks mod.
-- 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'},
}
})
local mv_electric_furnace_formspec =
"invsize[8,10;]"..
"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]"..
"list[current_name;upgrade1;1,4;1,1;]"..
"list[current_name;upgrade2;2,4;1,1;]"..
"label[1,5;Upgrade Slots]"
minetest.register_node(
"technic:mv_electric_furnace",
{description = "MV Electric furnace",
tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png",
"technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front.png"},
paramtype2 = "facedir",
groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,},
tube={insert_object=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:add_item("src",stack)
end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:room_for_item("src",stack)
end,
connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
},
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "MV Electric furnace")
meta:set_float("technic_mv_power_machine", 1)
meta:set_int("tube_time", 0)
meta:set_string("formspec", mv_electric_furnace_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
inv:set_size("upgrade1", 1)
inv:set_size("upgrade2", 1)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") 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:mv_electric_furnace_active",
{description = "MV Electric Furnace",
tiles = {"technic_mv_electric_furnace_top.png", "technic_mv_electric_furnace_bottom.png", "technic_mv_electric_furnace_side_tube.png",
"technic_mv_electric_furnace_side_tube.png", "technic_mv_electric_furnace_side.png", "technic_mv_electric_furnace_front_active.png"},
paramtype2 = "facedir",
light_source = 8,
drop = "technic:mv_electric_furnace",
groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1},
tube={insert_object=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:add_item("src",stack)
end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:room_for_item("src",stack)
end,
connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
},
legacy_facedir_simple = true,
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") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") 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,
-- These three makes sure upgrades are not moved in or out while the furnace is active.
allow_metadata_inventory_put = 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_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,
})
local send_cooked_items = function(pos,x_velocity,z_velocity)
-- Send items on their way in the pipe system.
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
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
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "MV")
-- Execute always logic
-- CODE HERE --
-- 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
-- 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 since we tube stuff
-- out while being idle.
if inv:is_empty("src") then
next_state = 1
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
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
elseif state == 2 or state == 3 or state == 4 then
hacky_swap_node(pos, machine_node.."_active")
meta:set_string("infotext", machine_name.." Active")
result = smelt_item(pos, data)
if result == 0 then
next_state = 1
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,
})
technic.register_MV_machine ("technic:mv_electric_furnace","RE")
technic.register_MV_machine ("technic:mv_electric_furnace_active","RE")

View File

@ -1,293 +0,0 @@
-- MV grinder
minetest.register_craft({
output = 'technic:mv_grinder',
recipe = {
{'technic:stainless_steel_ingot', 'technic:grinder', 'technic:stainless_steel_ingot'},
{'pipeworks:tube_000000', 'technic:mv_transformer', 'pipeworks:tube_000000'},
{'technic:stainless_steel_ingot', 'technic:mv_cable', 'technic:stainless_steel_ingot'},
}
})
minetest.register_craftitem("technic:mv_grinder", {
description = "MV Grinder",
stack_max = 99,
})
local mv_grinder_formspec =
"invsize[8,10;]"..
"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 Grinder]"..
"list[current_name;upgrade1;1,4;1,1;]"..
"list[current_name;upgrade2;2,4;1,1;]"..
"label[1,5;Upgrade Slots]"
minetest.register_node(
"technic:mv_grinder",
{
description = "MV Grinder",
tiles = {"technic_mv_grinder_top.png", "technic_mv_grinder_bottom.png", "technic_mv_grinder_side.png",
"technic_mv_grinder_side.png", "technic_mv_grinder_side.png", "technic_mv_grinder_front.png"},
paramtype2 = "facedir",
groups = {cracky=2, tubedevice=1,tubedevice_receiver=1,},
tube={insert_object=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:add_item("src",stack)
end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:room_for_item("src",stack)
end,
connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_string("infotext", "MV Grinder")
meta:set_float("technic_mv_power_machine", 1)
meta:set_int("tube_time", 0)
meta:set_string("formspec", mv_grinder_formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
inv:set_size("upgrade1", 1)
inv:set_size("upgrade2", 1)
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos);
local inv = meta:get_inventory()
if not inv:is_empty("src") or not inv:is_empty("dst") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") 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:mv_grinder_active",
{
description = "Grinder",
tiles = {"technic_mv_grinder_top.png", "technic_mv_grinder_bottom.png", "technic_mv_grinder_side.png",
"technic_mv_grinder_side.png", "technic_mv_grinder_side.png", "technic_mv_grinder_front_active.png"},
paramtype2 = "facedir",
groups = {cracky=2,tubedevice=1,tubedevice_receiver=1,not_in_creative_inventory=1},
tube={ insert_object=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:add_item("src",stack)
end,
can_insert=function(pos,node,stack,direction)
local meta=minetest.env:get_meta(pos)
local inv=meta:get_inventory()
return inv:room_for_item("src",stack)
end,
connect_sides = {left=1, right=1, back=1, top=1, bottom=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") or not inv:is_empty("upgrade1") or not inv:is_empty("upgrade2") 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,
-- These three makes sure upgrades are not moved in or out while the grinder is active.
allow_metadata_inventory_put = 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_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,
})
local send_grinded_items = function(pos,x_velocity,z_velocity)
-- Send items on their way in the pipe system.
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
minetest.register_abm(
{ nodenames = {"technic:mv_grinder","technic:mv_grinder_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- Run a machine through its states. Takes the same arguments as the ABM action
-- and adds the machine's states and any extra data which is needed by the machine.
-- A machine is characterized by running through a set number of states (usually 2:
-- Idle and active) in some order. A state decides when to move to the next one
-- and the machine only changes state if it is powered correctly.
-- The machine will automatically shut down if disconnected from power in some fashion.
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 Grinder"
local machine_node = "technic:mv_grinder"
local machine_state_demand = { 50, 600, 450, 300 }
-- 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
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, "MV")
-- 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()
local empty = inv:is_empty("src")
-- get the names of the upgrades
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_grinded_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 since we tube stuff
-- out while being idle.
if inv:is_empty("src") then
next_state = 1
end
if state == 1 then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
local result = technic.get_grinder_recipe(inv:get_stack("src", 1))
if not empty and result and inv:room_for_item("dst",result) then
meta:set_int("src_time", 0)
next_state = 2+EU_saving_upgrade
end
elseif state == 2 or state == 3 or state == 4 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") == 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("MV_EU_demand", machine_state_demand[next_state])
meta:set_int("state", next_state)
end
end
})
technic.register_MV_machine ("technic:mv_grinder","RE")
technic.register_MV_machine ("technic:mv_grinder_active","RE")

View File

@ -1,226 +0,0 @@
-- 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.
--
-- Punching the radiator will toggle the power state of all attached appliances.
--
local power_radius = 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("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 = power_radius
-- 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 pairs(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
local toggle_on_off_inductive_appliances = function(pos, node, puncher)
if pos == nil then return end
-- The supply radius
local rad = power_radius
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 pairs(positions) do
local meta1 = minetest.env:get_meta(pos1)
if meta1:get_string("has_supply") == pos.x..pos.y..pos.z then
minetest.env:punch_node(pos1)
end
end
end
minetest.register_node(
"technic:power_radiator", {
description = "Power Radiator",
tiles = {"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png",
"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.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,
on_punch = function(pos, node, puncher)
toggle_on_off_inductive_appliances(pos, node, puncher)
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)
meta:set_int("connected_EU_demand", 0)
meta:set_int("MV_EU_demand",1)
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 = power_radius
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 pairs(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 = math.floor(meta1:get_int("EU_demand")/eff_factor)
if connected_EU_demand + app_eu_demand <= max_charge then
--print("I can supply this:"..connected_EU_demand.."|"..app_eu_demand.."<="..max_charge.."|act:"..meta1:get_int("EU_charge"))
-- 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)
--Always 0: 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 = used_charge+math.floor(meta1:get_int("EU_charge")/eff_factor)
--print("My Lamp ("..pos.x..","..pos.y..","..pos.z..") Used:"..used_charge.."Max:"..max_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

@ -1,82 +0,0 @@
-- The medium voltage solar array is an assembly of low voltage arrays.
-- The assembly can deliver medium voltage levels and is a 10% less efficient
-- compared to 5 individual low voltage arrays due to losses in the transformer.
-- However medium voltage is supplied.
-- Solar arrays are not able to store large amounts of energy.
-- The MV arrays are used to make high voltage arrays.
minetest.register_node("technic:solar_array_mv", {
tiles = {"technic_mv_solar_array_top.png", "technic_mv_solar_array_bottom.png", "technic_mv_solar_array_side.png",
"technic_mv_solar_array_side.png", "technic_mv_solar_array_side.png", "technic_mv_solar_array_side.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
description="MV Solar Array",
active = false,
drawtype = "nodebox",
paramtype = "light",
is_ground_content = true,
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
selection_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
meta:set_float("technic_mv_power_machine", 1)
meta:set_int("MV_EU_supply", 0)
meta:set_string("infotext", "MV Solar Array")
end,
})
minetest.register_craft(
{
output = 'technic:solar_array_mv 1',
recipe = {
{'technic:solar_array_lv', 'technic:solar_array_lv','technic:solar_array_lv'},
{'technic:solar_array_lv', 'technic:mv_transformer','technic:solar_array_lv'},
{'default:steel_ingot', 'technic:mv_cable', 'default:steel_ingot'},
}
})
minetest.register_abm(
{nodenames = {"technic:solar_array_mv"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- The action here is to make the solar array produce power
-- Power is dependent on the light level and the height above ground
-- 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.
-- 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.
-- To take care of some of it solar panels do not work outside daylight hours or if
-- built below -10m
local pos1={}
pos1.y=pos.y+1
pos1.x=pos.x
pos1.z=pos.z
local light = minetest.env:get_node_light(pos1, nil)
local time_of_day = minetest.env:get_timeofday()
local meta = minetest.env:get_meta(pos)
if light == nil then light = 0 end
-- turn on array only during day time and if sufficient light
-- 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
local charge_to_give = math.floor(light*(light*2.4+pos1.y/130*12))
if charge_to_give<0 then charge_to_give=0 end
if charge_to_give>160 then charge_to_give=160 end
meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
-- meta:set_float("active",1)
meta:set_int("MV_EU_supply", charge_to_give)
else
meta:set_string("infotext", "Solar Array is inactive");
meta:set_int("MV_EU_supply", 0)
end
end,
})
technic.register_MV_machine ("technic:solar_array_mv","PR")

View File

@ -1,400 +0,0 @@
--MV cable node boxes
minetest.register_alias("mv_cable", "technic:mv_cable")
minetest.register_craft({
output = 'technic:mv_cable 3',
recipe ={
{'technic:rubber','technic:rubber','technic:rubber'},
{'technic:lv_cable','technic:lv_cable','technic:lv_cable'},
{'technic:rubber','technic:rubber','technic:rubber'},
}
})
minetest.register_craftitem("technic:mv_cable", {
description = "Medium Voltage Copper Cable",
stack_max = 99,
})
minetest.register_node("technic:mv_cable", {
description = "Medium Voltage Copper Cable",
tiles = {"technic_mv_cable.png"},
inventory_image = "technic_mv_cable_wield.png",
wield_image = "technic_mv_cable_wield.png",
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
drop = "technic:mv_cable",
mv_cablelike=1,
rules_x1=0,
rules_x2=0,
rules_y1=0,
rules_y2=0,
rules_z1=0,
rules_z2=0,
paramtype = "light",
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {
{ -0.1 , -0.1 , -0.1 , 0.1 , 0.1 , 0.1 },
}},
node_box = {
type = "fixed",
fixed = {
{ -0.1 , -0.1 , -0.1 , 0.1 , 0.1 , 0.1 },
}},
on_construct = function(pos)
meta=minetest.env:get_meta(pos)
meta:set_float("mv_cablelike",1)
meta:set_float("x1",0)
meta:set_float("x2",0)
meta:set_float("y1",0)
meta:set_float("y2",0)
meta:set_float("z1",0)
meta:set_float("z2",0)
MV_check_connections (pos)
end,
after_dig_node = function (pos, oldnode, oldmetadata, digger)
MV_check_connections_on_destroy (pos)
end,
})
str_y1= { -0.1 , -0.1 , -0.1 , 0.1 , 0.5, 0.1 } --0 y+
str_x1= { -0.1 , -0.1 , -0.1 , 0.5, 0.1 , 0.1 } --0 x+
str_z1= { -0.1 , -0.1 , 0.1 , 0.1 , 0.1 , 0.5 } --0 z+
str_z2= { -0.1 , -0.1, -0.5 , 0.1 , 0.1 , 0.1 } --0 z-
str_y2= { -0.1 , -0.5, -0.1 , 0.1 , 0.1 , 0.1 } --0 y-
str_x2= { -0.5 , -0.1, -0.1 , 0.1 , 0.1 , 0.1 } --0 x-
local x1,x2,y1,y2,z1,z2
local count=0
for x1 = 0, 1, 1 do --x-
for x2 = 0, 1, 1 do --x+
for y1 = 0, 1, 1 do --y-
for y2 = 0, 1, 1 do --y-
for z1 = 0, 1, 1 do --z-
for z2 = 0, 1, 1 do --z+
temp_x1={} temp_x2={} temp_y1={} temp_y2={} temp_z1={} temp_z2={}
if x1==1 then temp_x1=str_x1 end
if x2==1 then temp_x2=str_x2 end
if y1==1 then temp_y1=str_y1 end
if y2==1 then temp_y2=str_y2 end
if z1==1 then temp_z1=str_z1 end
if z2==1 then temp_z2=str_z2 end
minetest.register_node("technic:mv_cable"..count, {
description = "Medium Voltage Copper Cable",
tiles = {"technic_mv_cable.png"},
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
sounds = default.node_sound_wood_defaults(),
drop = "technic:mv_cable",
rules_x1=0,
rules_x2=0,
rules_y1=0,
rules_y2=0,
rules_z1=0,
rules_z2=0,
cablelike=1,
paramtype = "light",
drawtype = "nodebox",
selection_box = {
type = "fixed",
fixed = {
temp_x1,temp_x2,temp_y1,temp_y2,temp_z1,temp_z2,
}},
node_box = {
type = "fixed",
fixed = {
temp_x1,temp_x2,temp_y1,temp_y2,temp_z1,temp_z2,
}},
after_dig_node = function (pos, oldnode, oldmetadata, digger)
MV_check_connections_on_destroy (pos)
end,
})
count=count+1 end end end end end end
MV_check_connections = function(pos)
local pos1={}
pos1.x=pos.x
pos1.y=pos.y
pos1.z=pos.z
pos1.x=pos1.x+1
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
x2=1
x1=minetest.env:get_meta(pos1):get_float("x1")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:mv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("x2",x2)
meta=minetest.env:get_meta(pos)
x1=1
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("x1",x1)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:mv_cable"..rule)
end
pos1.x=pos1.x-2
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
x1=1
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:mv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("x1",x1)
meta=minetest.env:get_meta(pos)
x2=1
x1=minetest.env:get_meta(pos):get_float("x1")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("x2",x2)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:mv_cable"..rule)
end
pos1.x=pos1.x+1
pos1.y=pos1.y+1
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
y2=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:mv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("y2",y2)
meta=minetest.env:get_meta(pos)
y1=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("y1",y1)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:mv_cable"..rule)
end
if minetest.env:get_meta(pos1):get_float("technic_mv_power_machine")==1 then
y1=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:mv_cable"..rule)
meta=minetest.env:get_meta(pos)
meta:set_float("y1",y1)
end
pos1.y=pos1.y-2
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
y1=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:mv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("y1",y1)
meta=minetest.env:get_meta(pos)
y2=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
z1=minetest.env:get_meta(pos):get_float("z1")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("y2",y2)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:mv_cable"..rule)
end
pos1.y=pos1.y+1
pos1.z=pos1.z+1
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
z2=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:mv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("z2",z2)
meta=minetest.env:get_meta(pos)
z1=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z2=minetest.env:get_meta(pos):get_float("z2")
meta:set_float("z1",z1)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:mv_cable"..rule)
end
pos1.z=pos1.z-2
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
z1=1
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos1,"technic:mv_cable"..rule)
meta=minetest.env:get_meta(pos1)
meta:set_float("z1",z1)
meta=minetest.env:get_meta(pos)
z2=1
x1=minetest.env:get_meta(pos):get_float("x1")
x2=minetest.env:get_meta(pos):get_float("x2")
y1=minetest.env:get_meta(pos):get_float("y1")
y2=minetest.env:get_meta(pos):get_float("y2")
z1=minetest.env:get_meta(pos):get_float("z1")
meta:set_float("z2",z2)
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
hacky_swap_node(pos,"technic:mv_cable"..rule)
end
pos1.z=pos1.z+1
end
MV_check_connections_on_destroy = function(pos)
local pos1={}
pos1.x=pos.x
pos1.y=pos.y
pos1.z=pos.z
pos1.x=pos1.x+1
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
x2=0
x1=minetest.env:get_meta(pos1):get_float("x1")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:mv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:mv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("x2",x2)
end
pos1.x=pos1.x-2
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
x1=0
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:mv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:mv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("x1",x1)
end
pos1.x=pos1.x+1
pos1.y=pos1.y+1
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
y2=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:mv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:mv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("y2",y2)
end
pos1.y=pos1.y-2
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
y1=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:mv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:mv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("y1",y1)
end
pos1.y=pos1.y+1
pos1.z=pos1.z+1
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
z2=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z1=minetest.env:get_meta(pos1):get_float("z1")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:mv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:mv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("z2",z2)
end
pos1.z=pos1.z-2
if minetest.env:get_meta(pos1):get_float("mv_cablelike")==1 then
z1=0
x1=minetest.env:get_meta(pos1):get_float("x1")
x2=minetest.env:get_meta(pos1):get_float("x2")
y1=minetest.env:get_meta(pos1):get_float("y1")
y2=minetest.env:get_meta(pos1):get_float("y2")
z2=minetest.env:get_meta(pos1):get_float("z2")
rule=make_rule_number(x1,x2,y1,y2,z1,z2)
if rule==0 then hacky_swap_node(pos1,"technic:mv_cable") end
if rule>0 then hacky_swap_node(pos1,"technic:mv_cable"..rule) end
meta=minetest.env:get_meta(pos1)
meta:set_float("z1",z1)
end
pos1.y=pos1.y+1
end

View File

@ -20,7 +20,7 @@ minetest.register_craft({
})
mk1_on = function(pos, node)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local pos1={}
pos1.x=pos.x
@ -34,7 +34,7 @@ mk1_on = function(pos, node)
if node.name == "technic:constructor_mk1_off" then
hacky_swap_node(pos,"technic:constructor_mk1_on")
nodeupdate(pos)
local node1=minetest.env:get_node(pos1)
local node1=minetest.get_node(pos1)
deploy_node (inv,"slot1",pos1,node1,node)
end
end
@ -57,7 +57,7 @@ minetest.register_node("technic:constructor_mk1_off", {
mesecons= {effector={action_on=mk1_on}},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"invsize[8,9;]"..
"label[0,0;Constructor MK1]"..
@ -70,7 +70,7 @@ minetest.register_node("technic:constructor_mk1_off", {
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:is_empty("slot1")
end,
@ -91,7 +91,7 @@ minetest.register_node("technic:constructor_mk1_on", {
--Constructor MK2
mk2_on = function(pos, node)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local pos1={}
local pos2={}
@ -109,9 +109,9 @@ mk2_on = function(pos, node)
if node.name == "technic:constructor_mk2_off" then
hacky_swap_node(pos,"technic:constructor_mk2_on")
nodeupdate(pos)
local node1=minetest.env:get_node(pos1)
local node1=minetest.get_node(pos1)
deploy_node (inv,"slot1",pos1,node1,node)
local node1=minetest.env:get_node(pos2)
local node1=minetest.get_node(pos2)
deploy_node (inv,"slot2",pos2,node1,node)
end
end
@ -133,7 +133,7 @@ minetest.register_node("technic:constructor_mk2_off", {
mesecons= {effector={action_on=mk2_on}},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"invsize[8,9;]"..
"label[0,0;Constructor MK2]"..
@ -149,7 +149,7 @@ minetest.register_node("technic:constructor_mk2_off", {
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:is_empty("slot1")==false or inv:is_empty("slot2")==false then return false end
return true
@ -170,7 +170,7 @@ minetest.register_node("technic:constructor_mk2_on", {
-- Constructor MK3
mk3_on = function(pos, node)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local pos1={}
@ -202,13 +202,13 @@ mk3_on = function(pos, node)
if node.name == "technic:constructor_mk3_off" then
hacky_swap_node(pos,"technic:constructor_mk3_on")
nodeupdate(pos)
local node1=minetest.env:get_node(pos1)
local node1=minetest.get_node(pos1)
deploy_node (inv,"slot1",pos1,node1,node)
local node1=minetest.env:get_node(pos2)
local node1=minetest.get_node(pos2)
deploy_node (inv,"slot2",pos2,node1,node)
local node1=minetest.env:get_node(pos3)
local node1=minetest.get_node(pos3)
deploy_node (inv,"slot3",pos3,node1,node)
local node1=minetest.env:get_node(pos4)
local node1=minetest.get_node(pos4)
deploy_node (inv,"slot4",pos4,node1,node)
end
end
@ -230,7 +230,7 @@ minetest.register_node("technic:constructor_mk3_off", {
mesecons= {effector={action_on=mk3_on}},
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",
"invsize[8,9;]"..
"label[0,0;Constructor MK2]"..
@ -253,7 +253,7 @@ minetest.register_node("technic:constructor_mk3_off", {
end,
can_dig = function(pos,player)
local meta = minetest.env:get_meta(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
if inv:is_empty("slot1")==false or inv:is_empty("slot2")==false or inv:is_empty("slot3")==false or inv:is_empty("slot4")==false then return false end
return true
@ -279,7 +279,7 @@ deploy_node =function (inv, slot_name, pos1, node1, node)
local def = stack1[1]:get_definition()
if def.type == "node" then
node_to_be_placed={name=stack1[1]:get_name(), param1=0, param2=node.param2}
minetest.env:set_node(pos1,node_to_be_placed)
minetest.set_node(pos1,node_to_be_placed)
stack1[1]:take_item()
inv:set_stack(slot_name, 1, stack1[1])
elseif def.type == "craft" then
@ -334,10 +334,10 @@ deploy_node =function (inv, slot_name, pos1, node1, node)
end
loop = loop + 1
end
minetest.env:remove_node(pos1)
minetest.remove_node(pos1)
elseif type(drop) == "string" then
inv:add_item(slot_name,drop)
minetest.env:remove_node(pos1)
minetest.remove_node(pos1)
end
end

View File

@ -0,0 +1,284 @@
-- Register alloy recipes
technic.alloy_recipes = {}
-- Register recipe in a table
technic.register_alloy_recipe = function(metal1, count1, metal2, count2, result, count3)
in1 = {
name = metal1,
count = count1,
}
in2 = {
name = metal2,
count = count2,
}
-- Sort the inputs alphebetically
if in1.name > in2.name then
local temp = in1
in1 = in2
in2 = temp
end
technic.alloy_recipes[in1.name.." "..in2.name] = {
input = {in1, in2},
output = {
name = result,
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.
function technic.get_alloy_recipe(stack1, stack2)
-- Sort the stacks alphebetically
if stack1:get_name() > stack2:get_name() then
local temp = stack1
stack1 = stack2
stack2 = temp
end
for _, recipe in pairs(technic.alloy_recipes) do
if recipe.input[1].name == stack1:get_name() and
recipe.input[2].name == stack2:get_name() and
stack1:get_count() >= recipe.input[1].count and
stack2:get_count() >= recipe.input[2].count then
return recipe
end
end
end
technic.register_alloy_recipe("technic:copper_dust", 3, "technic:tin_dust", 1, "technic:bronze_dust", 4)
technic.register_alloy_recipe("default: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("default: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)
function technic.register_alloy_furnace(data)
local tier = data.tier
local ltier = string.lower(tier)
local tube_side_texture = data.tube and "technic_"..ltier.."_alloy_furnace_side_tube.png"
or "technic_"..ltier.."_alloy_furnace_side.png"
local groups = {cracky=2}
local active_groups = {cracky=2, not_in_creative_inventory=1}
if data.tube then
groups.tubedevice = 1
groups.tubedevice_receiver = 1
active_groups.tubedevice = 1
active_groups.tubedevice_receiver = 1
end
local formspec =
"invsize[8,10;]"..
"label[0,0;"..tier.." Alloy Furnace]"..
"list[current_name;src;3,1;1,2;]"..
"list[current_name;dst;5,1;2,2;]"..
"list[current_player;main;0,6;8,4;]"
if data.upgrade then
formspec = formspec..
"list[current_name;upgrade1;1,4;1,1;]"..
"list[current_name;upgrade2;2,4;1,1;]"..
"label[1,5;Upgrade Slots]"
end
data.formspec = formspec
local tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:add_item("src", stack)
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:room_for_item("src", stack)
end,
connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
}
minetest.register_node("technic:"..ltier.."_alloy_furnace", {
description = tier.." Alloy Furnace",
tiles = {"technic_"..ltier.."_alloy_furnace_top.png",
"technic_"..ltier.."_alloy_furnace_bottom.png",
tube_side_texture,
tube_side_texture,
"technic_"..ltier.."_alloy_furnace_side.png",
"technic_"..ltier.."_alloy_furnace_front.png"},
paramtype2 = "facedir",
groups = groups,
tube = tube,
technic = data,
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local name = minetest.get_node(pos).name
local data = minetest.registered_nodes[name].technic
meta:set_string("infotext", data.tier.." Alloy furnace")
meta:set_string("formspec", data.formspec)
meta:set_int("tube_time", 0)
local inv = meta:get_inventory()
inv:set_size("src", 2)
inv:set_size("dst", 4)
inv:set_size("upgrade1", 1)
inv:set_size("upgrade2", 1)
end,
can_dig = function(pos, player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
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
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:"..ltier.."_alloy_furnace_active",{
description = tier.." Alloy Furnace",
tiles = {"technic_"..ltier.."_alloy_furnace_top.png",
"technic_"..ltier.."_alloy_furnace_bottom.png",
tube_side_texture,
tube_side_texture,
"technic_"..ltier.."_alloy_furnace_side.png",
"technic_"..ltier.."_alloy_furnace_front_active.png"},
paramtype2 = "facedir",
light_source = 8,
drop = "technic:"..ltier.."_alloy_furnace",
groups = active_groups,
tube = tube,
technic = data,
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
can_dig = function(pos, player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
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
minetest.chat_send_player(player:get_player_name(),
"Machine cannot be removed because it is not empty");
return false
else
return true
end
end,
-- These three makes sure upgrades are not moved in or out while the furnace is active.
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if listname == "src" or listname == "dst" then
return stack:get_count()
else
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 stack:get_count()
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({
nodenames = {"technic:"..ltier.."_alloy_furnace", "technic:"..ltier.."_alloy_furnace_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local data = minetest.registered_nodes[node.name].technic
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local eu_input = meta:get_int(data.tier.."_EU_input")
-- Machine information
local machine_name = data.tier.." Alloy Furnace"
local machine_node = "technic:"..string.lower(data.tier).."_alloy_furnace"
local machine_demand = data.demand
-- Setup meta data if it does not exist.
if not eu_input then
meta:set_int(data.tier.."_EU_demand", machine_demand[1])
meta:set_int(data.tier.."_EU_input", 0)
end
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, data.tier)
local EU_upgrade, tube_upgrade = 0, 0
if data.upgrade then
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
end
if data.tube then
technic.handle_machine_pipeworks(pos, tube_upgrade)
end
-- Get what to cook if anything
local srcstack = inv:get_stack("src", 1)
local src2stack = inv:get_stack("src", 2)
local recipe = technic.get_alloy_recipe(srcstack, src2stack)
local result = recipe and ItemStack(recipe.output) or nil
-- Sort the stacks alphabetically
if srcstack:get_name() > src2stack:get_name() then
local temp = srcstack
srcstack = src2stack
src2stack = temp
end
if not result then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
meta:set_int(data.tier.."_EU_demand", 0)
return
end
if eu_input < machine_demand[EU_upgrade+1] then
-- Unpowered - go idle
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
next_state = 1
elseif eu_input >= machine_demand[EU_upgrade+1] then
-- Powered
hacky_swap_node(pos, machine_node.."_active")
meta:set_string("infotext", machine_name.." Active")
meta:set_int("src_time", meta:get_int("src_time") + 1)
if meta:get_int("src_time") == data.cook_time then
meta:set_int("src_time", 0)
-- check if there's room for output and that we have the materials
if inv:room_for_item("dst", result) then
srcstack:take_item(recipe.input[1].count)
inv:set_stack("src", 1, srcstack)
src2stack:take_item(recipe.input[2].count)
inv:set_stack("src", 2, src2stack)
-- Put result in "dst" list
inv:add_item("dst", result)
else
next_state = 1
end
end
end
meta:set_int(data.tier.."_EU_demand", machine_demand[EU_upgrade+1])
end,
})
technic.register_machine(tier, "technic:"..ltier.."_alloy_furnace", technic.receiver)
technic.register_machine(tier, "technic:"..ltier.."_alloy_furnace_active", technic.receiver)
end -- End registration

View File

@ -0,0 +1,216 @@
technic.battery_box_formspec =
"invsize[8,9;]"..
"image[1,1;1,2;technic_power_meter_bg.png]"..
"list[current_name;src;3,1;1,1;]"..
"image[4,1;1,1;technic_battery_reload.png]"..
"list[current_name;dst;5,1;1,1;]"..
"label[0,0;Battery Box]"..
"label[3,0;Charge]"..
"label[5,0;Discharge]"..
"label[1,3;Power level]"..
"list[current_player;main;0,5;8,4;]"
function technic.register_battery_box(data)
local tier = data.tier
local ltier = string.lower(tier)
for i = 0, 8 do
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2}
if i ~= 0 then
groups.not_in_creative_inventory = 1
end
minetest.register_node("technic:"..ltier.."_battery_box"..i, {
description = tier.." Battery Box",
tiles = {"technic_"..ltier.."_battery_box_top.png",
"technic_"..ltier.."_battery_box_bottom.png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png",
"technic_"..ltier.."_battery_box_side.png^technic_power_meter"..i..".png"},
groups = groups,
sounds = default.node_sound_wood_defaults(),
drop = "technic:"..ltier.."_battery_box0",
technic = data,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local node = minetest.get_node(pos)
local data = minetest.registered_nodes[node.name].technic
meta:set_string("infotext", data.tier.." Battery Box")
meta:set_string("formspec", battery_box_formspec)
meta:set_int(data.tier.."_EU_demand", 0)
meta:set_int(data.tier.."_EU_supply", 0)
meta:set_int(data.tier.."_EU_input", 0)
meta:set_float("internal_EU_charge", 0)
inv:set_size("src", 1)
inv:set_size("dst", 1)
end,
can_dig = function(pos,player)
local meta = minetest.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_abm({
nodenames = {"technic:"..ltier.."_battery_box0", "technic:"..ltier.."_battery_box1",
"technic:"..ltier.."_battery_box2", "technic:"..ltier.."_battery_box3",
"technic:"..ltier.."_battery_box4", "technic:"..ltier.."_battery_box5",
"technic:"..ltier.."_battery_box6", "technic:"..ltier.."_battery_box7",
"technic:"..ltier.."_battery_box8"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local data = minetest.registered_nodes[node.name].technic
local meta = minetest.get_meta(pos)
local eu_input = meta:get_int(data.tier.."_EU_input")
local current_charge = meta:get_int("internal_EU_charge")
local max_charge = data.max_charge
local charge_rate = data.charge_rate
local discharge_rate = data.discharge_rate
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, data.tier)
-- 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 = technic.charge_tools(meta,
current_charge, data.charge_step)
current_charge = technic.discharge_tools(meta,
current_charge, data.discharge_step, max_charge)
-- We allow batteries to charge on less than the demand
meta:set_int(data.tier.."_EU_demand",
math.min(charge_rate, max_charge - current_charge))
meta:set_int(data.tier.."_EU_supply",
math.min(discharge_rate, current_charge))
meta:set_int("internal_EU_charge", current_charge)
-- Select node textures
local charge_count = math.ceil((current_charge / max_charge) * 8)
charge_count = math.min(charge_count, 8)
charge_count = math.max(charge_count, 0)
local last_count = meta:get_float("last_side_shown")
if charge_count ~= last_count then
hacky_swap_node(pos,"technic:"..string.lower(data.tier).."_battery_box"..charge_count)
meta:set_float("last_side_shown", charge_count)
end
local charge_percent = math.floor(current_charge / max_charge * 100)
meta:set_string("formspec",
technic.battery_box_formspec..
"image[1,1;1,2;technic_power_meter_bg.png^[lowpart:"
..charge_percent..":technic_power_meter_fg.png]")
local infotext = data.tier.." battery box: "
..current_charge.."/"..max_charge
if eu_input == 0 then
infotext = infotext.." (idle)"
end
meta:set_string("infotext", infotext)
end
})
-- Register as a battery type
-- Battery type machines function as power reservoirs and can both receive and give back power
for i = 0, 8 do
technic.register_machine(tier, "technic:"..ltier.."_battery_box"..i, technic.battery)
end
end -- End registration
function technic.charge_tools(meta, charge, charge_step)
--charge registered power tools
local inv = meta:get_inventory()
if not inv:is_empty("src") then
local srcstack = inv:get_stack("src", 1)
local src_item = srcstack:to_table()
local src_meta = get_item_meta(src_item["metadata"])
local toolname = src_item["name"]
if technic.power_tools[toolname] ~= nil then
-- Set meta data for the tool if it didn't do it itself :-(
src_meta = get_item_meta(src_item["metadata"])
src_meta = src_meta or {}
if src_meta["charge"] == nil then
src_meta["charge"] = 0
end
-- Do the charging
local item_max_charge = technic.power_tools[toolname]
local tool_charge = src_meta["charge"]
if tool_charge < item_max_charge and charge > 0 then
if charge - charge_step < 0 then
charge_step = charge
end
if tool_charge + charge_step > item_max_charge then
charge_step = item_max_charge - tool_charge
end
tool_charge = tool_charge + charge_step
charge = charge - charge_step
technic.set_RE_wear(src_item, tool_charge, item_max_charge)
src_meta["charge"] = tool_charge
src_item["metadata"] = set_item_meta(src_meta)
inv:set_stack("src", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end
function technic.discharge_tools(meta, charge, charge_step, max_charge)
-- discharging registered power tools
local inv = meta:get_inventory()
if not inv:is_empty("dst") then
srcstack = inv:get_stack("dst", 1)
src_item = srcstack:to_table()
local src_meta = get_item_meta(src_item["metadata"])
local toolname = src_item["name"]
if technic.power_tools[toolname] ~= nil then
-- Set meta data for the tool if it didn't do it itself :-(
src_meta = get_item_meta(src_item["metadata"])
src_meta = src_meta or {}
if src_meta["charge"] == nil then
src_meta["charge"] = 0
end
-- Do the discharging
local item_max_charge = technic.power_tools[toolname]
local tool_charge = src_meta["charge"]
if tool_charge > 0 and charge < max_charge then
if charge + charge_step > max_charge then
charge_step = max_charge - charge
end
if tool_charge - charge_step < 0 then
charge_step = charge
end
tool_charge = tool_charge - charge_step
charge = charge + charge_step
technic.set_RE_wear(src_item, tool_charge, item_max_charge)
src_meta["charge"] = tool_charge
src_item["metadata"] = set_item_meta(src_meta)
inv:set_stack("dst", 1, src_item)
end
end
end
return charge -- return the remaining charge in the battery
end

View File

@ -0,0 +1,170 @@
technic.cables = {}
function technic.register_cable(tier, size)
local ltier = string.lower(tier)
for x1 = 0, 1 do
for x2 = 0, 1 do
for y1 = 0, 1 do
for y2 = 0, 1 do
for z1 = 0, 1 do
for z2 = 0, 1 do
local id = technic.get_cable_id({x1, x2, y1, y2, z1, z2})
technic.cables["technic:"..ltier.."_cable"..id] = tier
local groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2}
if id ~= 0 then
groups.not_in_creative_inventory = 1
end
minetest.register_node("technic:"..ltier.."_cable"..id, {
description = tier.." Cable",
tiles = {"technic_"..ltier.."_cable.png"},
inventory_image = "technic_"..ltier.."_cable_wield.png",
wield_image = "technic_"..ltier.."_cable_wield.png",
groups = groups,
sounds = default.node_sound_wood_defaults(),
drop = "technic:"..ltier.."_cable0",
paramtype = "light",
sunlight_propagates = true,
drawtype = "nodebox",
node_box = {
type = "fixed",
fixed = technic.gen_cable_nodebox(x1, y1, z1, x2, y2, z2, size)
},
after_place_node = function(pos)
local node = minetest.get_node(pos)
technic.update_cables(pos, technic.get_cable_tier(node.name))
end,
after_dig_node = function(pos, oldnode)
local tier = technic.get_cable_tier(oldnode.name)
technic.update_cables(pos, tier, true)
end
})
end
end
end
end
end
end
end
minetest.register_on_placenode(function(pos, node)
for tier, machine_list in pairs(technic.machines) do
for machine_name, _ in pairs(machine_list) do
if node.name == machine_name then
technic.update_cables(pos, tier, true)
end
end
end
end)
minetest.register_on_dignode(function(pos, node)
for tier, machine_list in pairs(technic.machines) do
for machine_name, _ in pairs(machine_list) do
if node.name == machine_name then
technic.update_cables(pos, tier, true)
end
end
end
end)
function technic.get_cable_id(links)
return (links[6] * 1) + (links[5] * 2)
+ (links[4] * 4) + (links[3] * 8)
+ (links[2] * 16) + (links[1] * 32)
end
function technic.update_cables(pos, tier, no_set, secondrun)
local link_positions = {
{x=pos.x+1, y=pos.y, z=pos.z},
{x=pos.x-1, y=pos.y, z=pos.z},
{x=pos.x, y=pos.y+1, z=pos.z},
{x=pos.x, y=pos.y-1, z=pos.z},
{x=pos.x, y=pos.y, z=pos.z+1},
{x=pos.x, y=pos.y, z=pos.z-1}}
local links = {0, 0, 0, 0, 0, 0}
for i, link_pos in pairs(link_positions) do
local connect_type = technic.cables_should_connect(pos, link_pos, tier)
if connect_type then
links[i] = 1
-- Have cables next to us update theirselves,
-- but only once. (We don't want to update the entire
-- network or start an infinite loop of updates)
if not secondrun and connect_type == "cable" then
technic.update_cables(link_pos, tier, false, true)
end
end
end
-- We don't want to set ourselves if we have been removed or we are
-- updating a machine
if not no_set then
minetest.set_node(pos, {name="technic:"..string.lower(tier)
.."_cable"..technic.get_cable_id(links)})
end
end
function technic.is_tier_cable(name, tier)
return technic.cables[name] and technic.cables[name] == tier
end
function technic.get_cable_tier(name)
return technic.cables[name]
end
function technic.cables_should_connect(pos1, pos2, tier)
local name = minetest.get_node(pos2).name
if technic.is_tier_cable(name, tier) then
return "cable"
elseif technic.machines[tier][name] then
return "machine"
end
return false
end
function technic.gen_cable_nodebox(x1, y1, z1, x2, y2, z2, size)
-- Nodeboxes
local box_center = {-size, -size, -size, size, size, size}
local box_y1 = {-size, -size, -size, size, 0.5, size} -- y+
local box_x1 = {-size, -size, -size, 0.5, size, size} -- x+
local box_z1 = {-size, -size, size, size, size, 0.5} -- z+
local box_z2 = {-size, -size, -0.5, size, size, size} -- z-
local box_y2 = {-size, -0.5, -size, size, size, size} -- y-
local box_x2 = {-0.5, -size, -size, size, size, size} -- x-
local box = {box_center}
if x1 == 1 then
table.insert(box, box_x1)
end
if y1 == 1 then
table.insert(box, box_y1)
end
if z1 == 1 then
table.insert(box, box_z1)
end
if x2 == 1 then
table.insert(box, box_x2)
end
if y2 == 1 then
table.insert(box, box_y2)
end
if z2 == 1 then
table.insert(box, box_z2)
end
return box
end

View File

@ -0,0 +1,111 @@
function technic.handle_machine_upgrades(meta)
-- Get the names of the upgrades
local inv = meta:get_inventory()
local upg_item1
local upg_item2
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
-- Save some power by installing battery upgrades.
-- Tube loading speed can be upgraded using control logic units.
local EU_upgrade = 0
local tube_upgrade = 0
if upg_item1 then
if upg_item1.name == "technic:battery" then
EU_upgrade = EU_upgrade + 1
elseif upg_item1.name == "technic:control_logic_unit" then
tube_upgrade = tube_upgrade + 1
end
end
if upg_item2 then
if upg_item2.name == "technic:battery" then
EU_upgrade = EU_upgrade + 1
elseif upg_item2.name == "technic:control_logic_unit" then
tube_upgrade = tube_upgrade + 1
end
end
return EU_upgrade, tube_upgrade
end
function technic.send_items(pos, x_velocity, z_velocity)
-- Send items on their way in the pipe system.
local meta = minetest.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
function technic.smelt_item(meta, result, speed)
local inv = meta:get_inventory()
meta:set_int("cook_time", meta:get_int("cook_time") + 1)
if meta:get_int("cook_time") < result.time / speed then
return
end
local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")})
if result and result.item then
meta:set_int("cook_time", 0)
-- check if there's room for output in "dst" list
if inv:room_for_item("dst", result) then
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
inv:add_item("dst", result.item)
end
end
end
function technic.handle_machine_pipeworks(pos, tube_upgrade)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local pos1 = vector.new(pos)
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.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_upgrade
if tube_time > 3 then
tube_time = 0
if output_tube_connected then
technic.send_items(pos, x_velocity, z_velocity)
end
end
meta:set_int("tube_time", tube_time)
end

View File

@ -0,0 +1,203 @@
function technic.register_electric_furnace(data)
local tier = data.tier
local ltier = string.lower(tier)
local tube_side_texture = data.tube and "technic_"..ltier.."_electric_furnace_side_tube.png"
or "technic_"..ltier.."_electric_furnace_side.png"
local tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:add_item("src",stack)
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:room_for_item("src", stack)
end,
connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
}
local formspec =
"invsize[8,10;]"..
"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;"..tier.." Electric Furnace]"
if data.upgrade then
formspec = formspec..
"list[current_name;upgrade1;1,4;1,1;]"..
"list[current_name;upgrade2;2,4;1,1;]"..
"label[1,5;Upgrade Slots]"
end
data.formspec = formspec
minetest.register_node("technic:"..ltier.."_electric_furnace", {
description = tier.." Electric furnace",
tiles = {"technic_"..ltier.."_electric_furnace_top.png",
"technic_"..ltier.."_electric_furnace_bottom.png",
tube_side_texture,
tube_side_texture,
"technic_"..ltier.."_electric_furnace_side.png",
"technic_"..ltier.."_electric_furnace_front.png"},
paramtype2 = "facedir",
groups = {cracky=2, tubedevice=1, tubedevice_receiver=1},
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
tube = tube,
technic = data,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local name = minetest.get_node(pos).name
local data = minetest.registered_nodes[name].technic
meta:set_string("infotext", data.tier.." Electric furnace")
meta:set_int("tube_time", 0)
meta:set_string("formspec", data.formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
inv:set_size("upgrade1", 1)
inv:set_size("upgrade2", 1)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
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
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:"..ltier.."_electric_furnace_active", {
description = tier.." Electric furnace",
tiles = {"technic_"..ltier.."_electric_furnace_top.png",
"technic_"..ltier.."_electric_furnace_bottom.png",
tube_side_texture,
tube_side_texture,
"technic_"..ltier.."_electric_furnace_side.png",
"technic_"..ltier.."_electric_furnace_front_active.png"},
paramtype2 = "facedir",
groups = {cracky=2, tubedevice=1, tubedevice_receiver=1, not_in_creative_inventory=1},
light_source = 8,
legacy_facedir_simple = true,
sounds = default.node_sound_stone_defaults(),
tube = tube,
technic = data,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local name = minetest.get_node(pos).name
local data = minetest.registered_nodes[name].technic
meta:set_string("infotext", data.tier.." Electric furnace")
meta:set_int("tube_time", 0)
meta:set_string("formspec", data.formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
inv:set_size("upgrade1", 1)
inv:set_size("upgrade2", 1)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
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
minetest.chat_send_player(player:get_player_name(),
"Machine cannot be removed because it is not empty");
return false
else
return true
end
end,
-- These three makes sure upgrades are not moved in or out while the furnace is active.
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if listname == "src" or listname == "dst" then
return stack:get_stack_max()
else
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 stack:get_stack_max()
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({
nodenames = {"technic:"..ltier.."_electric_furnace",
"technic:"..ltier.."_electric_furnace_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local data = minetest.registered_nodes[node.name].technic
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local eu_input = meta:get_int(data.tier.."_EU_input")
-- Machine information
local machine_name = data.tier.." Electric Furnace"
local machine_node = "technic:"..string.lower(data.tier).."_electric_furnace"
local machine_demand = data.demand
-- Setup meta data if it does not exist. state is used as an indicator of this
if not eu_input then
meta:set_int(data.tier.."_EU_demand", machine_demand[1])
meta:set_int(data.tier.."_EU_input", 0)
end
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, data.tier)
-- Check upgrade slots
local EU_upgrade, tube_upgrade = 0, 0
if data.upgrade then
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
end
if data.tube then
technic.handle_machine_pipeworks(pos, tube_upgrade)
end
local result = minetest.get_craft_result({
method = "cooking",
width = 1,
items = inv:get_list("src")})
if not result or result.time == 0 then
meta:set_int(data.tier.."_EU_demand", 0)
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
return
end
if eu_input < machine_demand[EU_upgrade+1] then
-- Unpowered - go idle
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
elseif eu_input >= machine_demand[EU_upgrade+1] then
-- Powered
hacky_swap_node(pos, machine_node.."_active")
meta:set_string("infotext", machine_name.." Active")
technic.smelt_item(meta, result, data.speed)
end
meta:set_int(data.tier.."_EU_demand", machine_demand[EU_upgrade+1])
end,
})
technic.register_machine(tier, "technic:"..ltier.."_electric_furnace", technic.receiver)
technic.register_machine(tier, "technic:"..ltier.."_electric_furnace_active", technic.receiver)
end -- End registration

View File

@ -0,0 +1,184 @@
function technic.register_grinder(data)
local tier = data.tier
local ltier = string.lower(tier)
local tube = {
insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:add_item("src", stack)
end,
can_insert = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return inv:room_for_item("src", stack)
end,
connect_sides = {left=1, right=1, back=1, top=1, bottom=1},
}
local formspec =
"invsize[8,10;]"..
"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;"..tier.." Grinder]"
if data.upgrade then
formspec = formspec..
"list[current_name;upgrade1;1,4;1,1;]"..
"list[current_name;upgrade2;2,4;1,1;]"..
"label[1,5;Upgrade Slots]"
end
data.formspec = formspec
minetest.register_node("technic:"..ltier.."_grinder", {
description = tier.." Grinder",
tiles = {"technic_"..ltier.."_grinder_top.png", "technic_"..ltier.."_grinder_bottom.png",
"technic_"..ltier.."_grinder_side.png", "technic_"..ltier.."_grinder_side.png",
"technic_"..ltier.."_grinder_side.png", "technic_"..ltier.."_grinder_front.png"},
paramtype2 = "facedir",
groups = {cracky=2, tubedevice=1, tubedevice_receiver=1},
technic = data,
tube = tube,
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
on_construct = function(pos)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local data = minetest.registered_nodes[node.name].technic
meta:set_string("infotext", data.tier.." Grinder")
meta:set_int("tube_time", 0)
meta:set_string("formspec", data.formspec)
local inv = meta:get_inventory()
inv:set_size("src", 1)
inv:set_size("dst", 4)
inv:set_size("upgrade1", 1)
inv:set_size("upgrade2", 1)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
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
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:"..ltier.."_grinder_active",{
description = tier.." Grinder",
tiles = {"technic_"..ltier.."_grinder_top.png", "technic_"..ltier.."_grinder_bottom.png",
"technic_"..ltier.."_grinder_side.png", "technic_"..ltier.."_grinder_side.png",
"technic_"..ltier.."_grinder_side.png", "technic_"..ltier.."_grinder_front_active.png"},
paramtype2 = "facedir",
groups = {cracky=2, tubedevice=1, tubedevice_receiver=1, not_in_creative_inventory=1},
legacy_facedir_simple = true,
sounds = default.node_sound_wood_defaults(),
technic = data,
tube = tube,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
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
minetest.chat_send_player(player:get_player_name(),
"Machine cannot be removed because it is not empty");
return false
else
return true
end
end,
-- These three makes sure upgrades are not moved in or out while the grinder is active.
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
if listname == "src" or listname == "dst" then
return stack:get_stack_max()
else
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 stack:get_stack_max()
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({
nodenames = {"technic:"..ltier.."_grinder","technic:"..ltier.."_grinder_active"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local data = minetest.registered_nodes[node.name].technic
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local eu_input = meta:get_int(data.tier.."_EU_input")
local machine_name = data.tier.." Grinder"
local machine_node = "technic:"..string.lower(data.tier).."_grinder"
local machine_demand = data.demand
-- Setup meta data if it does not exist.
if not eu_input then
meta:set_int(data.tier.."_EU_demand", machine_demand[1])
meta:set_int(data.tier.."_EU_input", 0)
return
end
-- Power off automatically if no longer connected to a switching station
technic.switching_station_timeout_count(pos, data.tier)
local EU_upgrade, tube_upgrade = 0, 0
if data.upgrade then
EU_upgrade, tube_upgrade = technic.handle_machine_upgrades(meta)
end
if data.tube then
technic.handle_machine_pipeworks(pos, tube_upgrade)
end
local result = technic.get_grinder_recipe(inv:get_stack("src", 1))
if not result then
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Idle")
meta:set_int(data.tier.."_EU_demand", 0)
return
end
if eu_input < machine_demand[EU_upgrade+1] then
-- Unpowered - go idle
hacky_swap_node(pos, machine_node)
meta:set_string("infotext", machine_name.." Unpowered")
elseif eu_input >= machine_demand[EU_upgrade+1] then
-- Powered
hacky_swap_node(pos, machine_node.."_active")
meta:set_string("infotext", machine_name.." Active")
meta:set_int("src_time", meta:get_int("src_time") + 1)
if meta:get_int("src_time") >= result.time / data.speed then
meta:set_int("src_time", 0)
local result_stack = ItemStack(result.output)
if inv:room_for_item("dst", result_stack) then
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
inv:add_item("dst", result_stack)
end
end
end
meta:set_int(data.tier.."_EU_demand", machine_demand[EU_upgrade+1])
end
})
technic.register_machine(tier, "technic:"..ltier.."_grinder", technic.receiver)
technic.register_machine(tier, "technic:"..ltier.."_grinder_active", technic.receiver)
end -- End registration

View File

@ -0,0 +1,94 @@
technic.grinder_recipes = {}
function technic.register_grinder_recipe(data)
data.time = data.time or 3
technic.grinder_recipes[data.input] = data
if unified_inventory then
unified_inventory.register_craft({
type = "grinding",
output = data.output,
items = {data.input},
width = 0,
})
end
end
-- Receive an ItemStack of result by an ItemStack input
function technic.get_grinder_recipe(itemstack)
return technic.grinder_recipes[itemstack:get_name()]
end
-- Sorted alphebeticaly
local recipes = {
{"default:bronze_ingot", "technic:bronze_dust 1"},
{"default:coal_lump", "technic:coal_dust 2"},
{"default:cobble", "default:gravel"},
{"default:copper_ingot", "technic:copper_dust 1"},
{"default:copper_lump", "technic:copper_dust 2"},
{"default:desert_stone", "default:desert_sand"},
{"default:gold_ingot", "technic:gold_dust 1"},
{"default:gold_lump", "technic:gold_dust 2"},
{"default:gravel", "default:dirt"},
{"default:iron_lump", "technic:iron_dust 2"},
{"default:steel_ingot", "technic:iron_dust 1"},
{"default:stone", "default:sand"},
{"gloopores:alatro_lump", "technic:alatro_dust 2"},
{"gloopores:kalite_lump", "technic:kalite_dust 2"},
{"gloopores:arol_lump", "technic:arol_dust 2"},
{"gloopores:talinite_lump", "technic:talinite_dust 2"},
{"gloopores:akalin_lump", "technic:akalin_dust 2"},
{"moreores:mithril_ingot", "technic:mithril_dust 1"},
{"moreores:mithril_lump", "technic:mithril_dust 2"},
{"moreores:silver_ingot", "technic:silver_dust 1"},
{"moreores:silver_lump", "technic:silver_dust 2"},
{"moreores:tin_ingot", "technic:tin_dust 1"},
{"moreores:tin_lump", "technic:tin_dust 2"},
{"technic:chromium_ingot", "technic:chromium_dust 1"},
{"technic:chromium_lump", "technic:chromium_dust 2"},
{"technic:zinc_lump", "technic:zinc_dust 2"},
}
if minetest.get_modpath("homedecor") then
table.insert(recipes, {"home_decor:brass_ingot", "technic:brass_dust 1"})
end
for _, data in pairs(recipes) do
technic.register_grinder_recipe({input=data[1], output=data[2]})
end
local function register_dust(name, ingot)
local lname = string.lower(name)
lname = string.gsub(lname, ' ', '_')
minetest.register_craftitem("technic:"..lname.."_dust", {
description = name.." Dust",
inventory_image = "technic_"..lname.."_dust.png",
on_place_on_ground = minetest.craftitem_place_item,
})
if ingot then
minetest.register_craft({
type = "cooking",
recipe = "technic:"..lname.."_dust",
output = ingot,
})
end
end
-- Sorted alphibeticaly
register_dust("Akalin", "glooptest:akalin_ingot")
register_dust("Alatro", "glooptest:alatro_ingot")
register_dust("Arol", "glooptest:arol_ingot")
register_dust("Brass", "technic:brass_ingot")
register_dust("Bronze", "default:bronze_ingot")
register_dust("Chromium", "technic:chromium_ingot")
register_dust("Coal", nil)
register_dust("Copper", "default:copper_ingot")
register_dust("Gold", "default:gold_ingot")
register_dust("Iron", "default:steel_ingot")
register_dust("Mithril", "moreores:mithril_ingot")
register_dust("Silver", "moreores:silver_ingot")
register_dust("Stainless Steel", "technic:stainless_steel_ingot")
register_dust("Talinite", "glooptest:talinite_ingot")
register_dust("Tin", "moreores:tin_ingot")
register_dust("Zinc", "technic:zinc_ingot")

View File

@ -0,0 +1,11 @@
local path = technic.modpath.."/machines/register"
dofile(path.."/alloy_furnace.lua")
dofile(path.."/battery_box.lua")
dofile(path.."/cables.lua")
dofile(path.."/common.lua")
dofile(path.."/electric_furnace.lua")
dofile(path.."/grinder.lua")
dofile(path.."/grinder_recipes.lua")
dofile(path.."/solar_array.lua")

View File

@ -0,0 +1,69 @@
function technic.register_solar_array(data)
local tier = data.tier
local ltier = string.lower(tier)
minetest.register_node("technic:solar_array_"..ltier, {
tiles = {"technic_"..ltier.."_solar_array_top.png", "technic_"..ltier.."_solar_array_bottom.png",
"technic_"..ltier.."_solar_array_side.png", "technic_"..ltier.."_solar_array_side.png",
"technic_"..ltier.."_solar_array_side.png", "technic_"..ltier.."_solar_array_side.png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
description = tier.." Solar Array",
active = false,
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
technic = data,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local name = minetest.get_node(pos).name
local tier = minetest.registered_nodes[name].technic.tier
meta:set_int(tier.."_EU_supply", 0)
end,
})
minetest.register_abm({
nodenames = {"technic:solar_array_"..ltier},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- The action here is to make the solar array produce power
-- Power is dependent on the light level and the height above ground
-- 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 2880EU for the array.
-- 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.
-- To take care of some of it solar panels do not work outside daylight hours or if
-- built below -10m
local pos1 = {}
pos1.y = pos.y + 1
pos1.x = pos.x
pos1.z = pos.z
local light = minetest.get_node_light(pos1, nil)
local time_of_day = minetest.get_timeofday()
local meta = minetest.get_meta(pos)
light = light or 0
local data = minetest.registered_nodes[node.name].technic
-- turn on array only during day time and if sufficient light
-- 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 > 0 then
local charge_to_give = math.floor((light + pos.y) * data.power)
charge_to_give = math.max(charge_to_give, 0)
charge_to_give = math.min(charge_to_give, data.power * 50)
meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
meta:set_int(data.tier.."_EU_supply", charge_to_give)
else
meta:set_string("infotext", "Solar Array is inactive");
meta:set_int(data.tier.."_EU_supply", 0)
end
end,
})
technic.register_machine(tier, "technic:solar_array_"..ltier, technic.producer)
end

View File

@ -1,232 +1,79 @@
-- 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.
-- The top side is setup as the receiver side, the bottom as the producer side.
-- Once the receiver 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_supply_converter_top.png", "technic_supply_converter_bottom.png", "technic_supply_converter_side.png",
"technic_supply_converter_side.png", "technic_supply_converter_side.png", "technic_supply_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_node("technic:supply_converter", {
description = "Supply Converter",
tiles = {"technic_supply_converter_top.png", "technic_supply_converter_bottom.png",
"technic_supply_converter_side.png", "technic_supply_converter_side.png",
"technic_supply_converter_side.png", "technic_supply_converter_side.png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
drawtype = "nodebox",
paramtype = "light",
node_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", "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'},
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
{'technic:mv_transformer', 'technic:mv_cable0', 'technic:lv_transformer'},
{'technic:mv_cable0', 'technic:rubber', 'technic:lv_cable0'},
}
})
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 power supply tier. Determines how many are needed
local max_mv_demand = 2000 -- -""-
local max_hv_demand = 2000 -- -""-
minetest.register_abm({
nodenames = {"technic:supply_converter"},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local demand = 10000
local remain = 0.9
-- Machine information
local machine_name = "Supply Converter"
local meta = minetest.get_meta(pos)
-- 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)
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 name_up = minetest.get_node(pos_up).name
local name_down = minetest.get_node(pos_down).name
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")
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
local from = technic.get_cable_tier(name_up)
local to = technic.get_cable_tier(name_down)
-- 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 from and to then
technic.switching_station_timeout_count(pos, from)
local input = meta:get_int(from.."_EU_input")
meta:set_int(from.."_EU_demand", demand)
meta:set_int(from.."_EU_supply", 0)
meta:set_int(to.."_EU_demand", 0)
meta:set_int(to.."_EU_supply", input * remain)
meta:set_string("infotext", machine_name
.." ("..input.." "..from.." -> "
..input * remain.." "..to..")")
else
meta:set_string("infotext", machine_name.." has bad cabling")
return
end
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,
})
for tier, machines in pairs(technic.machines) do
technic.register_machine(tier, "technic:supply_converter", technic.battery)
end

View File

@ -30,323 +30,256 @@
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_craft({
output = "technic:switching_station",
recipe = {
{"default:steel_ingot", "technic:lv_transformer", "default:steel_ingot"},
{"default:copper_ingot", "technic:lv_cable0", "default:copper_ingot"},
{"default:steel_ingot", "technic:lv_cable0", "default:steel_ingot"}
}
})
minetest.register_node(
"technic:switching_station",
{description = "Switching Station",
tiles = {"technic_water_mill_top_active.png", "technic_water_mill_top_active.png", "technic_water_mill_top_active.png",
"technic_water_mill_top_active.png", "technic_water_mill_top_active.png", "technic_water_mill_top_active.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
})
minetest.register_node("technic:switching_station",{
description = "Switching Station",
tiles = {"technic_water_mill_top_active.png", "technic_water_mill_top_active.png",
"technic_water_mill_top_active.png", "technic_water_mill_top_active.png",
"technic_water_mill_top_active.png", "technic_water_mill_top_active.png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", "Switching Station")
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
function technic.switching_station_timeout_count(pos, tier)
local meta = minetest.get_meta(pos)
timeout = meta:get_int(tier.."_EU_timeout")
if timeout == 0 then
meta:set_int(tier.."_EU_input", 0)
else
meta:set_int(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
local add_new_cable_node = function(nodes, pos)
-- Ignore if the node has already been added
for i = 1, #nodes do
if pos.x == nodes[i].x and
pos.y == nodes[i].y and
pos.z == nodes[i].z then
return false
end
end
table.insert(nodes, {x=pos.x, y=pos.y, z=pos.z, visited=1})
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
local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, all_nodes, pos, machines, tier)
local meta = minetest.get_meta(pos)
local name = minetest.get_node(pos).name
if technic.is_tier_cable(name, tier) then
add_new_cable_node(all_nodes, pos)
elseif machines[name] then
--dprint(name.." is a "..machines[name])
if machines[name] == technic.producer then
add_new_cable_node(PR_nodes, pos)
elseif machines[name] == technic.receiver then
add_new_cable_node(RE_nodes, pos)
elseif machines[name] == technic.battery then
add_new_cable_node(BA_nodes, pos)
end
meta:set_int(tier.."_EU_timeout", 2) -- Touch node
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
local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, all_nodes, i, machines, tier)
local pos = all_nodes[i]
local positions = {
{x=pos.x+1, y=pos.y, z=pos.z},
{x=pos.x-1, y=pos.y, z=pos.z},
{x=pos.x, y=pos.y+1, z=pos.z},
{x=pos.x, y=pos.y-1, z=pos.z},
{x=pos.x, y=pos.y, z=pos.z+1},
{x=pos.x, y=pos.y, z=pos.z-1}}
--print("ON")
for i, cur_pos in pairs(positions) do
check_node_subp(PR_nodes, RE_nodes, BA_nodes, all_nodes, cur_pos, machines, tier)
end
end
----------------------------------------------
-- The action code for the switching station
----------------------------------------------
minetest.register_abm(
{nodenames = {"technic:switching_station"},
-----------------------------------------------
-- 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 meta = minetest.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 = {}
local tier = ""
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
-- Which kind of network are we on:
pos1 = {x=pos.x, y=pos.y-1, z=pos.z}
all_nodes[1] = pos1
local name = minetest.get_node(pos1).name
local tier = technic.get_cable_tier(name)
if tier then
local i = 1
repeat
traverse_network(PR_nodes, RE_nodes, BA_nodes, all_nodes,
i, technic.machines[tier], tier)
i = i + 1
until all_nodes[i] == nil
else
--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))
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 = tier.."_EU_demand"
local eu_input_str = tier.."_EU_input"
local eu_supply_str = tier.."_EU_supply"
-- 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.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 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.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 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.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 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.get_meta(pos1)
BA_eu_demand = BA_eu_demand + meta1:get_int(eu_demand_str)
end
--dprint("Total BA demand:"..BA_eu_demand)
-- 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. Supply: "..PR_eu_supply
.." Demand: "..RE_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.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.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
return
end
-- 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
-- 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.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.get_meta(pos1)
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
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 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
-- If the PR+BA supply is not enough for the RE demand: Power only the batteries
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.get_meta(pos1)
local eu_demand = meta1:get_int(eu_demand_str)
meta1:set_int(eu_input_str, math.floor(eu_demand * charge_factor))
end
for n, pos1 in pairs(RE_nodes) do
meta1 = minetest.get_meta(pos1)
meta1:set_int(eu_input_str, 0)
end
end,
})
for tier, machines in pairs(technic.machines) do
-- SPECIAL will not be traversed
technic.register_machine(tier, "technic:switching_station", "SPECIAL")
end

48
technic/register.lua Normal file
View File

@ -0,0 +1,48 @@
-- This file includes the functions and data structures for registering machines and tools for LV, MV, HV types.
-- We use the technic namespace for these functions and data to avoid eventual conflict.
technic.receiver = "RE"
technic.producer = "PR"
technic.battery = "BA"
technic.machines = {}
technic.power_tools = {}
function technic.register_tier(tier, description)
technic.machines[tier] = {}
technic.cables[tier] = {}
end
function technic.register_machine(tier, nodename, machine_type)
if not technic.machines[tier] then
return
end
technic.machines[tier][nodename] = machine_type
end
function technic.register_power_tool(craftitem, max_charge)
technic.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, item_load, max_load)
local temp = 65536 - math.floor(item_load / max_load * 65535)
item_stack.wear = tostring(temp)
return item_stack
end

View File

@ -1,63 +0,0 @@
-- This file includes the functions and data structures for registering machines and tools for LV, MV, HV types.
-- We use the technic namespace for these functions and data to avoid eventual conflict.
-- register power tools here
technic.power_tools = {}
technic.register_power_tool = function(craftitem,max_charge)
technic.power_tools[craftitem] = max_charge
end
-- register LV machines here
technic.LV_machines = {}
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
-- 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
-- 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
-- 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

@ -1,123 +0,0 @@
-- Code of rubber tree by PilzAdam
minetest.register_node("technic:rubber_sapling", {
description = "Rubber Tree Sapling",
drawtype = "plantlike",
tiles = {"technic_rubber_sapling.png"},
inventory_image = "technic_rubber_sapling.png",
wield_image = "technic_rubber_sapling.png",
paramtype = "light",
walkable = false,
groups = {dig_immediate=3,flammable=2},
sounds = default.node_sound_defaults(),
})
minetest.register_node("technic:rubber_tree_full", {
description = "Rubber Tree",
tiles = {"default_tree_top.png", "default_tree_top.png", "technic_rubber_tree_full.png"},
groups = {tree=1,snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2},
drop = "default:tree",
sounds = default.node_sound_wood_defaults(),
on_dig = function(pos, node, digger)
minetest.node_dig(pos, node, digger)
minetest.env:remove_node(pos)
end,
after_destruct = function(pos, oldnode)
oldnode.name = "technic:rubber_tree_empty"
minetest.env:set_node(pos, oldnode)
end
})
minetest.register_node("technic:rubber_tree_empty", {
tiles = {"default_tree_top.png", "default_tree_top.png", "technic_rubber_tree_empty.png"},
groups = {tree=1,snappy=1,choppy=2,oddly_breakable_by_hand=1,flammable=2, not_in_creative_inventory=1},
drop = "default:tree",
sounds = default.node_sound_wood_defaults(),
})
minetest.register_abm({
nodenames = {"technic:rubber_tree_empty"},
interval = 60,
chance = 15,
action = function(pos, node)
node.name = "technic:rubber_tree_full"
minetest.env:set_node(pos, node)
end
})
minetest.register_node("technic:rubber_leaves", {
drawtype = "allfaces_optional",
visual_scale = 1.3,
tiles = {"technic_rubber_leaves.png"},
paramtype = "light",
groups = {snappy=3, leafdecay=3, flammable=2, not_in_creative_inventory=1},
drop = {
max_items = 1,
items = {
{
items = {'technic:rubber_sapling'},
rarity = 20,
},
}
},
sounds = default.node_sound_leaves_defaults(),
})
minetest.register_abm({
nodenames = {"technic:rubber_sapling"},
interval = 60,
chance = 20,
action = function(pos, node)
rubber_tree={
axiom="FFFFA",
rules_a="[&FFBFA]////[&BFFFA]////[&FBFFA]",
rules_b="[&FFA]////[&FFA]////[&FFA]",
trunk="technic:rubber_tree_full",
leaves="technic:rubber_leaves",
angle=35,
iterations=3,
random_level=1,
thin_trunks=false;
fruit_tree=false,
fruit=""
}
minetest.env:spawn_tree(pos,rubber_tree)
end
})
if technic.config:getBool("enable_rubber_tree_generation") then
minetest.register_on_generated(function(minp, maxp, blockseed)
if math.random(1, 100) > 5 then
return
end
local rubber_tree={
axiom="FFFFA",
rules_a="[&FFBFA]////[&BFFFA]////[&FBFFA]",
rules_b="[&FFA]////[&FFA]////[&FFA]",
trunk="technic:rubber_tree_full",
leaves="technic:rubber_leaves",
angle=35,
iterations=3,
random_level=1,
thin_trunks=false;
fruit_tree=false,
fruit=""
}
local tmp = {x=(maxp.x-minp.x)/2+minp.x, y=(maxp.y-minp.y)/2+minp.y, z=(maxp.z-minp.z)/2+minp.z}
local pos = minetest.env:find_node_near(tmp, maxp.x-minp.x, {"default:dirt_with_grass"})
if pos ~= nil then
minetest.env:spawn_tree({x=pos.x, y=pos.y+1, z=pos.z}, rubber_tree)
end
end)
end
-- ========= FUEL =========
minetest.register_craft({
type = "fuel",
recipe = "technic:rubber_sapling",
burntime = 10
})

View File

Before

Width:  |  Height:  |  Size: 777 B

After

Width:  |  Height:  |  Size: 777 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 738 B

View File

Before

Width:  |  Height:  |  Size: 508 B

After

Width:  |  Height:  |  Size: 508 B

View File

Before

Width:  |  Height:  |  Size: 543 B

After

Width:  |  Height:  |  Size: 543 B

View File

Before

Width:  |  Height:  |  Size: 313 B

After

Width:  |  Height:  |  Size: 313 B

View File

Before

Width:  |  Height:  |  Size: 397 B

After

Width:  |  Height:  |  Size: 397 B

View File

Before

Width:  |  Height:  |  Size: 738 B

After

Width:  |  Height:  |  Size: 738 B

View File

Before

Width:  |  Height:  |  Size: 594 B

After

Width:  |  Height:  |  Size: 594 B

Some files were not shown because too many files have changed in this diff Show More