Partial rewrite

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,111 @@
function technic.handle_machine_upgrades(meta)
-- Get the names of the upgrades
local inv = meta:get_inventory()
local upg_item1
local upg_item2
local srcstack = inv:get_stack("upgrade1", 1)
if srcstack then
upg_item1 = srcstack:to_table()
end
srcstack = inv:get_stack("upgrade2", 1)
if srcstack then
upg_item2 = srcstack:to_table()
end
-- Save some power by installing battery upgrades.
-- Tube loading speed can be upgraded using control logic units.
local EU_upgrade = 0
local tube_upgrade = 0
if upg_item1 then
if upg_item1.name == "technic:battery" then
EU_upgrade = EU_upgrade + 1
elseif upg_item1.name == "technic:control_logic_unit" then
tube_upgrade = tube_upgrade + 1
end
end
if upg_item2 then
if upg_item2.name == "technic:battery" then
EU_upgrade = EU_upgrade + 1
elseif upg_item2.name == "technic:control_logic_unit" then
tube_upgrade = tube_upgrade + 1
end
end
return EU_upgrade, tube_upgrade
end
function technic.send_items(pos, x_velocity, z_velocity)
-- Send items on their way in the pipe system.
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local i = 0
for _, stack in ipairs(inv:get_list("dst")) do
i = i + 1
if stack then
local item0 = stack:to_table()
if item0 then
item0["count"] = "1"
local item1 = tube_item({x=pos.x, y=pos.y, z=pos.z}, item0)
item1:get_luaentity().start_pos = {x=pos.x, y=pos.y, z=pos.z}
item1:setvelocity({x=x_velocity, y=0, z=z_velocity})
item1:setacceleration({x=0, y=0, z=0})
stack:take_item(1)
inv:set_stack("dst", i, stack)
return
end
end
end
end
function technic.smelt_item(meta, result, speed)
local inv = meta:get_inventory()
meta:set_int("cook_time", meta:get_int("cook_time") + 1)
if meta:get_int("cook_time") < result.time / speed then
return
end
local result = minetest.get_craft_result({method = "cooking", width = 1, items = inv:get_list("src")})
if result and result.item then
meta:set_int("cook_time", 0)
-- check if there's room for output in "dst" list
if inv:room_for_item("dst", result) then
srcstack = inv:get_stack("src", 1)
srcstack:take_item()
inv:set_stack("src", 1, srcstack)
inv:add_item("dst", result.item)
end
end
end
function technic.handle_machine_pipeworks(pos, tube_upgrade)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local pos1 = vector.new(pos)
local x_velocity = 0
local z_velocity = 0
-- Output is on the left side of the furnace
if node.param2 == 3 then pos1.z = pos1.z - 1 z_velocity = -1 end
if node.param2 == 2 then pos1.x = pos1.x - 1 x_velocity = -1 end
if node.param2 == 1 then pos1.z = pos1.z + 1 z_velocity = 1 end
if node.param2 == 0 then pos1.x = pos1.x + 1 x_velocity = 1 end
local output_tube_connected = false
local meta1 = minetest.get_meta(pos1)
if meta1:get_int("tubelike") == 1 then
output_tube_connected = true
end
tube_time = meta:get_int("tube_time")
tube_time = tube_time + tube_upgrade
if tube_time > 3 then
tube_time = 0
if output_tube_connected then
technic.send_items(pos, x_velocity, z_velocity)
end
end
meta:set_int("tube_time", tube_time)
end

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,69 @@
function technic.register_solar_array(data)
local tier = data.tier
local ltier = string.lower(tier)
minetest.register_node("technic:solar_array_"..ltier, {
tiles = {"technic_"..ltier.."_solar_array_top.png", "technic_"..ltier.."_solar_array_bottom.png",
"technic_"..ltier.."_solar_array_side.png", "technic_"..ltier.."_solar_array_side.png",
"technic_"..ltier.."_solar_array_side.png", "technic_"..ltier.."_solar_array_side.png"},
groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2},
sounds = default.node_sound_wood_defaults(),
description = tier.." Solar Array",
active = false,
drawtype = "nodebox",
paramtype = "light",
node_box = {
type = "fixed",
fixed = {-0.5, -0.5, -0.5, 0.5, 0, 0.5},
},
technic = data,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
local name = minetest.get_node(pos).name
local tier = minetest.registered_nodes[name].technic.tier
meta:set_int(tier.."_EU_supply", 0)
end,
})
minetest.register_abm({
nodenames = {"technic:solar_array_"..ltier},
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
-- The action here is to make the solar array produce power
-- Power is dependent on the light level and the height above ground
-- 130m and above is optimal as it would be above cloud level.
-- Height gives 1/4 of the effect, light 3/4. Max. effect is 2880EU for the array.
-- There are many ways to cheat by using other light sources like lamps.
-- As there is no way to determine if light is sunlight that is just a shame.
-- To take care of some of it solar panels do not work outside daylight hours or if
-- built below -10m
local pos1 = {}
pos1.y = pos.y + 1
pos1.x = pos.x
pos1.z = pos.z
local light = minetest.get_node_light(pos1, nil)
local time_of_day = minetest.get_timeofday()
local meta = minetest.get_meta(pos)
light = light or 0
local data = minetest.registered_nodes[node.name].technic
-- turn on array only during day time and if sufficient light
-- I know this is counter intuitive when cheating by using other light sources.
if light >= 12 and time_of_day >= 0.24 and time_of_day <= 0.76 and pos.y > 0 then
local charge_to_give = math.floor((light + pos.y) * data.power)
charge_to_give = math.max(charge_to_give, 0)
charge_to_give = math.min(charge_to_give, data.power * 50)
meta:set_string("infotext", "Solar Array is active ("..charge_to_give.."EU)")
meta:set_int(data.tier.."_EU_supply", charge_to_give)
else
meta:set_string("infotext", "Solar Array is inactive");
meta:set_int(data.tier.."_EU_supply", 0)
end
end,
})
technic.register_machine(tier, "technic:solar_array_"..ltier, technic.producer)
end