mirror of
https://github.com/minetest-mods/technic.git
synced 2025-07-01 15:50:39 +02:00
Move files to subfolders
This commit is contained in:
85
technic/machines/alloy_furnaces_commons.lua
Normal file
85
technic/machines/alloy_furnaces_commons.lua
Normal file
@ -0,0 +1,85 @@
|
||||
-- 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)
|
||||
|
55
technic/machines/grinder_gloopores.lua
Normal file
55
technic/machines/grinder_gloopores.lua
Normal file
@ -0,0 +1,55 @@
|
||||
technic.register_grinder_recipe("gloopores:alatro_lump","technic:alatro_dust 2")
|
||||
technic.register_grinder_recipe("gloopores:kalite_lump","technic:kalite_dust 2")
|
||||
technic.register_grinder_recipe("gloopores:arol_lump","technic:arol_dust 2")
|
||||
technic.register_grinder_recipe("gloopores:talinite_lump","technic:talinite_dust 2")
|
||||
technic.register_grinder_recipe("gloopores: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 = "gloopores:alatro_ingot",
|
||||
recipe = "technic:alatro_dust",
|
||||
})
|
||||
|
||||
minetest.register_craftitem("technicplus:arol_dust", {
|
||||
description = "Arol Dust",
|
||||
inventory_image = "technic_arol_dust.png",
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
output = "gloopores: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 = "gloopores: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 = "gloopores: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)
|
||||
})
|
231
technic/machines/hv/battery_box.lua
Normal file
231
technic/machines/hv/battery_box.lua
Normal file
@ -0,0 +1,231 @@
|
||||
-- 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;]"..
|
||||
"image[4,1;1,1;technic_battery_reload.png]"..
|
||||
"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;]"
|
||||
|
||||
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 can this node charge
|
||||
meta:set_int("HV_EU_supply", 0) -- How much can this node discharge
|
||||
meta:set_int("HV_EU_input", 0) -- How much power is this machine getting.
|
||||
meta:set_float("internal_EU_charge", 0)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("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
|
||||
|
||||
local power_tools = technic.HV_power_tools
|
||||
|
||||
local charge_HV_tools = function(meta, charge)
|
||||
--charge registered power tools
|
||||
local inv = meta:get_inventory()
|
||||
if inv:is_empty("src")==false then
|
||||
local srcstack = inv:get_stack("src", 1)
|
||||
local src_item=srcstack:to_table()
|
||||
local src_meta=get_item_meta(src_item["metadata"])
|
||||
|
||||
local toolname = src_item["name"]
|
||||
if power_tools[toolname] ~= nil then
|
||||
-- Set meta data for the tool if it didn't do it itself :-(
|
||||
src_meta=get_item_meta(src_item["metadata"])
|
||||
if src_meta==nil then
|
||||
src_meta={}
|
||||
src_meta["technic_hv_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
else
|
||||
if src_meta["technic_hv_power_tool"]==nil then
|
||||
src_meta["technic_hv_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
end
|
||||
end
|
||||
-- Do the charging
|
||||
local item_max_charge = power_tools[toolname]
|
||||
local load = src_meta["charge"]
|
||||
local load_step = 1000 -- how much to charge per tick
|
||||
if load<item_max_charge and charge>0 then
|
||||
if charge-load_step<0 then load_step=charge end
|
||||
if load+load_step>item_max_charge then load_step=item_max_charge-load end
|
||||
load=load+load_step
|
||||
charge=charge-load_step
|
||||
technic.set_RE_wear(src_item,load,item_max_charge)
|
||||
src_meta["charge"] = load
|
||||
src_item["metadata"] = set_item_meta(src_meta)
|
||||
inv:set_stack("src", 1, src_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
return charge -- return the remaining charge in the battery
|
||||
end
|
||||
|
||||
local discharge_HV_tools = function(meta, charge, max_charge)
|
||||
-- discharging registered power tools
|
||||
local inv = meta:get_inventory()
|
||||
if inv:is_empty("dst") == false then
|
||||
srcstack = inv:get_stack("dst", 1)
|
||||
src_item=srcstack:to_table()
|
||||
local src_meta=get_item_meta(src_item["metadata"])
|
||||
local toolname = src_item["name"]
|
||||
if power_tools[toolname] ~= nil then
|
||||
-- Set meta data for the tool if it didn't do it itself :-(
|
||||
src_meta=get_item_meta(src_item["metadata"])
|
||||
if src_meta==nil then
|
||||
src_meta={}
|
||||
src_meta["technic_hv_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
else
|
||||
if src_meta["technic_hv_power_tool"]==nil then
|
||||
src_meta["technic_hv_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
end
|
||||
end
|
||||
-- Do the discharging
|
||||
local item_max_charge = power_tools[toolname]
|
||||
local load = src_meta["charge"]
|
||||
local load_step = 4000 -- how much to discharge per tick
|
||||
if load>0 and charge<max_charge then
|
||||
if charge+load_step>max_charge then load_step=max_charge-charge end
|
||||
if load-load_step<0 then load_step=load end
|
||||
load=load-load_step
|
||||
charge=charge+load_step
|
||||
technic.set_RE_wear(src_item,load,item_max_charge)
|
||||
src_meta["charge"]=load
|
||||
src_item["metadata"]=set_item_meta(src_meta)
|
||||
inv:set_stack("dst", 1, src_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
return charge -- return the remaining charge in the battery
|
||||
end
|
||||
|
||||
minetest.register_abm(
|
||||
{nodenames = {"technic:hv_battery_box","technic:hv_battery_box1","technic:hv_battery_box2","technic:hv_battery_box3","technic:hv_battery_box4",
|
||||
"technic:hv_battery_box5","technic:hv_battery_box6","technic:hv_battery_box7","technic:hv_battery_box8"
|
||||
},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local max_charge = 1500000 -- Set maximum charge for the device here
|
||||
local max_charge_rate = 3000 -- Set maximum rate of charging
|
||||
local max_discharge_rate = 5000 -- Set maximum rate of discharging (16000)
|
||||
local eu_input = meta:get_int("HV_EU_input")
|
||||
local current_charge = meta:get_int("internal_EU_charge") -- Battery charge right now
|
||||
|
||||
-- Power off automatically if no longer connected to a switching station
|
||||
technic.switching_station_timeout_count(pos, "HV")
|
||||
|
||||
-- Charge/discharge the battery with the input EUs
|
||||
if eu_input >=0 then
|
||||
current_charge = math.min(current_charge+eu_input, max_charge)
|
||||
else
|
||||
current_charge = math.max(current_charge+eu_input, 0)
|
||||
end
|
||||
|
||||
-- Charging/discharging tools here
|
||||
current_charge = charge_HV_tools(meta, current_charge)
|
||||
current_charge = discharge_HV_tools(meta, current_charge, max_charge)
|
||||
|
||||
-- Set a demand (we allow batteries to charge on less than the demand though)
|
||||
meta:set_int("HV_EU_demand", math.min(max_charge_rate, max_charge-current_charge))
|
||||
|
||||
-- Set how much we can supply
|
||||
meta:set_int("HV_EU_supply", math.min(max_discharge_rate, current_charge))
|
||||
|
||||
meta:set_int("internal_EU_charge", current_charge)
|
||||
--dprint("BA: input:"..eu_input.." supply="..meta:get_int("HV_EU_supply").." demand="..meta:get_int("HV_EU_demand").." current:"..current_charge)
|
||||
|
||||
-- Select node textures
|
||||
local i=math.ceil((current_charge/max_charge)*8)
|
||||
if i > 8 then i = 8 end
|
||||
local j = meta:get_float("last_side_shown")
|
||||
if i~=j then
|
||||
if i>0 then hacky_swap_node(pos,"technic:hv_battery_box"..i)
|
||||
elseif i==0 then hacky_swap_node(pos,"technic:hv_battery_box") end
|
||||
meta:set_float("last_side_shown",i)
|
||||
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", "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
|
||||
|
225
technic/machines/hv/forcefield.lua
Normal file
225
technic/machines/hv/forcefield.lua
Normal file
@ -0,0 +1,225 @@
|
||||
-- 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 -- default 10
|
||||
local forcefield_update_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 add_forcefield(pos, range)
|
||||
for x=-range,range do
|
||||
for y=-range,range do
|
||||
for z=-range,range do
|
||||
if ((x*x+y*y+z*z) <= (range * range + range)) then
|
||||
if ((range-1) * (range-1) + (range-1) <= x*x+y*y+z*z) then
|
||||
local np={x=pos.x+x,y=pos.y+y,z=pos.z+z}
|
||||
local n = minetest.env:get_node(np).name
|
||||
if (n == "air") then
|
||||
minetest.env:add_node(np, {name = "technic:forcefield"})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
local function remove_forcefield(p, range)
|
||||
for x=-range,range do
|
||||
for y=-range,range do
|
||||
for z=-range,range do
|
||||
if ((x*x+y*y+z*z) <= (range * range + range)) then
|
||||
if ((range-1) * (range-1) + (range-1) <= x*x+y*y+z*z) then
|
||||
local np={x=p.x+x,y=p.y+y,z=p.z+z}
|
||||
local n = minetest.env:get_node(np).name
|
||||
if (n == "technic:forcefield") then
|
||||
minetest.env:remove_node(np)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local get_forcefield_formspec = function(range)
|
||||
-- return "invsize[8,9;]".. (if upgrades added later - colors for instance)
|
||||
return "invsize[3,4;]"..
|
||||
"label[0,0;Forcefield emitter]"..
|
||||
"label[1,1;Range]"..
|
||||
"label[1,2;"..range.."]"..
|
||||
"button[0,2;1,1;subtract;-]"..
|
||||
"button[2,2;1,1;add;+]"..
|
||||
"button[0,3;3,1;toggle;Enable/Disable]" -- ..
|
||||
-- "list[current_player;main;0,5;8,4;]"
|
||||
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
|
||||
remove_forcefield(pos, meta:get_int("range"))
|
||||
meta:set_int("range", range)
|
||||
meta:set_string("formspec", get_forcefield_formspec(range))
|
||||
end
|
||||
end
|
||||
|
||||
local forcefield_check = function(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
|
||||
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 eu_input == 0 then
|
||||
meta:set_string("infotext", "Forcefield Generator Unpowered")
|
||||
meta:set_int("HV_EU_demand", 100)
|
||||
meta:set_int("enabled", 0)
|
||||
if node.name == "technic:forcefield_emitter_on" then
|
||||
remove_forcefield(pos, meta:get_int("range"))
|
||||
hacky_swap_node(pos, "technic:forcefield_emitter_off")
|
||||
end
|
||||
elseif eu_input == power_requirement then
|
||||
if meta:get_int("enabled") == 1 then
|
||||
if node.name == "technic:forcefield_emitter_off" then
|
||||
hacky_swap_node(pos, "technic:forcefield_emitter_on")
|
||||
meta:set_string("infotext", "Forcefield Generator Active")
|
||||
add_forcefield(pos, meta:get_int("range"))
|
||||
else
|
||||
-- Range updated. Move the forcefield.
|
||||
add_forcefield(pos, meta:get_int("range"))
|
||||
end
|
||||
else
|
||||
if node.name == "technic:forcefield_emitter_on" then
|
||||
remove_forcefield(pos, meta:get_int("range"))
|
||||
hacky_swap_node(pos, "technic:forcefield_emitter_off")
|
||||
meta:set_int("HV_EU_demand", 100)
|
||||
meta:set_string("infotext", "Forcefield Generator Idle")
|
||||
end
|
||||
end
|
||||
else
|
||||
meta:set_int("HV_EU_demand", power_requirement)
|
||||
end
|
||||
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_check,
|
||||
on_receive_fields = forcefield_receive_fields,
|
||||
on_construct = function(pos)
|
||||
minetest.env:get_node_timer(pos):start(forcefield_update_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_check,
|
||||
on_receive_fields = forcefield_receive_fields,
|
||||
on_construct = function(pos)
|
||||
minetest.env:get_node_timer(pos):start(forcefield_update_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)
|
||||
remove_forcefield(pos, minetest.env:get_meta(pos):get_int("range"))
|
||||
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")
|
8
technic/machines/hv/init.lua
Normal file
8
technic/machines/hv/init.lua
Normal file
@ -0,0 +1,8 @@
|
||||
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")
|
||||
|
239
technic/machines/hv/nuclear_reactor.lua
Normal file
239
technic/machines/hv/nuclear_reactor.lua
Normal file
@ -0,0 +1,239 @@
|
||||
-- The enriched uranium rod driven EU generator.
|
||||
-- A very large and advanced machine providing vast amounts of power.
|
||||
-- Very efficient but also expensive to run as it needs uranium. (10000EU 86400 ticks (24h))
|
||||
-- Provides HV EUs that can be down converted as needed.
|
||||
--
|
||||
-- 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 = 1 -- [minutes]. How many minutes does the power plant burn per serving?
|
||||
local power_supply = 10000 -- [HV] EUs
|
||||
local fuel_type = "technic:enriched_uranium" -- This reactor burns this stuff
|
||||
|
||||
-- FIXME: recipe must make more sense like a rod recepticle, steam chamber, HV generator?
|
||||
minetest.register_craft({
|
||||
output = 'technic:hv_nuclear_reactor_core',
|
||||
recipe = {
|
||||
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot'},
|
||||
{'technic:stainless_steel_ingot', '', 'technic:stainless_steel_ingot'},
|
||||
{'technic:stainless_steel_ingot', 'technic:hv_cable', 'technic:stainless_steel_ingot'},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craftitem("technic:hv_nuclear_reactor_core", {
|
||||
description = "Uranium Rod Driven HV Reactor",
|
||||
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;]"
|
||||
|
||||
-- "Boxy sphere"
|
||||
local nodebox = {{ -0.353, -0.353, -0.353, 0.353, 0.353, 0.353 }, -- Box
|
||||
{ -0.495, -0.064, -0.064, 0.495, 0.064, 0.064 }, -- Circle +-x
|
||||
{ -0.483, -0.128, -0.128, 0.483, 0.128, 0.128 },
|
||||
{ -0.462, -0.191, -0.191, 0.462, 0.191, 0.191 },
|
||||
{ -0.433, -0.249, -0.249, 0.433, 0.249, 0.249 },
|
||||
{ -0.397, -0.303, -0.303, 0.397, 0.303, 0.303 },
|
||||
{ -0.305, -0.396, -0.305, 0.305, 0.396, 0.305 }, -- Circle +-y
|
||||
{ -0.250, -0.432, -0.250, 0.250, 0.432, 0.250 },
|
||||
{ -0.191, -0.461, -0.191, 0.191, 0.461, 0.191 },
|
||||
{ -0.130, -0.482, -0.130, 0.130, 0.482, 0.130 },
|
||||
{ -0.066, -0.495, -0.066, 0.066, 0.495, 0.066 },
|
||||
{ -0.064, -0.064, -0.495, 0.064, 0.064, 0.495 }, -- Circle +-z
|
||||
{ -0.128, -0.128, -0.483, 0.128, 0.128, 0.483 },
|
||||
{ -0.191, -0.191, -0.462, 0.191, 0.191, 0.462 },
|
||||
{ -0.249, -0.249, -0.433, 0.249, 0.249, 0.433 },
|
||||
{ -0.303, -0.303, -0.397, 0.303, 0.303, 0.397 },
|
||||
}
|
||||
|
||||
minetest.register_node(
|
||||
"technic:hv_nuclear_reactor_core",
|
||||
{
|
||||
description = "Nuclear Reactor",
|
||||
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
|
||||
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
|
||||
-- paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drawtype="nodebox",
|
||||
paramtype = "light",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox
|
||||
},
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env: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
|
||||
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 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:hv_nuclear_reactor_core_active",
|
||||
{
|
||||
description = "Coal Driven Generator",
|
||||
tiles = {"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png",
|
||||
"technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png", "technic_hv_nuclear_reactor_core.png"},
|
||||
-- paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,not_in_creative_inventory=1},
|
||||
legacy_facedir_simple = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
drop="technic:generator",
|
||||
drawtype="nodebox",
|
||||
light_source = 15,
|
||||
paramtype = "light",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = nodebox
|
||||
},
|
||||
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,
|
||||
})
|
||||
|
||||
local check_reactor_structure = function(pos)
|
||||
-- The reactor consists of an 11x11x11 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
|
||||
-- The man-hole and the HV cable is only in the middle.
|
||||
local water_nodes = minetest.find_nodes_in_area({x=pos.x-1, y=pos.y-1, z=pos.z-1},
|
||||
{x=pos.x+1, y=pos.y+1, z=pos.z+1}, "default:water_source")
|
||||
--print("Water ( 25):"..#water_nodes)
|
||||
if #water_nodes ~= 25 then
|
||||
--print("Water supply defect")
|
||||
return 0
|
||||
end
|
||||
local inner_shield_nodes = minetest.find_nodes_in_area({x=pos.x-2, y=pos.y-2, z=pos.z-2},
|
||||
{x=pos.x+2, y=pos.y+2, z=pos.z+2}, "technic:concrete")
|
||||
|
||||
--print("Concrete 1 ( 96):"..#inner_shield_nodes)
|
||||
if #inner_shield_nodes ~= 96 then
|
||||
--print("Inner shield defect")
|
||||
return 0
|
||||
end
|
||||
local steel_shield_nodes = minetest.find_nodes_in_area({x=pos.x-3, y=pos.y-3, z=pos.z-3},
|
||||
{x=pos.x+3, y=pos.y+3, z=pos.z+3}, "default:steelblock")
|
||||
|
||||
--print("Steel ( 216):"..#steel_shield_nodes)
|
||||
if #steel_shield_nodes ~= 216 then
|
||||
--print("Steel shield defect")
|
||||
return 0
|
||||
end
|
||||
local outer_shield_nodes = minetest.find_nodes_in_area({x=pos.x-5, y=pos.y-5, z=pos.z-5},
|
||||
{x=pos.x+5, y=pos.y+5, z=pos.z+5}, "technic:concrete")
|
||||
--print("Concrete 2 (1080):"..#outer_shield_nodes)
|
||||
if #outer_shield_nodes ~= (984+#inner_shield_nodes) then
|
||||
--print("Outer shield defect")
|
||||
return 0
|
||||
end
|
||||
return 1
|
||||
end
|
||||
|
||||
local explode_reactor = function(pos)
|
||||
print("BOOM A reactor exploded!")
|
||||
end
|
||||
|
||||
minetest.register_abm(
|
||||
{
|
||||
nodenames = {"technic:hv_nuclear_reactor_core","technic:hv_nuclear_reactor_core_active"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local burn_time= meta:get_int("burn_time")
|
||||
|
||||
-- If more to burn and the energy produced was used: produce some more
|
||||
if burn_time>0 then
|
||||
if meta:get_int("HV_EU_supply") == 0 then
|
||||
-- We did not use the power
|
||||
meta:set_int("HV_EU_supply", power_sypply)
|
||||
else
|
||||
burn_time = burn_time - 1
|
||||
meta:set_int("burn_time",burn_time)
|
||||
meta:set_string("infotext", "Nuclear Reactor Core ("..math.floor(burn_time/(burn_ticks*60)*100).."%)")
|
||||
end
|
||||
end
|
||||
|
||||
-- Burn another piece of coal
|
||||
if burn_time==0 then
|
||||
local inv = meta:get_inventory()
|
||||
local correct_fuel_count = 0
|
||||
if inv:is_empty("src") == false then
|
||||
local srclist= inv:get_list("src")
|
||||
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
|
||||
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 check_reactor_structure(pos) == 1 then
|
||||
burn_time=burn_ticks*60
|
||||
meta:set_int("burn_time",burn_time)
|
||||
hacky_swap_node (pos,"technic:hv_nuclear_reactor_core_active")
|
||||
meta:set_int("HV_EU_supply", power_supply)
|
||||
for idx, srcstack in pairs(srclist) do
|
||||
srcstack:take_item()
|
||||
inv:set_stack("src", idx, srcstack)
|
||||
end
|
||||
else
|
||||
-- BOOM!!! (the reactor was compromised and it should explode after some time) TNT mod inspired??
|
||||
explode_reactor(pos)
|
||||
end
|
||||
else
|
||||
meta:set_int("HV_EU_supply", 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Nothing left to burn
|
||||
if burn_time==0 then
|
||||
meta:set_string("infotext", "Nuclear Reactor Core (idle)")
|
||||
hacky_swap_node (pos,"technic:hv_nuclear_reactor_core")
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
technic.register_HV_machine ("technic:hv_nuclear_reactor_core","PR")
|
||||
technic.register_HV_machine ("technic:hv_nuclear_reactor_core_active","PR")
|
78
technic/machines/hv/solar_array.lua
Normal file
78
technic/machines/hv/solar_array.lua
Normal file
@ -0,0 +1,78 @@
|
||||
-- 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>160 then charge_to_give=160 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")
|
||||
|
398
technic/machines/hv/wires.lua
Normal file
398
technic/machines/hv/wires.lua
Normal file
@ -0,0 +1,398 @@
|
||||
--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 = "Gigh 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
|
||||
|
10
technic/machines/init.lua
Normal file
10
technic/machines/init.lua
Normal file
@ -0,0 +1,10 @@
|
||||
local path = technic.modpath.."/machines"
|
||||
|
||||
dofile(path.."/switching_station.lua")
|
||||
dofile(path.."/supply_converter.lua")
|
||||
dofile(path.."/alloy_furnaces_commons.lua")
|
||||
dofile(path.."/lv/init.lua")
|
||||
dofile(path.."/mv/init.lua")
|
||||
dofile(path.."/hv/init.lua")
|
||||
dofile(path.."/other/init.lua")
|
||||
|
367
technic/machines/lv/alloy_furnace.lua
Normal file
367
technic/machines/lv/alloy_furnace.lua
Normal file
@ -0,0 +1,367 @@
|
||||
-- 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,
|
||||
})
|
||||
|
269
technic/machines/lv/battery_box.lua
Normal file
269
technic/machines/lv/battery_box.lua
Normal file
@ -0,0 +1,269 @@
|
||||
-- LV Battery box and some other nodes...
|
||||
technic.register_LV_power_tool("technic:battery",10000)
|
||||
technic.register_MV_power_tool("technic:red_energy_crystal",100000)
|
||||
technic.register_HV_power_tool("technic:green_energy_crystal",250000)
|
||||
technic.register_HV_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;]"..
|
||||
"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;]"
|
||||
|
||||
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
|
||||
|
||||
local power_tools = technic.LV_power_tools
|
||||
|
||||
local charge_LV_tools = function(meta, charge)
|
||||
--charge registered power tools
|
||||
local inv = meta:get_inventory()
|
||||
if inv:is_empty("src")==false then
|
||||
local srcstack = inv:get_stack("src", 1)
|
||||
local src_item=srcstack:to_table()
|
||||
local src_meta=get_item_meta(src_item["metadata"])
|
||||
|
||||
local toolname = src_item["name"]
|
||||
if power_tools[toolname] ~= nil then
|
||||
-- Set meta data for the tool if it didn't do it itself :-(
|
||||
src_meta=get_item_meta(src_item["metadata"])
|
||||
if src_meta==nil then
|
||||
src_meta={}
|
||||
src_meta["technic_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
else
|
||||
if src_meta["technic_power_tool"]==nil then
|
||||
src_meta["technic_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
end
|
||||
end
|
||||
-- Do the charging
|
||||
local item_max_charge = power_tools[toolname]
|
||||
local load = src_meta["charge"]
|
||||
local load_step = 1000 -- how much to charge per tick
|
||||
if load<item_max_charge and charge>0 then
|
||||
if charge-load_step<0 then load_step=charge end
|
||||
if load+load_step>item_max_charge then load_step=item_max_charge-load end
|
||||
load=load+load_step
|
||||
charge=charge-load_step
|
||||
technic.set_RE_wear(src_item,load,item_max_charge)
|
||||
src_meta["charge"] = load
|
||||
src_item["metadata"] = set_item_meta(src_meta)
|
||||
inv:set_stack("src", 1, src_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
return charge -- return the remaining charge in the battery
|
||||
end
|
||||
|
||||
local discharge_LV_tools = function(meta, charge, max_charge)
|
||||
-- discharging registered power tools
|
||||
local inv = meta:get_inventory()
|
||||
if inv:is_empty("dst") == false then
|
||||
srcstack = inv:get_stack("dst", 1)
|
||||
src_item=srcstack:to_table()
|
||||
local src_meta=get_item_meta(src_item["metadata"])
|
||||
local toolname = src_item["name"]
|
||||
if power_tools[toolname] ~= nil then
|
||||
-- Set meta data for the tool if it didn't do it itself :-(
|
||||
src_meta=get_item_meta(src_item["metadata"])
|
||||
if src_meta==nil then
|
||||
src_meta={}
|
||||
src_meta["technic_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
else
|
||||
if src_meta["technic_power_tool"]==nil then
|
||||
src_meta["technic_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
end
|
||||
end
|
||||
-- Do the discharging
|
||||
local item_max_charge = power_tools[toolname]
|
||||
local load = src_meta["charge"]
|
||||
local load_step = 4000 -- how much to discharge per tick
|
||||
if load>0 and charge<max_charge then
|
||||
if charge+load_step>max_charge then load_step=max_charge-charge end
|
||||
if load-load_step<0 then load_step=load end
|
||||
load=load-load_step
|
||||
charge=charge+load_step
|
||||
technic.set_RE_wear(src_item,load,item_max_charge)
|
||||
src_meta["charge"]=load
|
||||
src_item["metadata"]=set_item_meta(src_meta)
|
||||
inv:set_stack("dst", 1, src_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
return charge -- return the remaining charge in the battery
|
||||
end
|
||||
|
||||
minetest.register_abm(
|
||||
{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_LV_tools(meta, current_charge)
|
||||
current_charge = discharge_LV_tools(meta, current_charge, max_charge)
|
||||
|
||||
-- Set a demand (we allow batteries to charge on less than the demand though)
|
||||
meta:set_int("LV_EU_demand", math.min(max_charge_rate, max_charge-current_charge))
|
||||
--print("BA:"..max_charge_rate.."|"..max_charge-current_charge.."|"..math.min(max_charge_rate, max_charge-current_charge))
|
||||
|
||||
-- Set how much we can supply
|
||||
meta:set_int("LV_EU_supply", math.min(max_discharge_rate, current_charge))
|
||||
|
||||
meta:set_int("internal_EU_charge", current_charge)
|
||||
--dprint("BA: input:"..eu_input.." supply="..meta:get_int("LV_EU_supply").." demand="..meta:get_int("LV_EU_demand").." current:"..current_charge)
|
||||
|
||||
-- Select node textures
|
||||
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
|
||||
|
293
technic/machines/lv/cnc.lua
Normal file
293
technic/machines/lv/cnc.lua
Normal file
@ -0,0 +1,293 @@
|
||||
-- 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'},
|
||||
},
|
||||
})
|
||||
|
372
technic/machines/lv/cnc_api.lua
Normal file
372
technic/machines/lv/cnc_api.lua
Normal file
@ -0,0 +1,372 @@
|
||||
-- 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
|
70
technic/machines/lv/cnc_nodes.lua
Normal file
70
technic/machines/lv/cnc_nodes.lua
Normal file
@ -0,0 +1,70 @@
|
||||
-- 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")
|
160
technic/machines/lv/electric_furnace.lua
Normal file
160
technic/machines/lv/electric_furnace.lua
Normal file
@ -0,0 +1,160 @@
|
||||
-- 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")
|
||||
|
220
technic/machines/lv/extractor.lua
Normal file
220
technic/machines/lv/extractor.lua
Normal file
@ -0,0 +1,220 @@
|
||||
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")
|
||||
|
150
technic/machines/lv/generator.lua
Normal file
150
technic/machines/lv/generator.lua
Normal file
@ -0,0 +1,150 @@
|
||||
-- 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")
|
156
technic/machines/lv/geothermal.lua
Normal file
156
technic/machines/lv/geothermal.lua
Normal file
@ -0,0 +1,156 @@
|
||||
-- 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")
|
352
technic/machines/lv/grinder.lua
Normal file
352
technic/machines/lv/grinder.lua
Normal file
@ -0,0 +1,352 @@
|
||||
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")
|
||||
|
19
technic/machines/lv/init.lua
Normal file
19
technic/machines/lv/init.lua
Normal file
@ -0,0 +1,19 @@
|
||||
local path = technic.modpath.."/machines/lv"
|
||||
|
||||
dofile(path.."/wires.lua")
|
||||
dofile(path.."/battery_box.lua")
|
||||
dofile(path.."/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")
|
||||
dofile(path.."/cnc_api.lua")
|
||||
dofile(path.."/cnc_nodes.lua")
|
||||
dofile(path.."/extractor.lua")
|
||||
|
156
technic/machines/lv/music_player.lua
Normal file
156
technic/machines/lv/music_player.lua
Normal file
@ -0,0 +1,156 @@
|
||||
-- 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")
|
78
technic/machines/lv/solar_array.lua
Normal file
78
technic/machines/lv/solar_array.lua
Normal file
@ -0,0 +1,78 @@
|
||||
-- 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")
|
||||
|
78
technic/machines/lv/solar_panel.lua
Normal file
78
technic/machines/lv/solar_panel.lua
Normal file
@ -0,0 +1,78 @@
|
||||
-- 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")
|
||||
|
122
technic/machines/lv/tool_workshop.lua
Normal file
122
technic/machines/lv/tool_workshop.lua
Normal file
@ -0,0 +1,122 @@
|
||||
-- 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")
|
||||
|
122
technic/machines/lv/water_mill.lua
Normal file
122
technic/machines/lv/water_mill.lua
Normal file
@ -0,0 +1,122 @@
|
||||
-- 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")
|
401
technic/machines/lv/wires.lua
Normal file
401
technic/machines/lv/wires.lua
Normal file
@ -0,0 +1,401 @@
|
||||
--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
|
||||
|
459
technic/machines/mv/alloy_furnace.lua
Normal file
459
technic/machines/mv/alloy_furnace.lua
Normal file
@ -0,0 +1,459 @@
|
||||
-- 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,
|
||||
},
|
||||
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,
|
||||
},
|
||||
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 and no tube is connected
|
||||
-- or if we have nothing to send with a tube connected.
|
||||
if (not output_tube_connected and inv:is_empty("src"))
|
||||
or ( output_tube_connected and inv:is_empty("dst")) then
|
||||
next_state = 1
|
||||
end
|
||||
----------------------
|
||||
local empty = 1
|
||||
local recipe = nil
|
||||
local result = nil
|
||||
|
||||
-- Get what to cook if anything
|
||||
local srcstack = inv:get_stack("src", 1)
|
||||
local src2stack = inv:get_stack("src", 2)
|
||||
local src_item1 = nil
|
||||
local src_item2 = nil
|
||||
if srcstack and src2stack then
|
||||
src_item1 = srcstack:to_table()
|
||||
src_item2 = src2stack:to_table()
|
||||
empty = 0
|
||||
end
|
||||
|
||||
if src_item1 and src_item2 then
|
||||
recipe = technic.get_alloy_recipe(src_item1,src_item2)
|
||||
end
|
||||
if recipe then
|
||||
result = { name=recipe.dst_name, count=recipe.dst_count}
|
||||
end
|
||||
|
||||
if state == 1 then
|
||||
hacky_swap_node(pos, machine_node)
|
||||
meta:set_string("infotext", machine_name.." Idle")
|
||||
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("src") then
|
||||
if empty == 0 and recipe and inv:room_for_item("dst", result) then
|
||||
meta:set_string("infotext", machine_name.." Active")
|
||||
meta:set_int("src_time", 0)
|
||||
next_state = 2+EU_saving_upgrade -- Next state is decided by the battery upgrade (state 2= 0 batteries, state 3 = 1 battery, 4 = 2 batteries)
|
||||
end
|
||||
end
|
||||
|
||||
elseif state == 2 or state == 3 or state == 4 then
|
||||
hacky_swap_node(pos, machine_node.."_active")
|
||||
meta:set_int("src_time", meta:get_int("src_time") + 1)
|
||||
if meta:get_int("src_time") == 4 then -- 4 ticks per output
|
||||
meta:set_string("src_time", 0)
|
||||
-- check if there's room for output in "dst" list and that we have the materials
|
||||
if recipe and inv:room_for_item("dst", result) then
|
||||
-- Take stuff from "src" list
|
||||
srcstack:take_item(recipe.src1_count)
|
||||
inv:set_stack("src", 1, srcstack)
|
||||
src2stack:take_item(recipe.src2_count)
|
||||
inv:set_stack("src2", 1, src2stack)
|
||||
-- Put result in "dst" list
|
||||
inv:add_item("dst",result)
|
||||
else
|
||||
next_state = 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
-- Change state?
|
||||
if next_state ~= state then
|
||||
meta:set_int("MV_EU_demand", machine_state_demand[next_state])
|
||||
meta:set_int("state", next_state)
|
||||
end
|
||||
|
||||
|
||||
|
||||
------------------------------------
|
||||
|
||||
-- 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")
|
233
technic/machines/mv/battery_box.lua
Normal file
233
technic/machines/mv/battery_box.lua
Normal file
@ -0,0 +1,233 @@
|
||||
-- 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;]"..
|
||||
"image[4,1;1,1;technic_battery_reload.png]"..
|
||||
"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;]"
|
||||
|
||||
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
|
||||
|
||||
local power_tools = technic.MV_power_tools
|
||||
|
||||
local charge_MV_tools = function(meta, charge)
|
||||
--charge registered power tools
|
||||
local inv = meta:get_inventory()
|
||||
if inv:is_empty("src")==false then
|
||||
local srcstack = inv:get_stack("src", 1)
|
||||
local src_item=srcstack:to_table()
|
||||
local src_meta=get_item_meta(src_item["metadata"])
|
||||
|
||||
local toolname = src_item["name"]
|
||||
if power_tools[toolname] ~= nil then
|
||||
-- Set meta data for the tool if it didn't do it itself :-(
|
||||
src_meta=get_item_meta(src_item["metadata"])
|
||||
if src_meta==nil then
|
||||
src_meta={}
|
||||
src_meta["technic_mv_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
else
|
||||
if src_meta["technic_mv_power_tool"]==nil then
|
||||
src_meta["technic_mv_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
end
|
||||
end
|
||||
-- Do the charging
|
||||
local item_max_charge = power_tools[toolname]
|
||||
local load = src_meta["charge"]
|
||||
local load_step = 1000 -- how much to charge per tick
|
||||
if load<item_max_charge and charge>0 then
|
||||
if charge-load_step<0 then load_step=charge end
|
||||
if load+load_step>item_max_charge then load_step=item_max_charge-load end
|
||||
load=load+load_step
|
||||
charge=charge-load_step
|
||||
technic.set_RE_wear(src_item,load,item_max_charge)
|
||||
src_meta["charge"] = load
|
||||
src_item["metadata"] = set_item_meta(src_meta)
|
||||
inv:set_stack("src", 1, src_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
return charge -- return the remaining charge in the battery
|
||||
end
|
||||
|
||||
local discharge_MV_tools = function(meta, charge, max_charge)
|
||||
-- discharging registered power tools
|
||||
local inv = meta:get_inventory()
|
||||
if inv:is_empty("dst") == false then
|
||||
srcstack = inv:get_stack("dst", 1)
|
||||
src_item=srcstack:to_table()
|
||||
local src_meta=get_item_meta(src_item["metadata"])
|
||||
local toolname = src_item["name"]
|
||||
if power_tools[toolname] ~= nil then
|
||||
-- Set meta data for the tool if it didn't do it itself :-(
|
||||
src_meta=get_item_meta(src_item["metadata"])
|
||||
if src_meta==nil then
|
||||
src_meta={}
|
||||
src_meta["technic_mv_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
else
|
||||
if src_meta["technic_mv_power_tool"]==nil then
|
||||
src_meta["technic_mv_power_tool"]=true
|
||||
src_meta["charge"]=0
|
||||
end
|
||||
end
|
||||
-- Do the discharging
|
||||
local item_max_charge = power_tools[toolname]
|
||||
local load = src_meta["charge"]
|
||||
local load_step = 4000 -- how much to discharge per tick
|
||||
if load>0 and charge<max_charge then
|
||||
if charge+load_step>max_charge then load_step=max_charge-charge end
|
||||
if load-load_step<0 then load_step=load end
|
||||
load=load-load_step
|
||||
charge=charge+load_step
|
||||
technic.set_RE_wear(src_item,load,item_max_charge)
|
||||
src_meta["charge"]=load
|
||||
src_item["metadata"]=set_item_meta(src_meta)
|
||||
inv:set_stack("dst", 1, src_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
return charge -- return the remaining charge in the battery
|
||||
end
|
||||
|
||||
minetest.register_abm(
|
||||
{
|
||||
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_MV_tools(meta, current_charge)
|
||||
current_charge = discharge_MV_tools(meta, current_charge, max_charge)
|
||||
|
||||
-- Set a demand (we allow batteries to charge on less than the demand though)
|
||||
meta:set_int("MV_EU_demand", math.min(max_charge_rate, max_charge-current_charge))
|
||||
|
||||
-- Set how much we can supply
|
||||
meta:set_int("MV_EU_supply", math.min(max_discharge_rate, current_charge))
|
||||
|
||||
meta:set_int("internal_EU_charge", current_charge)
|
||||
--dprint("BA: input:"..eu_input.." supply="..meta:get_int("MV_EU_supply").." demand="..meta:get_int("MV_EU_demand").." current:"..current_charge)
|
||||
|
||||
-- Select node textures
|
||||
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
|
||||
|
304
technic/machines/mv/electric_furnace.lua
Normal file
304
technic/machines/mv/electric_furnace.lua
Normal file
@ -0,0 +1,304 @@
|
||||
-- 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,
|
||||
},
|
||||
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,
|
||||
},
|
||||
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 and no tube is connected
|
||||
-- or if we have nothing to send with a tube connected.
|
||||
if (not output_tube_connected and inv:is_empty("src"))
|
||||
or ( output_tube_connected and inv:is_empty("dst")) then
|
||||
next_state = 1
|
||||
end
|
||||
----------------------
|
||||
|
||||
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")
|
13
technic/machines/mv/init.lua
Normal file
13
technic/machines/mv/init.lua
Normal file
@ -0,0 +1,13 @@
|
||||
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")
|
||||
dofile(path.."/alloy_furnace.lua")
|
||||
|
||||
-- The power radiator supplies appliances with inductive coupled power:
|
||||
-- Lighting and associated textures is taken directly from VanessaE's homedecor and made electric.
|
||||
dofile(path.."/power_radiator.lua")
|
||||
dofile(path.."/lighting.lua")
|
||||
|
590
technic/machines/mv/lighting.lua
Normal file
590
technic/machines/mv/lighting.lua
Normal file
@ -0,0 +1,590 @@
|
||||
-- NOTE: The code is takes directly from VanessaE's homedecor mod.
|
||||
-- I just made it the lights into indictive appliances for this mod.
|
||||
|
||||
-- This file supplies electric powered glowlights
|
||||
|
||||
-- Boilerplate to support localized strings if intllib mod is installed.
|
||||
local S
|
||||
if (minetest.get_modpath("intllib")) then
|
||||
dofile(minetest.get_modpath("intllib").."/intllib.lua")
|
||||
S = intllib.Getter(minetest.get_current_modname())
|
||||
else
|
||||
S = function ( s ) return s end
|
||||
end
|
||||
|
||||
function technic_homedecor_node_is_owned(pos, placer)
|
||||
local ownername = false
|
||||
if type(IsPlayerNodeOwner) == "function" then -- node_ownership mod
|
||||
if HasOwner(pos, placer) then -- returns true if the node is owned
|
||||
if not IsPlayerNodeOwner(pos, placer:get_player_name()) then
|
||||
if type(getLastOwner) == "function" then -- ...is an old version
|
||||
ownername = getLastOwner(pos)
|
||||
elseif type(GetNodeOwnerName) == "function" then -- ...is a recent version
|
||||
ownername = GetNodeOwnerName(pos)
|
||||
else
|
||||
ownername = S("someone")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
elseif type(isprotect)=="function" then -- glomie's protection mod
|
||||
if not isprotect(5, pos, placer) then
|
||||
ownername = S("someone")
|
||||
end
|
||||
elseif type(protector)=="table" and type(protector.can_dig)=="function" then -- Zeg9's protection mod
|
||||
if not protector.can_dig(5, pos, placer) then
|
||||
ownername = S("someone")
|
||||
end
|
||||
end
|
||||
|
||||
if ownername ~= false then
|
||||
minetest.chat_send_player( placer:get_player_name(), S("Sorry, %s owns that spot."):format(ownername) )
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
local dirs1 = { 20, 23, 22, 21 }
|
||||
local dirs2 = { 9, 18, 7, 12 }
|
||||
|
||||
local technic_homedecor_rotate_and_place = function(itemstack, placer, pointed_thing)
|
||||
if not technic_homedecor_node_is_owned(pointed_thing.under, placer)
|
||||
and not technic_homedecor_node_is_owned(pointed_thing.above, placer) then
|
||||
local node = minetest.env:get_node(pointed_thing.under)
|
||||
if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].on_rightclick then
|
||||
|
||||
local above = pointed_thing.above
|
||||
local under = pointed_thing.under
|
||||
local pitch = placer:get_look_pitch()
|
||||
local pname = minetest.env:get_node(under).name
|
||||
local node = minetest.env:get_node(above)
|
||||
local fdir = minetest.dir_to_facedir(placer:get_look_dir())
|
||||
local wield_name = itemstack:get_name()
|
||||
|
||||
if not minetest.registered_nodes[pname]
|
||||
or not minetest.registered_nodes[pname].on_rightclick then
|
||||
|
||||
local iswall = (above.x ~= under.x) or (above.z ~= under.z)
|
||||
local isceiling = (above.x == under.x) and (above.z == under.z) and (pitch > 0)
|
||||
local pos1 = above
|
||||
|
||||
if minetest.registered_nodes[pname]["buildable_to"] then
|
||||
pos1 = under
|
||||
iswall = false
|
||||
end
|
||||
|
||||
if not minetest.registered_nodes[minetest.env:get_node(pos1).name]["buildable_to"] then return end
|
||||
|
||||
if iswall then
|
||||
minetest.env:add_node(pos1, {name = wield_name, param2 = dirs2[fdir+1] }) -- place wall variant
|
||||
elseif isceiling then
|
||||
minetest.env:add_node(pos1, {name = wield_name, param2 = 20 }) -- place upside down variant
|
||||
else
|
||||
minetest.env:add_node(pos1, {name = wield_name, param2 = 0 }) -- place right side up
|
||||
end
|
||||
|
||||
if not homedecor_expect_infinite_stacks then
|
||||
itemstack:take_item()
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
else
|
||||
minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, placer, itemstack)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Yellow -- Half node
|
||||
minetest.register_node('technic:homedecor_glowlight_half_yellow', {
|
||||
description = S("Yellow Glowlight (thick)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_thick_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thick_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thick_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thick_yellow_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3 },
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thick)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_yellow_active")
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node('technic:homedecor_glowlight_half_yellow_active', {
|
||||
description = S("Yellow Glowlight (thick)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_thick_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thick_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thick_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thick_yellow_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
light_source = LIGHT_MAX,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3, not_in_creative_inventory=1},
|
||||
drop="technic:homedecor_glowlight_half_yellow",
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thick)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_yellow")
|
||||
end
|
||||
})
|
||||
|
||||
-- Yellow -- Quarter node
|
||||
minetest.register_node('technic:homedecor_glowlight_quarter_yellow', {
|
||||
description = S("Yellow Glowlight (thin)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_thin_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thin_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thin_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thin_yellow_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3 },
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thin)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_yellow_active")
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node('technic:homedecor_glowlight_quarter_yellow_active', {
|
||||
description = S("Yellow Glowlight (thin)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_thin_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thin_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thin_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_thin_yellow_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
light_source = LIGHT_MAX-1,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3, not_in_creative_inventory=1},
|
||||
drop="technic:homedecor_glowlight_quarter_yellow",
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 100, "Yellow Glowlight (thin)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_yellow")
|
||||
end
|
||||
})
|
||||
|
||||
|
||||
-- White -- half node
|
||||
minetest.register_node('technic:homedecor_glowlight_half_white', {
|
||||
description = S("White Glowlight (thick)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_white_tb.png',
|
||||
'technic_homedecor_glowlight_white_tb.png',
|
||||
'technic_homedecor_glowlight_thick_white_sides.png',
|
||||
'technic_homedecor_glowlight_thick_white_sides.png',
|
||||
'technic_homedecor_glowlight_thick_white_sides.png',
|
||||
'technic_homedecor_glowlight_thick_white_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3 },
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 100, "White Glowlight (thick)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_half_white_active")
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node('technic:homedecor_glowlight_half_white_active', {
|
||||
description = S("White Glowlight (thick)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_white_tb.png',
|
||||
'technic_homedecor_glowlight_white_tb.png',
|
||||
'technic_homedecor_glowlight_thick_white_sides.png',
|
||||
'technic_homedecor_glowlight_thick_white_sides.png',
|
||||
'technic_homedecor_glowlight_thick_white_sides.png',
|
||||
'technic_homedecor_glowlight_thick_white_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, 0, 0.5 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
light_source = LIGHT_MAX,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3, not_in_creative_inventory=1},
|
||||
drop="technic:homedecor_glowlight_half_white",
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 100, "White Glowlight (thick)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_half_white")
|
||||
end
|
||||
})
|
||||
|
||||
-- White -- Quarter node
|
||||
minetest.register_node('technic:homedecor_glowlight_quarter_white', {
|
||||
description = S("White Glowlight (thin)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_white_tb.png',
|
||||
'technic_homedecor_glowlight_white_tb.png',
|
||||
'technic_homedecor_glowlight_thin_white_sides.png',
|
||||
'technic_homedecor_glowlight_thin_white_sides.png',
|
||||
'technic_homedecor_glowlight_thin_white_sides.png',
|
||||
'technic_homedecor_glowlight_thin_white_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3 },
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 100, "White Glowlight (thin)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_off(pos, 100, "technic:homedecor_glowlight_quarter_white_active")
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node('technic:homedecor_glowlight_quarter_white_active', {
|
||||
description = S("White Glowlight (thin)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_white_tb.png',
|
||||
'technic_homedecor_glowlight_white_tb.png',
|
||||
'technic_homedecor_glowlight_thin_white_sides.png',
|
||||
'technic_homedecor_glowlight_thin_white_sides.png',
|
||||
'technic_homedecor_glowlight_thin_white_sides.png',
|
||||
'technic_homedecor_glowlight_thin_white_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.5, -0.5, -0.5, 0.5, -0.25, 0.5 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
light_source = LIGHT_MAX-1,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3, not_in_creative_inventory=1},
|
||||
drop="technic:homedecor_glowlight_quarter_white",
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 100, "White Glowlight (thin)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_quarter_white")
|
||||
end
|
||||
})
|
||||
|
||||
-- Glowlight "cubes" - yellow
|
||||
minetest.register_node('technic:homedecor_glowlight_small_cube_yellow', {
|
||||
description = S("Yellow Glowlight (small cube)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_cube_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_cube_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_cube_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_cube_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_cube_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_cube_yellow_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3 },
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_yellow_active")
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node('technic:homedecor_glowlight_small_cube_yellow_active', {
|
||||
description = S("Yellow Glowlight (small cube)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_cube_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_cube_yellow_tb.png',
|
||||
'technic_homedecor_glowlight_cube_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_cube_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_cube_yellow_sides.png',
|
||||
'technic_homedecor_glowlight_cube_yellow_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
light_source = LIGHT_MAX-1,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3, not_in_creative_inventory=1},
|
||||
drop="technic:homedecor_glowlight_small_cube_yellow",
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 50, "Yellow Glowlight (small cube)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_yellow")
|
||||
end
|
||||
})
|
||||
|
||||
-- Glowlight "cubes" - white
|
||||
minetest.register_node('technic:homedecor_glowlight_small_cube_white', {
|
||||
description = S("White Glowlight (small cube)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_cube_white_tb.png',
|
||||
'technic_homedecor_glowlight_cube_white_tb.png',
|
||||
'technic_homedecor_glowlight_cube_white_sides.png',
|
||||
'technic_homedecor_glowlight_cube_white_sides.png',
|
||||
'technic_homedecor_glowlight_cube_white_sides.png',
|
||||
'technic_homedecor_glowlight_cube_white_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3 },
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 50, "White Glowlight (small cube)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_off(pos, 50, "technic:homedecor_glowlight_small_cube_white_active")
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node('technic:homedecor_glowlight_small_cube_white_active', {
|
||||
description = S("White Glowlight (small cube)"),
|
||||
drawtype = "nodebox",
|
||||
tiles = {
|
||||
'technic_homedecor_glowlight_cube_white_tb.png',
|
||||
'technic_homedecor_glowlight_cube_white_tb.png',
|
||||
'technic_homedecor_glowlight_cube_white_sides.png',
|
||||
'technic_homedecor_glowlight_cube_white_sides.png',
|
||||
'technic_homedecor_glowlight_cube_white_sides.png',
|
||||
'technic_homedecor_glowlight_cube_white_sides.png'
|
||||
},
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
||||
},
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed = { -0.25, -0.5, -0.25, 0.25, 0, 0.25 }
|
||||
},
|
||||
|
||||
sunlight_propagates = false,
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
walkable = true,
|
||||
light_source = LIGHT_MAX-1,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
|
||||
groups = { snappy = 3, not_in_creative_inventory=1},
|
||||
drop="technic:homedecor_glowlight_small_cube_white",
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
technic_homedecor_rotate_and_place(itemstack, placer, pointed_thing)
|
||||
return itemstack
|
||||
end,
|
||||
on_construct = function(pos)
|
||||
technic.inductive_on_construct(pos, 50, "White Glowlight (small cube)")
|
||||
end,
|
||||
on_punch = function(pos, node, puncher)
|
||||
technic.inductive_on_punch_on(pos, 0, "technic:homedecor_glowlight_small_cube_white")
|
||||
end
|
||||
})
|
||||
|
||||
technic.register_inductive_machine("technic:homedecor_glowlight_half_yellow")
|
||||
technic.register_inductive_machine("technic:homedecor_glowlight_half_white")
|
||||
technic.register_inductive_machine("technic:homedecor_glowlight_quarter_yellow")
|
||||
technic.register_inductive_machine("technic:homedecor_glowlight_quarter_white")
|
||||
technic.register_inductive_machine("technic:homedecor_glowlight_small_cube_yellow")
|
||||
technic.register_inductive_machine("technic:homedecor_glowlight_small_cube_white")
|
226
technic/machines/mv/power_radiator.lua
Normal file
226
technic/machines/mv/power_radiator.lua
Normal file
@ -0,0 +1,226 @@
|
||||
-- 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")
|
82
technic/machines/mv/solar_array.lua
Normal file
82
technic/machines/mv/solar_array.lua
Normal file
@ -0,0 +1,82 @@
|
||||
-- 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")
|
||||
|
400
technic/machines/mv/wires.lua
Normal file
400
technic/machines/mv/wires.lua
Normal file
@ -0,0 +1,400 @@
|
||||
--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
|
||||
|
344
technic/machines/other/constructor.lua
Normal file
344
technic/machines/other/constructor.lua
Normal file
@ -0,0 +1,344 @@
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = 'technic:constructor_mk1_off 1',
|
||||
recipe = {'technic:nodebreaker_off', 'technic:deployer_off'},
|
||||
|
||||
})
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = 'technic:constructor_mk2_off 1',
|
||||
recipe = {'technic:constructor_mk1_off', 'technic:constructor_mk1_off'},
|
||||
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = 'technic:constructor_mk3_off 1',
|
||||
recipe = {'technic:constructor_mk2_off', 'technic:constructor_mk2_off'},
|
||||
|
||||
})
|
||||
|
||||
mk1_on = function(pos, node)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local pos1={}
|
||||
pos1.x=pos.x
|
||||
pos1.y=pos.y
|
||||
pos1.z=pos.z
|
||||
if node.param2==3 then pos1.x=pos1.x+1 end
|
||||
if node.param2==2 then pos1.z=pos1.z+1 end
|
||||
if node.param2==1 then pos1.x=pos1.x-1 end
|
||||
if node.param2==0 then pos1.z=pos1.z-1 end
|
||||
|
||||
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)
|
||||
deploy_node (inv,"slot1",pos1,node1,node)
|
||||
end
|
||||
end
|
||||
|
||||
mk1_off = function(pos, node)
|
||||
if node.name == "technic:constructor_mk1_on" then
|
||||
hacky_swap_node(pos,"technic:constructor_mk1_off")
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("technic:constructor_mk1_off", {
|
||||
description = "Constructor MK1",
|
||||
tile_images = {"technic_constructor_mk1_top_off.png","technic_constructor_mk1_bottom_off.png","technic_constructor_mk1_side2_off.png","technic_constructor_mk1_side1_off.png",
|
||||
"technic_constructor_back.png","technic_constructor_front_off.png"},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon_receptor_off = 1, mesecon_effector_off = 1, mesecon = 2},
|
||||
mesecons= {effector={action_on=mk1_on}},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"label[0,0;Constructor MK1]"..
|
||||
"label[5,0;Slot 1]"..
|
||||
"list[current_name;slot1;6,0;1,1;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
meta:set_string("infotext", "Constructor MK1")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("slot1", 1)
|
||||
end,
|
||||
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("slot1")
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("technic:constructor_mk1_on", {
|
||||
description = "Constructor MK1",
|
||||
tile_images = {"technic_constructor_mk1_top_on.png","technic_constructor_mk1_bottom_on.png","technic_constructor_mk1_side2_on.png","technic_constructor_mk1_side1_on.png",
|
||||
"technic_constructor_back.png","technic_constructor_front_on.png"},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon = 2,not_in_creative_inventory=1},
|
||||
mesecons= {effector={action_off=mk1_off}},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
|
||||
--Constructor MK2
|
||||
|
||||
mk2_on = function(pos, node)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local pos1={}
|
||||
local pos2={}
|
||||
pos1.x=pos.x
|
||||
pos1.y=pos.y
|
||||
pos1.z=pos.z
|
||||
pos2.x=pos.x
|
||||
pos2.y=pos.y
|
||||
pos2.z=pos.z
|
||||
if node.param2==3 then pos1.x=pos1.x+1 pos2.x=pos2.x+2 end
|
||||
if node.param2==2 then pos1.z=pos1.z+1 pos2.z=pos2.z+2 end
|
||||
if node.param2==1 then pos1.x=pos1.x-1 pos2.x=pos2.x-2 end
|
||||
if node.param2==0 then pos1.z=pos1.z-1 pos2.z=pos2.z-2 end
|
||||
|
||||
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)
|
||||
deploy_node (inv,"slot1",pos1,node1,node)
|
||||
local node1=minetest.env:get_node(pos2)
|
||||
deploy_node (inv,"slot2",pos2,node1,node)
|
||||
end
|
||||
end
|
||||
|
||||
mk2_off = function(pos, node)
|
||||
if node.name == "technic:constructor_mk2_on" then
|
||||
hacky_swap_node(pos,"technic:constructor_mk2_off")
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("technic:constructor_mk2_off", {
|
||||
description = "Constructor MK2",
|
||||
tile_images = {"technic_constructor_mk2_top_off.png","technic_constructor_mk2_bottom_off.png","technic_constructor_mk2_side2_off.png","technic_constructor_mk2_side1_off.png",
|
||||
"technic_constructor_back.png","technic_constructor_front_off.png"},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2},
|
||||
mesecons= {effector={action_on=mk2_on}},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"label[0,0;Constructor MK2]"..
|
||||
"label[5,0;Slot 1]"..
|
||||
"list[current_name;slot1;6,0;1,1;]"..
|
||||
"label[5,1;Slot 2]"..
|
||||
"list[current_name;slot2;6,1;1,1;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
meta:set_string("infotext", "Constructor MK2")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("slot1", 1)
|
||||
inv:set_size("slot2", 1)
|
||||
end,
|
||||
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env: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
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("technic:constructor_mk2_on", {
|
||||
description = "Constructor MK2",
|
||||
tile_images = {"technic_constructor_mk2_top_on.png","technic_constructor_mk2_bottom_on.png","technic_constructor_mk2_side2_on.png","technic_constructor_mk2_side1_on.png",
|
||||
"technic_constructor_back.png","technic_constructor_front_on.png"},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2, not_in_creative_inventory=1},
|
||||
mesecons= {effector={action_off=mk2_off}},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
|
||||
-- Constructor MK3
|
||||
mk3_on = function(pos, node)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local pos1={}
|
||||
local pos2={}
|
||||
local pos3={}
|
||||
local pos4={}
|
||||
|
||||
pos1.x=pos.x
|
||||
pos1.y=pos.y
|
||||
pos1.z=pos.z
|
||||
|
||||
pos2.x=pos.x
|
||||
pos2.y=pos.y
|
||||
pos2.z=pos.z
|
||||
|
||||
pos3.x=pos.x
|
||||
pos3.y=pos.y
|
||||
pos3.z=pos.z
|
||||
|
||||
pos4.x=pos.x
|
||||
pos4.y=pos.y
|
||||
pos4.z=pos.z
|
||||
|
||||
if node.param2==3 then pos1.x=pos1.x+1 pos2.x=pos2.x+2 pos3.x=pos3.x+3 pos4.x=pos4.x+4 end
|
||||
if node.param2==2 then pos1.z=pos1.z+1 pos2.z=pos2.z+2 pos3.z=pos3.z+3 pos4.z=pos4.z+4 end
|
||||
if node.param2==1 then pos1.x=pos1.x-1 pos2.x=pos2.x-2 pos3.x=pos3.x-3 pos4.x=pos4.x-4 end
|
||||
if node.param2==0 then pos1.z=pos1.z-1 pos2.z=pos2.z-2 pos3.z=pos3.z-3 pos4.z=pos4.z-4 end
|
||||
|
||||
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)
|
||||
deploy_node (inv,"slot1",pos1,node1,node)
|
||||
local node1=minetest.env:get_node(pos2)
|
||||
deploy_node (inv,"slot2",pos2,node1,node)
|
||||
local node1=minetest.env:get_node(pos3)
|
||||
deploy_node (inv,"slot3",pos3,node1,node)
|
||||
local node1=minetest.env:get_node(pos4)
|
||||
deploy_node (inv,"slot4",pos4,node1,node)
|
||||
end
|
||||
end
|
||||
|
||||
mk3_off = function(pos, node)
|
||||
if node.name == "technic:constructor_mk3_on" then
|
||||
hacky_swap_node(pos,"technic:constructor_mk3_off")
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("technic:constructor_mk3_off", {
|
||||
description = "Constructor MK3",
|
||||
tile_images = {"technic_constructor_mk3_top_off.png","technic_constructor_mk3_bottom_off.png","technic_constructor_mk3_side2_off.png","technic_constructor_mk3_side1_off.png",
|
||||
"technic_constructor_back.png","technic_constructor_front_off.png"},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2},
|
||||
mesecons= {effector={action_on=mk3_on}},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"label[0,0;Constructor MK2]"..
|
||||
"label[5,0;Slot 1]"..
|
||||
"list[current_name;slot1;6,0;1,1;]"..
|
||||
"label[5,1;Slot 2]"..
|
||||
"list[current_name;slot2;6,1;1,1;]"..
|
||||
"label[5,2;Slot 3]"..
|
||||
"list[current_name;slot3;6,2;1,1;]"..
|
||||
"label[5,3;Slot 4]"..
|
||||
"list[current_name;slot4;6,3;1,1;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
meta:set_string("infotext", "Constructor MK3")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("slot1", 1)
|
||||
inv:set_size("slot2", 1)
|
||||
inv:set_size("slot3", 1)
|
||||
inv:set_size("slot4", 1)
|
||||
|
||||
end,
|
||||
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env: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
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("technic:constructor_mk3_on", {
|
||||
description = "Constructor MK3",
|
||||
tile_images = {"technic_constructor_mk3_top_on.png","technic_constructor_mk3_bottom_on.png","technic_constructor_mk3_side2_on.png","technic_constructor_mk3_side1_on.png",
|
||||
"technic_constructor_back.png","technic_constructor_front_on.png"},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,not_in_creative_inventory=1},
|
||||
mesecons= {effector={action_off=mk3_off}},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
|
||||
deploy_node =function (inv, slot_name, pos1, node1, node)
|
||||
if node1.name == "air" then
|
||||
if not inv:is_empty(slot_name) then
|
||||
stack1=inv:get_list(slot_name)
|
||||
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)
|
||||
stack1[1]:take_item()
|
||||
inv:set_stack(slot_name, 1, stack1[1])
|
||||
elseif def.type == "craft" then
|
||||
if def.on_place then
|
||||
-- print("deploy_node: item has on_place. trying...")
|
||||
local ok, stk = pcall(def.on_place, stack1[1], nil, {
|
||||
-- Fake pointed_thing
|
||||
type = "node",
|
||||
above = pos1,
|
||||
under = { x=pos1.x, y=pos1.y-1, z=pos1.z },
|
||||
})
|
||||
if ok then
|
||||
-- print("deploy_node: on_place succeeded!")
|
||||
inv:set_stack(slot_name, 1, stk or stack1[1])
|
||||
return
|
||||
-- else
|
||||
-- print("deploy_node: WARNING: error while running on_place: "..tostring(stk))
|
||||
end
|
||||
end
|
||||
minetest.item_place_object(stack1[1], nil, {
|
||||
-- Fake pointed_thing
|
||||
type = "node",
|
||||
above = pos1,
|
||||
under = pos1,
|
||||
})
|
||||
inv:set_stack(slot_name, 1, nil)
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
if node1.name == "ignore" or
|
||||
node1.name == "default:lava_source" or
|
||||
node1.name == "default:lava_flowing" or
|
||||
node1.name == "default:water_source" or
|
||||
node1.name == "default:water_flowing"
|
||||
then return end
|
||||
if inv:room_for_item(slot_name,node1) then
|
||||
local def = minetest.registered_nodes[node1.name]
|
||||
if not def then return end
|
||||
local drop = def.drop or node1.name
|
||||
if type(drop) == "table" then
|
||||
local pr = PseudoRandom(math.random())
|
||||
local c = 0
|
||||
local loop = 0 -- Prevent infinite loop
|
||||
while (c < (drop.max_items or 1)) and (loop < 1000) do
|
||||
local i = math.floor(pr:next(1, #drop.items))
|
||||
if pr:next(1, drop.items[i].rarity or 1) == 1 then
|
||||
for _,item in ipairs(drop.items[i].items) do
|
||||
inv:add_item(slot_name,item)
|
||||
end
|
||||
c = c + 1
|
||||
end
|
||||
loop = loop + 1
|
||||
end
|
||||
minetest.env:remove_node(pos1)
|
||||
elseif type(drop) == "string" then
|
||||
inv:add_item(slot_name,drop)
|
||||
minetest.env:remove_node(pos1)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
113
technic/machines/other/deployer.lua
Normal file
113
technic/machines/other/deployer.lua
Normal file
@ -0,0 +1,113 @@
|
||||
minetest.register_craft({
|
||||
output = 'technic:deployer_off 1',
|
||||
recipe = {
|
||||
{'default:wood', 'default:chest','default:wood'},
|
||||
{'default:stone', 'mesecons:piston','default:stone'},
|
||||
{'default:stone', 'mesecons:mesecon','default:stone'},
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
deployer_signal_on = function(pos, node)
|
||||
local pos1={}
|
||||
pos1.x=pos.x
|
||||
pos1.y=pos.y
|
||||
pos1.z=pos.z
|
||||
if node.param2==3 then pos1.x=pos1.x+1 end
|
||||
if node.param2==2 then pos1.z=pos1.z+1 end
|
||||
if node.param2==1 then pos1.x=pos1.x-1 end
|
||||
if node.param2==0 then pos1.z=pos1.z-1 end
|
||||
|
||||
if node.name == "technic:deployer_off" then
|
||||
local node1=minetest.env:get_node(pos1)
|
||||
if node1.name == "air" then
|
||||
hacky_swap_node(pos,"technic:deployer_on")
|
||||
nodeupdate(pos)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
local i=0
|
||||
for _,stack in ipairs(inv:get_list("main")) do
|
||||
i=i+1
|
||||
if stack:get_name() ~=nil and minetest.registered_nodes[stack:get_name()]~=nil then
|
||||
node1={name=stack:get_name(), param1=0, param2=node.param2}
|
||||
minetest.env:place_node(pos1,node1)
|
||||
stack:take_item(1);
|
||||
inv:set_stack("main", i, stack)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
deployer_signal_off = function(pos, node)
|
||||
if node.name == "technic:deployer_on" then
|
||||
hacky_swap_node(pos,"technic:deployer_off")
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("technic:deployer_off", {
|
||||
description = "Deployer",
|
||||
tile_images = {"technic_deployer_top.png","technic_deployer_bottom.png","technic_deployer_side2.png","technic_deployer_side1.png",
|
||||
"technic_deployer_back.png","technic_deployer_front_off.png"},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, tubedevice_receiver=1},
|
||||
mesecons = {effector={action_on=deployer_signal_on}},
|
||||
tube={insert_object=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:add_item("main",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("main",stack)
|
||||
end,
|
||||
input_inventory="main"},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"label[0,0;Deployer]"..
|
||||
"list[current_name;main;4,1;3,3;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
meta:set_string("infotext", "Deployer")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 3*3)
|
||||
end,
|
||||
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("main") then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end,
|
||||
|
||||
})
|
||||
|
||||
minetest.register_node("technic:deployer_on", {
|
||||
description = "Deployer",
|
||||
tile_images = {"technic_deployer_top.png","technic_deployer_bottom.png","technic_deployer_side2.png","technic_deployer_side1.png",
|
||||
"technic_deployer_back.png","technic_deployer_front_on.png"},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1, tubedevice_receiver=1,not_in_creative_inventory=1},
|
||||
mesecons = {effector={action_off=deployer_signal_off}},
|
||||
tube={insert_object=function(pos,node,stack,direction)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv=meta:get_inventory()
|
||||
return inv:add_item("main",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("main",stack)
|
||||
end,
|
||||
input_inventory="main"},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
439
technic/machines/other/frames.lua
Normal file
439
technic/machines/other/frames.lua
Normal file
@ -0,0 +1,439 @@
|
||||
frames={}
|
||||
|
||||
function get_face(pos,ppos,pvect)
|
||||
ppos={x=ppos.x-pos.x,y=ppos.y-pos.y+1.5,z=ppos.z-pos.z}
|
||||
if pvect.x>0 then
|
||||
local t=(-0.5-ppos.x)/pvect.x
|
||||
local y_int=ppos.y+t*pvect.y
|
||||
local z_int=ppos.z+t*pvect.z
|
||||
if y_int>-0.4 and y_int<0.4 and z_int>-0.4 and z_int<0.4 then return 1 end
|
||||
elseif pvect.x<0 then
|
||||
local t=(0.5-ppos.x)/pvect.x
|
||||
local y_int=ppos.y+t*pvect.y
|
||||
local z_int=ppos.z+t*pvect.z
|
||||
if y_int>-0.4 and y_int<0.4 and z_int>-0.4 and z_int<0.4 then return 2 end
|
||||
end
|
||||
if pvect.y>0 then
|
||||
local t=(-0.5-ppos.y)/pvect.y
|
||||
local x_int=ppos.x+t*pvect.x
|
||||
local z_int=ppos.z+t*pvect.z
|
||||
if x_int>-0.4 and x_int<0.4 and z_int>-0.4 and z_int<0.4 then return 3 end
|
||||
elseif pvect.y<0 then
|
||||
local t=(0.5-ppos.y)/pvect.y
|
||||
local x_int=ppos.x+t*pvect.x
|
||||
local z_int=ppos.z+t*pvect.z
|
||||
if x_int>-0.4 and x_int<0.4 and z_int>-0.4 and z_int<0.4 then return 4 end
|
||||
end
|
||||
if pvect.z>0 then
|
||||
local t=(-0.5-ppos.z)/pvect.z
|
||||
local x_int=ppos.x+t*pvect.x
|
||||
local y_int=ppos.y+t*pvect.y
|
||||
if x_int>-0.4 and x_int<0.4 and y_int>-0.4 and y_int<0.4 then return 5 end
|
||||
elseif pvect.z<0 then
|
||||
local t=(0.5-ppos.z)/pvect.z
|
||||
local x_int=ppos.x+t*pvect.x
|
||||
local y_int=ppos.y+t*pvect.y
|
||||
if x_int>-0.4 and x_int<0.4 and y_int>-0.4 and y_int<0.4 then return 6 end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for xm=0,1 do
|
||||
for xp=0,1 do
|
||||
for ym=0,1 do
|
||||
for yp=0,1 do
|
||||
for zm=0,1 do
|
||||
for zp=0,1 do
|
||||
|
||||
local a=8/16
|
||||
local b=7/16
|
||||
local nodeboxes= {
|
||||
{ -a, -a, -a, -b, a, -b },
|
||||
{ -a, -a, b, -b, a, a },
|
||||
{ b, -a, b, a, a, a },
|
||||
{ b, -a, -a, a, a, -b },
|
||||
|
||||
{ -b, b, -a, b, a, -b },
|
||||
{ -b, -a, -a, b, -b, -b },
|
||||
|
||||
{ -b, b, b, b, a, a },
|
||||
{ -b, -a, b, b, -b, a },
|
||||
|
||||
{ b, b, -b, a, a, b },
|
||||
{ b, -a, -b, a, -b, b },
|
||||
|
||||
{ -a, b, -b, -b, a, b },
|
||||
{ -a, -a, -b, -b, -b, b },
|
||||
}
|
||||
|
||||
if yp==0 then
|
||||
table.insert(nodeboxes, {-b,b,-b, b,a,b})
|
||||
end
|
||||
if ym==0 then
|
||||
table.insert(nodeboxes, {-b,-a,-b, b,-b,b})
|
||||
end
|
||||
if xp==0 then
|
||||
table.insert(nodeboxes, {b,b,b,a,-b,-b})
|
||||
end
|
||||
if xm==0 then
|
||||
table.insert(nodeboxes, {-a,-b,-b,-b,b,b})
|
||||
end
|
||||
if zp==0 then
|
||||
table.insert(nodeboxes, {-b,-b,b, b,b,a})
|
||||
end
|
||||
if zm==0 then
|
||||
table.insert(nodeboxes, {-b,-b,-a, b,b,-b})
|
||||
end
|
||||
|
||||
local nameext=tostring(xm)..tostring(xp)..tostring(ym)..tostring(yp)..tostring(zm)..tostring(zp)
|
||||
local groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2}
|
||||
if nameext~="111111" then groups.not_in_creative_inventory=1 end
|
||||
|
||||
|
||||
minetest.register_node("technic:frame_"..nameext,{
|
||||
description = "Frame",
|
||||
tiles = {"technic_frame.png"},
|
||||
groups=groups,
|
||||
drawtype = "nodebox",
|
||||
node_box = {
|
||||
type = "fixed",
|
||||
fixed=nodeboxes,
|
||||
},
|
||||
selection_box = {
|
||||
type="fixed",
|
||||
fixed={-0.5,-0.5,-0.5,0.5,0.5,0.5}
|
||||
},
|
||||
paramtype = "light",
|
||||
frame=1,
|
||||
drop="technic:frame_111111",
|
||||
frame_connect_all=function(pos)
|
||||
local nodename=minetest.env:get_node(pos).name
|
||||
l2={}
|
||||
l1={{x=-1,y=0,z=0},{x=1,y=0,z=0},{x=0,y=-1,z=0},{x=0,y=1,z=0},{x=0,y=0,z=-1},{x=0,y=0,z=1}}
|
||||
for i,dir in ipairs(l1) do
|
||||
if string.sub(nodename,-7+i,-7+i)=="1" then
|
||||
l2[#(l2)+1]=dir
|
||||
end
|
||||
end
|
||||
return l2
|
||||
end,
|
||||
on_punch=function(pos,node,puncher)
|
||||
local ppos=puncher:getpos()
|
||||
local pvect=puncher:get_look_dir()
|
||||
local pface=get_face(pos,ppos,pvect)
|
||||
if pface==nil then return end
|
||||
local nodename=node.name
|
||||
local newstate=tostring(1-tonumber(string.sub(nodename,-7+pface,-7+pface)))
|
||||
if pface<=5 then
|
||||
nodename=string.sub(nodename,1,-7+pface-1)..newstate..string.sub(nodename,-7+pface+1)
|
||||
else
|
||||
nodename=string.sub(nodename,1,-2)..newstate
|
||||
end
|
||||
node.name=nodename
|
||||
minetest.env:set_node(pos,node)
|
||||
end
|
||||
})
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function frame_motor1_on(pos,node)
|
||||
local npos={x=pos.x,y=pos.y+1,z=pos.z}
|
||||
local nnode=minetest.env:get_node(npos)
|
||||
if node.param2==0 then
|
||||
dir={x=1,y=0,z=0}
|
||||
elseif node.param2==1 then
|
||||
dir={x=0,y=0,z=-1}
|
||||
elseif node.param2==2 then
|
||||
dir={x=-1,y=0,z=0}
|
||||
else
|
||||
dir={x=0,y=0,z=1}
|
||||
end
|
||||
if minetest.registered_nodes[nnode.name].frame==1 then
|
||||
local connected_nodes=get_connected_nodes(npos)
|
||||
move_nodes_vect(connected_nodes,dir)
|
||||
end
|
||||
end
|
||||
|
||||
function frame_motor2_on(pos,node)
|
||||
local npos={x=pos.x,y=pos.y-1,z=pos.z}
|
||||
local nnode=minetest.env:get_node(npos)
|
||||
if node.param2==0 then
|
||||
dir={x=1,y=0,z=0}
|
||||
elseif node.param2==1 then
|
||||
dir={x=0,y=0,z=-1}
|
||||
elseif node.param2==2 then
|
||||
dir={x=-1,y=0,z=0}
|
||||
else
|
||||
dir={x=0,y=0,z=1}
|
||||
end
|
||||
if minetest.registered_nodes[nnode.name].frame==1 then
|
||||
local connected_nodes=get_connected_nodes(npos)
|
||||
move_nodes_vect(connected_nodes,dir)
|
||||
end
|
||||
end
|
||||
|
||||
function frame_motor3_on(pos,node)
|
||||
local npos={x=pos.x,y=pos.y,z=pos.z}
|
||||
if node.param2==0 then
|
||||
dir={x=1,y=0,z=0}
|
||||
npos.z=npos.z-1
|
||||
elseif node.param2==1 then
|
||||
dir={x=0,y=0,z=-1}
|
||||
npos.x=npos.x-1
|
||||
elseif node.param2==2 then
|
||||
dir={x=-1,y=0,z=0}
|
||||
npos.z=npos.z+1
|
||||
else
|
||||
dir={x=0,y=0,z=1}
|
||||
npos.x=npos.x+1
|
||||
end
|
||||
local nnode=minetest.env:get_node(npos)
|
||||
if minetest.registered_nodes[nnode.name].frame==1 then
|
||||
local connected_nodes=get_connected_nodes(npos)
|
||||
move_nodes_vect(connected_nodes,dir)
|
||||
end
|
||||
end
|
||||
|
||||
function frame_motor4_on(pos,node)
|
||||
local npos={x=pos.x,y=pos.y,z=pos.z}
|
||||
if node.param2==0 then
|
||||
dir={x=-1,y=0,z=0}
|
||||
npos.z=npos.z-1
|
||||
elseif node.param2==1 then
|
||||
dir={x=0,y=0,z=1}
|
||||
npos.x=npos.x-1
|
||||
elseif node.param2==2 then
|
||||
dir={x=1,y=0,z=0}
|
||||
npos.z=npos.z+1
|
||||
else
|
||||
dir={x=0,y=0,z=-1}
|
||||
npos.x=npos.x+1
|
||||
end
|
||||
local nnode=minetest.env:get_node(npos)
|
||||
if minetest.registered_nodes[nnode.name].frame==1 then
|
||||
local connected_nodes=get_connected_nodes(npos)
|
||||
move_nodes_vect(connected_nodes,dir)
|
||||
end
|
||||
end
|
||||
|
||||
function frame_motor5_on(pos,node)
|
||||
local npos={x=pos.x,y=pos.y,z=pos.z}
|
||||
if node.param2==0 then
|
||||
npos.z=npos.z-1
|
||||
elseif node.param2==1 then
|
||||
npos.x=npos.x-1
|
||||
elseif node.param2==2 then
|
||||
npos.z=npos.z+1
|
||||
else
|
||||
npos.x=npos.x+1
|
||||
end
|
||||
dir={x=0,y=1,z=0}
|
||||
local nnode=minetest.env:get_node(npos)
|
||||
if minetest.registered_nodes[nnode.name].frame==1 then
|
||||
local connected_nodes=get_connected_nodes(npos)
|
||||
move_nodes_vect(connected_nodes,dir)
|
||||
end
|
||||
end
|
||||
|
||||
function frame_motor6_on(pos,node)
|
||||
local npos={x=pos.x,y=pos.y,z=pos.z}
|
||||
if node.param2==0 then
|
||||
npos.z=npos.z-1
|
||||
elseif node.param2==1 then
|
||||
npos.x=npos.x-1
|
||||
elseif node.param2==2 then
|
||||
npos.z=npos.z+1
|
||||
else
|
||||
npos.x=npos.x+1
|
||||
end
|
||||
dir={x=0,y=-1,z=0}
|
||||
local nnode=minetest.env:get_node(npos)
|
||||
if minetest.registered_nodes[nnode.name].frame==1 then
|
||||
local connected_nodes=get_connected_nodes(npos)
|
||||
move_nodes_vect(connected_nodes,dir)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("technic:frame_motor1",{
|
||||
description = "Frame motor 1",
|
||||
tiles = {"pipeworks_filter_top.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,mesecon=2},
|
||||
paramtype2 = "facedir",
|
||||
mesecons={effector={action_on=frame_motor1_on}},
|
||||
frames_can_connect=function(pos,dir)
|
||||
return dir.y~=-1
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("technic:frame_motor2",{
|
||||
description = "Frame motor 2",
|
||||
tiles = {"technic_lv_cable.png", "pipeworks_filter_top.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,mesecon=2},
|
||||
paramtype2 = "facedir",
|
||||
mesecons={effector={action_on=frame_motor2_on}},
|
||||
frames_can_connect=function(pos,dir)
|
||||
return dir.y~=1
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("technic:frame_motor3",{
|
||||
description = "Frame motor 3",
|
||||
tiles = {"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png",
|
||||
"technic_lv_cable.png", "technic_lv_cable.png", "pipeworks_filter_top.png"},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2},
|
||||
paramtype2 = "facedir",
|
||||
mesecons={effector={action_on=frame_motor3_on}},
|
||||
frames_can_connect=function(pos,dir)
|
||||
local node=minetest.env:get_node(pos)
|
||||
if node.param2==0 then return dir.z~=1
|
||||
elseif node.param2==1 then return dir.x~=1
|
||||
elseif node.param2==2 then return dir.z~=-1
|
||||
else return dir.x~=-1 end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("technic:frame_motor4",{
|
||||
description = "Frame motor 4",
|
||||
tiles = {"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png",
|
||||
"technic_lv_cable.png", "technic_lv_cable.png", "pipeworks_filter_top.png^[transformR180"},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2},
|
||||
paramtype2 = "facedir",
|
||||
mesecons={effector={action_on=frame_motor4_on}},
|
||||
frames_can_connect=function(pos,dir)
|
||||
local node=minetest.env:get_node(pos)
|
||||
if node.param2==0 then return dir.z~=1
|
||||
elseif node.param2==1 then return dir.x~=1
|
||||
elseif node.param2==2 then return dir.z~=-1
|
||||
else return dir.x~=-1 end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("technic:frame_motor5",{
|
||||
description = "Frame motor 5",
|
||||
tiles = {"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png",
|
||||
"technic_lv_cable.png", "technic_lv_cable.png", "pipeworks_filter_top.png^[transformR90"},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2},
|
||||
paramtype2 = "facedir",
|
||||
mesecons={effector={action_on=frame_motor5_on}},
|
||||
frames_can_connect=function(pos,dir)
|
||||
local node=minetest.env:get_node(pos)
|
||||
if node.param2==0 then return dir.z~=1
|
||||
elseif node.param2==1 then return dir.x~=1
|
||||
elseif node.param2==2 then return dir.z~=-1
|
||||
else return dir.x~=-1 end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("technic:frame_motor6",{
|
||||
description = "Frame motor 6",
|
||||
tiles = {"technic_lv_cable.png", "technic_lv_cable.png", "technic_lv_cable.png",
|
||||
"technic_lv_cable.png", "technic_lv_cable.png", "pipeworks_filter_top.png^[transformR270"},
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,mesecon=2},
|
||||
paramtype2 = "facedir",
|
||||
mesecons={effector={action_on=frame_motor6_on}},
|
||||
frames_can_connect=function(pos,dir)
|
||||
local node=minetest.env:get_node(pos)
|
||||
if node.param2==0 then return dir.z~=1
|
||||
elseif node.param2==1 then return dir.x~=1
|
||||
elseif node.param2==2 then return dir.z~=-1
|
||||
else return dir.x~=-1 end
|
||||
end
|
||||
})
|
||||
|
||||
function add_table(table,toadd)
|
||||
local i=1
|
||||
while true do
|
||||
o=table[i]
|
||||
if o==toadd then return end
|
||||
if o==nil then break end
|
||||
i=i+1
|
||||
end
|
||||
table[i]=toadd
|
||||
end
|
||||
|
||||
function move_nodes_vect(poslist,vect)
|
||||
for _,pos in ipairs(poslist) do
|
||||
local npos=frames.addVect(pos,vect)
|
||||
local name = minetest.env:get_node(npos).name
|
||||
if (name~="air" and minetest.registered_nodes[name].liquidtype=="none") and not(pos_in_list(poslist,npos)) then
|
||||
return end
|
||||
end
|
||||
nodelist={}
|
||||
for _,pos in ipairs(poslist) do
|
||||
local node=minetest.env:get_node(pos)
|
||||
local meta=minetest.env:get_meta(pos):to_table()
|
||||
nodelist[#(nodelist)+1]={pos=pos,node=node,meta=meta}
|
||||
end
|
||||
objects={}
|
||||
for _,pos in ipairs(poslist) do
|
||||
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, 1)) do
|
||||
add_table(objects,object)
|
||||
end
|
||||
end
|
||||
for _,obj in ipairs(objects) do
|
||||
obj:setpos(frames.addVect(obj:getpos(),vect))
|
||||
le=obj:get_luaentity()
|
||||
if le and le.name == "pipeworks:tubed_item" then
|
||||
le.start_pos=frames.addVect(le.start_pos,vect)
|
||||
end
|
||||
end
|
||||
for _,n in ipairs(nodelist) do
|
||||
local npos=frames.addVect(n.pos,vect)
|
||||
minetest.env:set_node(npos,n.node)
|
||||
local meta=minetest.env:get_meta(npos)
|
||||
meta:from_table(n.meta)
|
||||
for __,pos in ipairs(poslist) do
|
||||
if npos.x==pos.x and npos.y==pos.y and npos.z==pos.z then
|
||||
table.remove(poslist, __)
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
for __,pos in ipairs(poslist) do
|
||||
minetest.env:remove_node(pos)
|
||||
end
|
||||
end
|
||||
|
||||
function get_connected_nodes(pos)
|
||||
c={pos}
|
||||
local nodename=minetest.env:get_node(pos).name
|
||||
connected(pos,c,minetest.registered_nodes[nodename].frame_connect_all(pos))
|
||||
return c
|
||||
end
|
||||
|
||||
function frames.addVect(pos,vect)
|
||||
return {x=pos.x+vect.x,y=pos.y+vect.y,z=pos.z+vect.z}
|
||||
end
|
||||
|
||||
function pos_in_list(l,pos)
|
||||
for _,p in ipairs(l) do
|
||||
if p.x==pos.x and p.y==pos.y and p.z==pos.z then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function connected(pos,c,adj)
|
||||
for _,vect in ipairs(adj) do
|
||||
local pos1=frames.addVect(pos,vect)
|
||||
local nodename=minetest.env:get_node(pos1).name
|
||||
if not(pos_in_list(c,pos1)) and nodename~="air" and
|
||||
(minetest.registered_nodes[nodename].frames_can_connect==nil or
|
||||
minetest.registered_nodes[nodename].frames_can_connect(pos1,vect)) then
|
||||
c[#(c)+1]=pos1
|
||||
if minetest.registered_nodes[nodename].frame==1 then
|
||||
local adj=minetest.registered_nodes[nodename].frame_connect_all(pos1)
|
||||
connected(pos1,c,adj)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
8
technic/machines/other/init.lua
Normal file
8
technic/machines/other/init.lua
Normal file
@ -0,0 +1,8 @@
|
||||
local path = technic.modpath.."/machines/other"
|
||||
|
||||
-- mesecons and tubes related
|
||||
dofile(path.."/injector.lua")
|
||||
dofile(path.."/node_breaker.lua")
|
||||
dofile(path.."/deployer.lua")
|
||||
dofile(path.."/constructor.lua")
|
||||
dofile(path.."/frames.lua")
|
117
technic/machines/other/injector.lua
Normal file
117
technic/machines/other/injector.lua
Normal file
@ -0,0 +1,117 @@
|
||||
minetest.register_craftitem("technic:injector", {
|
||||
description = "Injector",
|
||||
stack_max = 99,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'technic:injector 1',
|
||||
recipe = {
|
||||
{'', 'technic:control_logic_unit',''},
|
||||
{'', 'default:chest',''},
|
||||
{'', 'pipeworks:tube_000000',''},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_node("technic:injector", {
|
||||
description = "Injector",
|
||||
tiles = {"technic_injector_top.png", "technic_injector_bottom.png", "technic_injector_side.png",
|
||||
"technic_injector_side.png", "technic_injector_side.png", "technic_injector_side.png"},
|
||||
groups = chest_groups1,
|
||||
tube = tubes_properties,
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"label[0,0;Injector]"..
|
||||
"button[0,1;.8,.8;mode;]"..
|
||||
"label[.8,1;Mode: single items]"..
|
||||
"list[current_name;main;0,2;8,2;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
meta:set_string("infotext", "Injector")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("main", 8*4)
|
||||
meta:set_string("mode","single items")
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
return inv:is_empty("main")
|
||||
end,
|
||||
on_receive_fields = function(pos, formanme, fields, sender)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local mode=meta:get_string("mode")
|
||||
if fields.mode then
|
||||
if mode=="single items" then mode="whole stacks"
|
||||
else mode="single items"
|
||||
end
|
||||
local mode=meta:set_string("mode",mode)
|
||||
end
|
||||
meta:set_string("formspec",
|
||||
"invsize[8,9;]"..
|
||||
"label[0,0;Injector]"..
|
||||
"button[0,1;.8,.8;mode;]"..
|
||||
"label[.8,1;Mode: "..mode.."]"..
|
||||
"list[current_name;main;0,2;8,2;]"..
|
||||
"list[current_player;main;0,5;8,4;]")
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"technic:injector"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local pos1={}
|
||||
pos1.x = pos.x
|
||||
pos1.y = pos.y-1
|
||||
pos1.z = pos.z
|
||||
local meta=minetest.env:get_meta(pos1)
|
||||
if meta:get_int("tubelike")==1 then inject_items (pos) end
|
||||
end,
|
||||
})
|
||||
|
||||
function inject_items (pos)
|
||||
local meta=minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local mode=meta:get_string("mode")
|
||||
if mode=="single items" then
|
||||
local i=0
|
||||
for _,stack in ipairs(inv:get_list("main")) 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=0, y=-1, z=0})
|
||||
item1:setacceleration({x=0, y=0, z=0})
|
||||
stack:take_item(1);
|
||||
inv:set_stack("main", i, stack)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if mode=="whole stacks" then
|
||||
local i=0
|
||||
for _,stack in ipairs(inv:get_list("main")) do
|
||||
i=i+1
|
||||
if stack then
|
||||
local item0=stack:to_table()
|
||||
if item0 then
|
||||
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=0, y=-1, z=0})
|
||||
item1:setacceleration({x=0, y=0, z=0})
|
||||
stack:clear()
|
||||
inv:set_stack("main", i, stack)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
89
technic/machines/other/node_breaker.lua
Normal file
89
technic/machines/other/node_breaker.lua
Normal file
@ -0,0 +1,89 @@
|
||||
minetest.register_craft({
|
||||
output = 'technic:nodebreaker_off 1',
|
||||
recipe = {
|
||||
{'default:wood', 'default:pick_mese','default:wood'},
|
||||
{'default:stone', 'mesecons:piston','default:stone'},
|
||||
{'default:stone', 'mesecons:mesecon','default:stone'},
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
node_breaker_on = function(pos, node)
|
||||
if node.name == "technic:nodebreaker_off" then
|
||||
hacky_swap_node(pos,"technic:nodebreaker_on")
|
||||
break_node (pos,node.param2)
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
|
||||
node_breaker_off = function(pos, node)
|
||||
if node.name == "technic:nodebreaker_on" then
|
||||
hacky_swap_node(pos,"technic:nodebreaker_off")
|
||||
nodeupdate(pos)
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_node("technic:nodebreaker_off", {
|
||||
description = "Node Breaker",
|
||||
tile_images = {"technic_nodebreaker_top_off.png","technic_nodebreaker_bottom_off.png","technic_nodebreaker_side2_off.png","technic_nodebreaker_side1_off.png",
|
||||
"technic_nodebreaker_back.png","technic_nodebreaker_front_off.png"},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1},
|
||||
mesecons= {effector={action_on=node_breaker_on, action_off=node_breaker_off}},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
end,
|
||||
|
||||
})
|
||||
|
||||
minetest.register_node("technic:nodebreaker_on", {
|
||||
description = "Node Breaker",
|
||||
tile_images = {"technic_nodebreaker_top_on.png","technic_nodebreaker_bottom_on.png","technic_nodebreaker_side2_on.png","technic_nodebreaker_side1_on.png",
|
||||
"technic_nodebreaker_back.png","technic_nodebreaker_front_on.png"},
|
||||
mesecons= {effector={action_on=node_breaker_on, action_off=node_breaker_off}},
|
||||
is_ground_content = true,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, mesecon = 2,tubedevice=1,not_in_creative_inventory=1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
|
||||
function break_node (pos,n_param)
|
||||
local pos1={}
|
||||
local pos2={}
|
||||
pos1.x=pos.x
|
||||
pos1.y=pos.y
|
||||
pos1.z=pos.z
|
||||
pos2.x=pos.x
|
||||
pos2.y=pos.y
|
||||
pos2.z=pos.z
|
||||
|
||||
--param2 3=x+ 1=x- 2=z+ 0=z-
|
||||
local x_velocity=0
|
||||
local z_velocity=0
|
||||
|
||||
if n_param==3 then pos2.x=pos2.x+1 pos1.x=pos1.x-1 x_velocity=-1 end
|
||||
if n_param==2 then pos2.z=pos2.z+1 pos1.z=pos1.z-1 z_velocity=-1 end
|
||||
if n_param==1 then pos2.x=pos2.x-1 pos1.x=pos1.x+1 x_velocity=1 end
|
||||
if n_param==0 then pos2.z=pos2.z-1 pos1.x=pos1.z+1 z_velocity=1 end
|
||||
|
||||
local node=minetest.env:get_node(pos2)
|
||||
if node.name == "air" then return nil end
|
||||
if node.name == "default:lava_source" then return nil end
|
||||
if node.name == "default:lava_flowing" then return nil end
|
||||
if node.name == "default:water_source" then minetest.env:remove_node(pos2) return nil end
|
||||
if node.name == "default:water_flowing" then minetest.env:remove_node(pos2) return nil end
|
||||
if node.name == "ignore" then minetest.env:remove_node(pos2) return nil end
|
||||
local drops = minetest.get_node_drops(node.name, "default:pick_mese")
|
||||
local _, dropped_item
|
||||
for _, dropped_item in ipairs(drops) do
|
||||
local item1=tube_item({x=pos.x,y=pos.y,z=pos.z},dropped_item)
|
||||
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})
|
||||
end
|
||||
minetest.env:remove_node(pos2)
|
||||
end
|
||||
|
17
technic/machines/other/tetris.lua
Normal file
17
technic/machines/other/tetris.lua
Normal file
@ -0,0 +1,17 @@
|
||||
minetest.register_node("technic:tetris_machine_node1", {
|
||||
tiles = {"tetris_machine_top.png", "technic_mv_battery_box_bottom.png", "tetris_machine_front1.png",
|
||||
"tetris_machine_side1B.png", "tetris_machine_side1P.png", "tetris_machine_side1L.png"},
|
||||
tile_images = {"technic_tetris_machine.png",},
|
||||
is_ground_content = true,
|
||||
groups = {cracky=1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("technic:tetris_machine_node2", {
|
||||
tiles = {"tetris_machine_top.png", "technic_mv_battery_box_bottom.png", "tetris_machine_front2.png",
|
||||
"tetris_machine_side2B.png", "tetris_machine_side2P.png", "tetris_machine_side2L.png"},
|
||||
tile_images = {"technic_tetris_machine.png",},
|
||||
is_ground_content = true,
|
||||
groups = {cracky=1},
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
})
|
232
technic/machines/supply_converter.lua
Normal file
232
technic/machines/supply_converter.lua
Normal file
@ -0,0 +1,232 @@
|
||||
-- The supply converter is a generic device which can convert from
|
||||
-- LV to MV and back, and HV to MV and back.
|
||||
-- The machine will not convert from HV directly to LV.
|
||||
-- The machine is configured by the wiring below and above it.
|
||||
-- It is prepared for an upgrade slot if this is to be implemented later.
|
||||
--
|
||||
-- The conversion factor is a constant and the conversion is a lossy operation.
|
||||
--
|
||||
-- It works like this:
|
||||
-- The top side is setup as the "RE" side, the bottom as the "PR" side.
|
||||
-- Once the RE side is powered it will deliver power to the other side.
|
||||
-- Unused power is wasted just like any other producer!
|
||||
--
|
||||
minetest.register_node(
|
||||
"technic:supply_converter", {
|
||||
description = "Supply Converter",
|
||||
tiles = {"technic_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_craft({
|
||||
output = 'technic:supply_converter 1',
|
||||
recipe = {
|
||||
{'technic:stainless_steel_ingot', 'technic:stainless_steel_ingot','technic:stainless_steel_ingot'},
|
||||
{'technic:mv_transformer', 'technic:mv_cable', 'technic:lv_transformer'},
|
||||
{'technic:mv_cable', 'technic:rubber', 'technic:lv_cable'},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_abm(
|
||||
{ nodenames = {"technic:supply_converter"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
-- Conversion factors (a picture of V*A - loss) Asymmetric.
|
||||
local lv_mv_factor = 5 -- division (higher is less efficient)
|
||||
local mv_lv_factor = 4 -- multiplication (higher is more efficient)
|
||||
local mv_hv_factor = 5 -- division
|
||||
local hv_mv_factor = 4 -- multiplication
|
||||
local max_lv_demand = 2000 -- The increment size power supply tier. Determines how many are needed
|
||||
local max_mv_demand = 2000 -- -""-
|
||||
local max_hv_demand = 2000 -- -""-
|
||||
|
||||
-- Machine information
|
||||
local machine_name = "Supply Converter"
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local upgrade = "" -- Replace with expansion slot later??
|
||||
|
||||
-- High voltage on top, low at bottom regardless of converter direction
|
||||
local pos_up = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
local pos_down = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local meta_up = minetest.env:get_meta(pos_up)
|
||||
local meta_down = minetest.env:get_meta(pos_down)
|
||||
local convert_MV_LV = 0
|
||||
local convert_LV_MV = 0
|
||||
local convert_MV_HV = 0
|
||||
local convert_HV_MV = 0
|
||||
-- check cabling
|
||||
if meta_up:get_float("mv_cablelike") == 1 and meta_down:get_float("cablelike") == 1 then
|
||||
convert_MV_LV = 1
|
||||
upgrade = "MV-LV step down"
|
||||
end
|
||||
if meta_up:get_float("cablelike") == 1 and meta_down:get_float("mv_cablelike") == 1 then
|
||||
convert_LV_MV = 1
|
||||
upgrade = "LV-MV step up"
|
||||
end
|
||||
if meta_up:get_float("mv_cablelike") == 1 and meta_down:get_float("hv_cablelike") == 1 then
|
||||
convert_MV_HV = 1
|
||||
upgrade = "MV-HV step up"
|
||||
end
|
||||
if meta_up:get_float("hv_cablelike") == 1 and meta_down:get_float("mv_cablelike") == 1 then
|
||||
convert_HV_MV = 1
|
||||
upgrade = "HV-MV step down"
|
||||
end
|
||||
--print("Cabling:"..convert_MV_LV.."|"..convert_LV_MV.."|"..convert_HV_MV.."|"..convert_MV_HV)
|
||||
|
||||
if convert_MV_LV == 0 and convert_LV_MV == 0 and convert_HV_MV == 0 and convert_MV_HV == 0 then
|
||||
meta:set_string("infotext", machine_name.." has bad cabling")
|
||||
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
|
||||
|
||||
-- The node is programmed with an upgrade slot
|
||||
-- containing a MV-LV step down, LV-MV step up, HV-MV step down or MV-HV step up unit
|
||||
|
||||
if upgrade == "" then
|
||||
meta:set_string("infotext", machine_name.." has an empty converter slot");
|
||||
technic.unregister_LV_machine("technic:supply_converter")
|
||||
technic.unregister_MV_machine("technic:supply_converter")
|
||||
technic.unregister_HV_machine("technic:supply_converter")
|
||||
meta:set_int("LV_EU_demand", 0)
|
||||
meta:set_int("LV_EU_supply", 0)
|
||||
meta:set_int("LV_EU_input", 0)
|
||||
meta:set_int("MV_EU_demand", 0)
|
||||
meta:set_int("MV_EU_supply", 0)
|
||||
meta:set_int("MV_EU_input", 0)
|
||||
meta:set_int("HV_EU_demand", 0)
|
||||
meta:set_int("HV_EU_supply", 0)
|
||||
meta:set_int("HV_EU_input", 0)
|
||||
return
|
||||
end
|
||||
|
||||
-- State machine
|
||||
if upgrade == "MV-LV step down" and convert_MV_LV then
|
||||
-- Register machine type
|
||||
technic.register_LV_machine("technic:supply_converter","PR")
|
||||
technic.register_MV_machine("technic:supply_converter","RE")
|
||||
|
||||
-- Power off automatically if no longer connected to a switching station
|
||||
technic.switching_station_timeout_count(pos, "MV")
|
||||
|
||||
local eu_input = meta:get_int("MV_EU_input")
|
||||
if eu_input == 0 then
|
||||
-- Unpowered - go idle
|
||||
--hacky_swap_node(pos, machine_node)
|
||||
meta:set_string("infotext", machine_name.." Unpowered")
|
||||
meta:set_int("LV_EU_supply", 0)
|
||||
meta:set_int("MV_EU_supply", 0)
|
||||
|
||||
meta:set_int("LV_EU_demand", 0)
|
||||
meta:set_int("MV_EU_demand", max_mv_demand)
|
||||
else
|
||||
-- MV side has got power to spare
|
||||
meta:set_string("infotext", machine_name.." is active (MV:"..max_mv_demand.."->LV:"..eu_input*mv_lv_factor..")");
|
||||
meta:set_int("LV_EU_supply", eu_input*mv_lv_factor)
|
||||
end
|
||||
---------------------------------------------------
|
||||
elseif upgrade == "LV-MV step up" and convert_LV_MV then
|
||||
-- Register machine type
|
||||
technic.register_LV_machine("technic:supply_converter","RE")
|
||||
technic.register_MV_machine("technic:supply_converter","PR")
|
||||
|
||||
-- Power off automatically if no longer connected to a switching station
|
||||
technic.switching_station_timeout_count(pos, "LV")
|
||||
|
||||
local eu_input = meta:get_int("LV_EU_input")
|
||||
if eu_input == 0 then
|
||||
-- Unpowered - go idle
|
||||
--hacky_swap_node(pos, machine_node)
|
||||
meta:set_string("infotext", machine_name.." Unpowered")
|
||||
meta:set_int("LV_EU_supply", 0)
|
||||
meta:set_int("MV_EU_supply", 0)
|
||||
|
||||
meta:set_int("LV_EU_demand", max_lv_demand)
|
||||
meta:set_int("MV_EU_demand", 0)
|
||||
else
|
||||
-- LV side has got power to spare
|
||||
meta:set_string("infotext", machine_name.." is active (LV:"..max_lv_demand.."->MV:"..eu_input/lv_mv_factor..")");
|
||||
meta:set_int("MV_EU_supply", eu_input/lv_mv_factor)
|
||||
end
|
||||
---------------------------------------------------
|
||||
|
||||
elseif upgrade == "HV-MV step down" and convert_HV_MV then
|
||||
-- Register machine type
|
||||
technic.register_MV_machine("technic:supply_converter","PR")
|
||||
technic.register_HV_machine("technic:supply_converter","RE")
|
||||
|
||||
-- Power off automatically if no longer connected to a switching station
|
||||
technic.switching_station_timeout_count(pos, "HV")
|
||||
|
||||
local eu_input = meta:get_int("HV_EU_input")
|
||||
if eu_input == 0 then
|
||||
-- Unpowered - go idle
|
||||
--hacky_swap_node(pos, machine_node)
|
||||
meta:set_string("infotext", machine_name.." Unpowered")
|
||||
meta:set_int("MV_EU_supply", 0)
|
||||
meta:set_int("HV_EU_supply", 0)
|
||||
|
||||
meta:set_int("MV_EU_demand", 0)
|
||||
meta:set_int("HV_EU_demand", max_hv_demand)
|
||||
else
|
||||
-- HV side has got power to spare
|
||||
meta:set_string("infotext", machine_name.." is active (HV:"..max_hv_demand.."->MV:"..eu_input*hv_mv_factor..")");
|
||||
meta:set_int("MV_EU_supply", eu_input*hv_mv_factor)
|
||||
end
|
||||
---------------------------------------------------
|
||||
elseif upgrade == "MV-HV step up" and convert_MV_HV then
|
||||
-- Register machine type
|
||||
technic.register_MV_machine("technic:supply_converter","RE")
|
||||
technic.register_HV_machine("technic:supply_converter","PR")
|
||||
|
||||
-- Power off automatically if no longer connected to a switching station
|
||||
technic.switching_station_timeout_count(pos, "MV")
|
||||
|
||||
local eu_input = meta:get_int("MV_EU_input")
|
||||
if eu_input == 0 then
|
||||
-- Unpowered - go idle
|
||||
--hacky_swap_node(pos, machine_node)
|
||||
meta:set_string("infotext", machine_name.." Unpowered")
|
||||
meta:set_int("MV_EU_supply", 0)
|
||||
meta:set_int("HV_EU_supply", 0)
|
||||
|
||||
meta:set_int("MV_EU_demand", max_mv_demand)
|
||||
meta:set_int("HV_EU_demand", 0)
|
||||
else
|
||||
-- MV side has got power to spare
|
||||
meta:set_string("infotext", machine_name.." is active (MV:"..max_mv_demand.."->HV:"..eu_input/mv_hv_factor..")");
|
||||
meta:set_int("HV_EU_supply", eu_input/mv_hv_factor)
|
||||
end
|
||||
---------------------------------------------------
|
||||
end
|
||||
end,
|
||||
})
|
352
technic/machines/switching_station.lua
Normal file
352
technic/machines/switching_station.lua
Normal file
@ -0,0 +1,352 @@
|
||||
-- SWITCHING STATION
|
||||
-- The switching station is the center of all power distribution on an electric network.
|
||||
-- The station will collect all produced power from producers (PR) and batteries (BA)
|
||||
-- and distribute it to receivers (RE) and depleted batteries (BA).
|
||||
--
|
||||
-- It works like this:
|
||||
-- All PR,BA,RE nodes are indexed and tagged with the switching station.
|
||||
-- The tagging is to allow more stations to be built without allowing a cheat
|
||||
-- with duplicating power.
|
||||
-- All the RE nodes are queried for their current EU demand. Those which are off
|
||||
-- would require no or a small standby EU demand, while those which are on would
|
||||
-- require more.
|
||||
-- If the total demand is less than the available power they are all updated with the
|
||||
-- demand number.
|
||||
-- If any surplus exists from the PR nodes the batteries will be charged evenly with this.
|
||||
-- If the total demand requires draw on the batteries they will be discharged evenly.
|
||||
--
|
||||
-- If the total demand is more than the available power all RE nodes will be shut down.
|
||||
-- We have a brown-out situation.
|
||||
--
|
||||
-- Hence all the power distribution logic resides in this single node.
|
||||
--
|
||||
-- Nodes connected to the network will have one or more of these parameters as meta data:
|
||||
-- <LV|MV|HV>_EU_supply : Exists for PR and BA node types. This is the EU value supplied by the node. Output
|
||||
-- <LV|MV|HV>_EU_demand : Exists for RE and BA node types. This is the EU value the node requires to run. Output
|
||||
-- <LV|MV|HV>_EU_input : Exists for RE and BA node types. This is the actual EU value the network can give the node. Input
|
||||
--
|
||||
-- The reason the LV|MV|HV type is prepended toe meta data is because some machine could require several supplies to work.
|
||||
-- This way the supplies are separated per network.
|
||||
technic.DBG = 1
|
||||
local dprint = technic.dprint
|
||||
|
||||
minetest.register_craft(
|
||||
{
|
||||
output = 'technic:switching_station 1',
|
||||
recipe = {
|
||||
{'technic:lv_transformer', 'technic:mv_transformer', 'technic:hv_transformer'},
|
||||
{'technic:lv_transformer', 'technic:mv_transformer', 'technic:hv_transformer'},
|
||||
{'technic:lv_cable', 'technic:mv_cable', 'technic:hv_cable'},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_node(
|
||||
"technic:switching_station",
|
||||
{description = "Switching Station",
|
||||
tiles = {"technic_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
|
||||
})
|
||||
|
||||
--------------------------------------------------
|
||||
-- Functions to help the machines on the electrical network
|
||||
--------------------------------------------------
|
||||
-- This one provides a timeout for a node in case it was disconnected from the network
|
||||
-- A node must be touched by the station continuously in order to function
|
||||
technic.switching_station_timeout_count = function(pos, machine_tier)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
timeout = meta:get_int(machine_tier.."_EU_timeout")
|
||||
--print("Counting timeout "..timeout)
|
||||
if timeout == 0 then
|
||||
--print("OFF")
|
||||
meta:set_int(machine_tier.."_EU_input", 0)
|
||||
else
|
||||
--print("ON")
|
||||
meta:set_int(machine_tier.."_EU_timeout", timeout-1)
|
||||
end
|
||||
end
|
||||
|
||||
--------------------------------------------------
|
||||
-- Functions to traverse the electrical network
|
||||
--------------------------------------------------
|
||||
|
||||
-- Add a wire node to the LV/MV/HV network
|
||||
local add_new_cable_node = function(nodes,pos)
|
||||
local i = 1
|
||||
repeat
|
||||
if nodes[i]==nil then break end
|
||||
if pos.x==nodes[i].x and pos.y==nodes[i].y and pos.z==nodes[i].z then return false end
|
||||
i=i+1
|
||||
until false
|
||||
nodes[i] = {x=pos.x, y=pos.y, z=pos.z, visited=1} -- copy position
|
||||
return true
|
||||
end
|
||||
|
||||
-- Generic function to add found connected nodes to the right classification array
|
||||
local check_node_subp = function(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos,machines,cablename)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local name = minetest.env:get_node(pos).name
|
||||
if meta:get_float(cablename)==1 then
|
||||
add_new_cable_node(all_nodes,pos)
|
||||
elseif machines[name] then
|
||||
--dprint(name.." is a "..machines[name])
|
||||
if machines[name] == "PR" then
|
||||
add_new_cable_node(PR_nodes,pos)
|
||||
elseif machines[name] == "RE" then
|
||||
add_new_cable_node(RE_nodes,pos)
|
||||
elseif machines[name] == "BA" then
|
||||
add_new_cable_node(BA_nodes,pos)
|
||||
end
|
||||
if cablename == "cablelike" then
|
||||
meta:set_int("LV_EU_timeout", 2) -- Touch node
|
||||
elseif cablename == "mv_cablelike" then
|
||||
meta:set_int("MV_EU_timeout", 2) -- Touch node
|
||||
elseif cablename == "hv_cablelike" then
|
||||
meta:set_int("HV_EU_timeout", 2) -- Touch node
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Traverse a network given a list of machines and a cable type name
|
||||
local traverse_network = function(PR_nodes,RE_nodes,BA_nodes,all_nodes, i, machines, cablename)
|
||||
local pos = {x=all_nodes[i].x, y=all_nodes[i].y, z=all_nodes[i].z} -- copy position
|
||||
pos.x=pos.x+1
|
||||
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
|
||||
pos.x=pos.x-2
|
||||
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
|
||||
pos.x=pos.x+1
|
||||
|
||||
pos.y=pos.y+1
|
||||
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
|
||||
pos.y=pos.y-2
|
||||
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
|
||||
pos.y=pos.y+1
|
||||
|
||||
pos.z=pos.z+1
|
||||
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
|
||||
pos.z=pos.z-2
|
||||
check_node_subp(PR_nodes,RE_nodes,BA_nodes,all_nodes,pos, machines, cablename)
|
||||
pos.z=pos.z+1
|
||||
end
|
||||
|
||||
----------------------------------------------
|
||||
-- The action code for the switching station
|
||||
----------------------------------------------
|
||||
minetest.register_abm(
|
||||
{nodenames = {"technic:switching_station"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local meta1 = nil
|
||||
local pos1 = {}
|
||||
local PR_EU = 0 -- EUs from PR nodes
|
||||
local BA_PR_EU = 0 -- EUs from BA nodes (discharching)
|
||||
local BA_RE_EU = 0 -- EUs to BA nodes (charging)
|
||||
local RE_EU = 0 -- EUs to RE nodes
|
||||
|
||||
local network = ""
|
||||
local all_nodes = {}
|
||||
local PR_nodes = {}
|
||||
local BA_nodes = {}
|
||||
local RE_nodes = {}
|
||||
|
||||
-- -- Possible to turn off the entire network
|
||||
-- if meta:get_int("active") == 0 then
|
||||
-- for _,pos1 in pairs(RE_nodes) do
|
||||
-- meta1 = minetest.env:get_meta(pos1)
|
||||
-- meta1:set_int("EU_input", 0)
|
||||
-- end
|
||||
-- for _,pos1 in pairs(BA_nodes) do
|
||||
-- meta1 = minetest.env:get_meta(pos1)
|
||||
-- meta1:set_int("EU_input", 0)
|
||||
-- end
|
||||
-- return
|
||||
-- end
|
||||
|
||||
-- Which kind of network are we on:
|
||||
pos1 = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
all_nodes[1] = pos1
|
||||
|
||||
meta1 = minetest.env:get_meta(pos1)
|
||||
if meta1:get_float("cablelike") ==1 then
|
||||
-- LV type
|
||||
--dprint("LV type")
|
||||
network = "LV"
|
||||
local table_index = 1
|
||||
repeat
|
||||
traverse_network(PR_nodes,RE_nodes,BA_nodes,all_nodes,table_index, technic.LV_machines, "cablelike")
|
||||
table_index = table_index + 1
|
||||
if all_nodes[table_index] == nil then break end
|
||||
until false
|
||||
elseif meta1:get_float("mv_cablelike") ==1 then
|
||||
-- MV type
|
||||
--dprint("MV type")
|
||||
network = "MV"
|
||||
local table_index = 1
|
||||
repeat
|
||||
traverse_network(PR_nodes,RE_nodes,BA_nodes,all_nodes,table_index, technic.MV_machines, "mv_cablelike")
|
||||
table_index = table_index + 1
|
||||
if all_nodes[table_index] == nil then break end
|
||||
until false
|
||||
elseif meta1:get_float("hv_cablelike") ==1 then
|
||||
-- HV type
|
||||
--dprint("HV type")
|
||||
network = "HV"
|
||||
local table_index = 1
|
||||
repeat
|
||||
traverse_network(PR_nodes,RE_nodes,BA_nodes,all_nodes,table_index, technic.HV_machines, "hv_cablelike")
|
||||
table_index = table_index + 1
|
||||
if all_nodes[table_index] == nil then break end
|
||||
until false
|
||||
else
|
||||
-- No type :-)
|
||||
--dprint("Not connected to a network")
|
||||
meta:set_string("infotext", "Switching Station - no network")
|
||||
return
|
||||
end
|
||||
--dprint("nodes="..table.getn(all_nodes).." PR="..table.getn(PR_nodes).." BA="..table.getn(BA_nodes).." RE="..table.getn(RE_nodes))
|
||||
|
||||
-- Strings for the meta data
|
||||
local eu_demand_str = network.."_EU_demand"
|
||||
local eu_input_str = network.."_EU_input"
|
||||
local eu_supply_str = network.."_EU_supply"
|
||||
local eu_from_fuel_str = network.."_EU_from_fuel"
|
||||
|
||||
-- Get all the power from the PR nodes
|
||||
local PR_eu_supply = 0 -- Total power
|
||||
for _,pos1 in pairs(PR_nodes) do
|
||||
meta1 = minetest.env:get_meta(pos1)
|
||||
PR_eu_supply = PR_eu_supply + meta1:get_int(eu_supply_str)
|
||||
end
|
||||
--dprint("Total PR supply:"..PR_eu_supply)
|
||||
|
||||
-- Get all the demand from the RE nodes
|
||||
local RE_eu_demand = 0
|
||||
for _,pos1 in pairs(RE_nodes) do
|
||||
meta1 = minetest.env:get_meta(pos1)
|
||||
RE_eu_demand = RE_eu_demand + meta1:get_int(eu_demand_str)
|
||||
end
|
||||
--dprint("Total RE demand:"..RE_eu_demand)
|
||||
|
||||
-- Get all the power from the BA nodes
|
||||
local BA_eu_supply = 0
|
||||
for _,pos1 in pairs(BA_nodes) do
|
||||
meta1 = minetest.env:get_meta(pos1)
|
||||
BA_eu_supply = BA_eu_supply + meta1:get_int(eu_supply_str)
|
||||
end
|
||||
--dprint("Total BA supply:"..BA_eu_supply)
|
||||
|
||||
-- Get all the demand from the BA nodes
|
||||
local BA_eu_demand = 0
|
||||
for _,pos1 in pairs(BA_nodes) do
|
||||
meta1 = minetest.env:get_meta(pos1)
|
||||
BA_eu_demand = BA_eu_demand + meta1:get_int(eu_demand_str)
|
||||
end
|
||||
--dprint("Total BA demand:"..BA_eu_demand)
|
||||
|
||||
meta:set_string("infotext", "Switching Station. PR("..(PR_eu_supply+BA_eu_supply)..") RE("..(RE_eu_demand+BA_eu_demand)..")")
|
||||
|
||||
-- If the PR supply is enough for the RE demand supply them all
|
||||
if PR_eu_supply >= RE_eu_demand then
|
||||
--dprint("PR_eu_supply"..PR_eu_supply.." >= RE_eu_demand"..RE_eu_demand)
|
||||
for _,pos1 in pairs(RE_nodes) do
|
||||
meta1 = minetest.env:get_meta(pos1)
|
||||
local eu_demand = meta1:get_int(eu_demand_str)
|
||||
meta1:set_int(eu_input_str, eu_demand)
|
||||
end
|
||||
-- We have a surplus, so distribute the rest equally to the BA nodes
|
||||
-- Let's calculate the factor of the demand
|
||||
PR_eu_supply = PR_eu_supply - RE_eu_demand
|
||||
local charge_factor = 0 -- Assume all batteries fully charged
|
||||
if BA_eu_demand > 0 then
|
||||
charge_factor = PR_eu_supply / BA_eu_demand
|
||||
end
|
||||
for n,pos1 in pairs(BA_nodes) do
|
||||
meta1 = minetest.env:get_meta(pos1)
|
||||
local eu_demand = meta1:get_int(eu_demand_str)
|
||||
meta1:set_int(eu_input_str, math.floor(eu_demand*charge_factor))
|
||||
--dprint("Charging battery:"..math.floor(eu_demand*charge_factor))
|
||||
end
|
||||
-- If still a surplus we can start giving back to the fuel burning generators
|
||||
-- Only full EU packages are given back. The rest is wasted.
|
||||
if BA_eu_demand == 0 then
|
||||
for _,pos1 in pairs(PR_nodes) do
|
||||
meta1 = minetest.env:get_meta(pos1)
|
||||
if meta1:get_int(eu_from_fuel_str) == 1 then
|
||||
local eu_supply = meta1:get_int(eu_supply_str)
|
||||
if PR_eu_supply < eu_supply then
|
||||
break
|
||||
else
|
||||
-- Set the supply to 0 if we did not require it.
|
||||
meta1:set_int(eu_supply_str, 0)
|
||||
PR_eu_supply = PR_eu_supply - eu_supply
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- If the PR supply is not enough for the RE demand we will discharge the batteries too
|
||||
if PR_eu_supply+BA_eu_supply >= RE_eu_demand then
|
||||
--dprint("PR_eu_supply "..PR_eu_supply.."+BA_eu_supply "..BA_eu_supply.." >= RE_eu_demand"..RE_eu_demand)
|
||||
for _,pos1 in pairs(RE_nodes) do
|
||||
meta1 = minetest.env:get_meta(pos1)
|
||||
local eu_demand = meta1:get_int(eu_demand_str)
|
||||
meta1:set_int(eu_input_str, eu_demand)
|
||||
end
|
||||
-- We have a deficit, so distribute to the BA nodes
|
||||
-- Let's calculate the factor of the supply
|
||||
local charge_factor = 0 -- Assume all batteries depleted
|
||||
if BA_eu_supply > 0 then
|
||||
charge_factor = (PR_eu_supply - RE_eu_demand) / BA_eu_supply
|
||||
end
|
||||
for n,pos1 in pairs(BA_nodes) do
|
||||
meta1 = minetest.env:get_meta(pos1)
|
||||
local eu_supply = meta1:get_int(eu_supply_str)
|
||||
meta1:set_int(eu_input_str, math.floor(eu_supply*charge_factor))
|
||||
--dprint("Discharging battery:"..math.floor(eu_supply*charge_factor))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- If the PR+BA supply is not enough for the RE demand: Shut everything down!
|
||||
-- Note: another behaviour could also be imagined: provide the average power for all and let the node decide what happens.
|
||||
-- This is much simpler though: Not enough power for all==no power for all
|
||||
--print("NO POWER")
|
||||
for _,pos1 in pairs(RE_nodes) do
|
||||
meta1 = minetest.env:get_meta(pos1)
|
||||
meta1:set_int(eu_input_str, 0)
|
||||
end
|
||||
end,
|
||||
})
|
Reference in New Issue
Block a user