summaryrefslogtreecommitdiff
path: root/technic/machines
diff options
context:
space:
mode:
authorVanessa Ezekowitz <vanessaezekowitz@gmail.com>2017-03-14 00:04:17 -0400
committerVanessa Ezekowitz <vanessaezekowitz@gmail.com>2017-03-14 00:04:17 -0400
commit6885943d0491db83268f8bb4743bfd82ed725ea2 (patch)
tree4be2bba618fe67d1b99a99f9aedf1a0f397a9c9c /technic/machines
parenta46f07cbfbd9ae59b7b1cc2fc32f68c39ae34de0 (diff)
downloaddreambuilder_modpack-6885943d0491db83268f8bb4743bfd82ed725ea2.tar
dreambuilder_modpack-6885943d0491db83268f8bb4743bfd82ed725ea2.tar.gz
dreambuilder_modpack-6885943d0491db83268f8bb4743bfd82ed725ea2.tar.bz2
dreambuilder_modpack-6885943d0491db83268f8bb4743bfd82ed725ea2.tar.xz
dreambuilder_modpack-6885943d0491db83268f8bb4743bfd82ed725ea2.zip
update coloredwood, digilines, technic, gloopblocks, homedecor, mesecons,
pipeworks, player_textures, signs_lib, unifieddyes, and worldedit
Diffstat (limited to 'technic/machines')
-rw-r--r--technic/machines/HV/quarry.lua13
-rw-r--r--technic/machines/init.lua1
-rw-r--r--technic/machines/other/constructor.lua2
-rw-r--r--technic/machines/power_monitor.lua67
-rw-r--r--technic/machines/register/cables.lua108
-rw-r--r--technic/machines/supply_converter.lua61
-rw-r--r--technic/machines/switching_station.lua79
7 files changed, 301 insertions, 30 deletions
diff --git a/technic/machines/HV/quarry.lua b/technic/machines/HV/quarry.lua
index 8255676..8d87b65 100644
--- a/technic/machines/HV/quarry.lua
+++ b/technic/machines/HV/quarry.lua
@@ -12,6 +12,7 @@ minetest.register_craft({
local quarry_dig_above_nodes = 3 -- How far above the quarry we will dig nodes
local quarry_max_depth = 100
local quarry_demand = 10000
+local quarry_eject_dir = vector.new(0, 1, 0)
local function set_quarry_formspec(meta)
local radius = meta:get_int("size")
@@ -83,7 +84,7 @@ local function quarry_handle_purge(pos)
if stack then
local item = stack:to_table()
if item then
- technic.tube_inject_item(pos, pos, vector.new(0, 1, 0), item)
+ technic.tube_inject_item(pos, pos, quarry_eject_dir, item)
stack:clear()
inv:set_stack("cache", i, stack)
break
@@ -217,6 +218,16 @@ minetest.register_node("technic:quarry", {
connect_sides = {"bottom", "front", "left", "right"},
tube = {
connect_sides = {top = 1},
+ -- lower priority than other tubes, so that quarries will prefer any
+ -- other tube to another quarry, which could lead to server freezes
+ -- in certain quarry placements (2x2 for example would never eject)
+ priority = 10,
+ can_go = function(pos, node, velocity, stack)
+ -- always eject the same, even if items came in another way
+ -- this further mitigates loops and generally avoids random sideway movement
+ -- that can be expected in certain quarry placements
+ return { quarry_eject_dir }
+ end
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
diff --git a/technic/machines/init.lua b/technic/machines/init.lua
index ad79eab..f2e31c9 100644
--- a/technic/machines/init.lua
+++ b/technic/machines/init.lua
@@ -8,6 +8,7 @@ dofile(path.."/MV/init.lua")
dofile(path.."/HV/init.lua")
dofile(path.."/switching_station.lua")
+dofile(path.."/power_monitor.lua")
dofile(path.."/supply_converter.lua")
dofile(path.."/other/init.lua")
diff --git a/technic/machines/other/constructor.lua b/technic/machines/other/constructor.lua
index 3396ac7..9c64051 100644
--- a/technic/machines/other/constructor.lua
+++ b/technic/machines/other/constructor.lua
@@ -21,7 +21,7 @@ local function deploy_node(inv, slot_name, pos, node, machine_node)
end
if remove_to then
for i = 1, remove_to do
- inv:remove_item(drops[i])
+ inv:remove_item(slot_name, drops[i])
end
else
minetest.remove_node(pos)
diff --git a/technic/machines/power_monitor.lua b/technic/machines/power_monitor.lua
new file mode 100644
index 0000000..4306693
--- /dev/null
+++ b/technic/machines/power_monitor.lua
@@ -0,0 +1,67 @@
+-- POWER MONITOR
+-- The power monitor can be used to monitor how much power is available on a network,
+-- similarly to the old "slave" switching stations.
+
+local S = technic.getter
+
+minetest.register_craft({
+ output = "technic:power_monitor",
+ recipe = {
+ {"", "", ""},
+ {"", "technic:machine_casing", "default:copper_ingot"},
+ {"technic:lv_cable", "technic:lv_cable", "technic:lv_cable"}
+ }
+})
+
+minetest.register_node("technic:power_monitor",{
+ description = S("Power Monitor"),
+ tiles = {
+ "technic_power_monitor_sides.png",
+ "technic_power_monitor_bottom_back.png",
+ "technic_power_monitor_sides.png",
+ "technic_power_monitor_sides.png",
+ "technic_power_monitor_bottom_back.png",
+ "technic_power_monitor_front.png"
+ },
+ paramtype2 = "facedir",
+ groups = {snappy=2, choppy=2, oddly_breakable_by_hand=2, technic_all_tiers=1, technic_machine=1},
+ connect_sides = {"bottom", "back"},
+ sounds = default.node_sound_wood_defaults(),
+ on_construct = function(pos)
+ local meta = minetest.get_meta(pos)
+ meta:set_string("infotext", S("Power Monitor"))
+ end,
+})
+
+minetest.register_abm({
+ nodenames = {"technic:power_monitor"},
+ label = "Power Monitor",
+ interval = 1,
+ chance = 1,
+ action = function(pos, node, active_object_count, active_object_count_wider)
+ local meta = minetest.get_meta(pos)
+ local network_hash = technic.cables[minetest.hash_node_position(pos)]
+ local network = network_hash and minetest.get_position_from_hash(network_hash)
+ local sw_pos = network and {x=network.x,y=network.y+1,z=network.z}
+ local timeout = 0
+ for tier in pairs(technic.machines) do
+ timeout = math.max(meta:get_int(tier.."_EU_timeout"),timeout)
+ end
+ if timeout > 0 and sw_pos and minetest.get_node(sw_pos).name == "technic:switching_station" then
+ local sw_meta = minetest.get_meta(sw_pos)
+ local supply = sw_meta:get_int("supply")
+ local demand = sw_meta:get_int("demand")
+ meta:set_string("infotext",
+ S("Power Monitor. Supply: @1 Demand: @2",
+ technic.pretty_num(supply), technic.pretty_num(demand)))
+ else
+ meta:set_string("infotext",S("Power Monitor Has No Network"))
+ end
+ end,
+})
+
+for tier in pairs(technic.machines) do
+ -- RE in order to use the "timeout" functions, although it consumes 0 power
+ technic.register_machine(tier, "technic:power_monitor", "RE")
+end
+
diff --git a/technic/machines/register/cables.lua b/technic/machines/register/cables.lua
index 28984c0..165db98 100644
--- a/technic/machines/register/cables.lua
+++ b/technic/machines/register/cables.lua
@@ -11,8 +11,110 @@ function technic.get_cable_tier(name)
return cable_tier[name]
end
-local function clear_networks()
- technic.networks = {}
+local function check_connections(pos)
+ -- Build a table of all machines
+ local machines = {}
+ for tier,list in pairs(technic.machines) do
+ for k,v in pairs(list) do
+ machines[k] = v
+ end
+ end
+ local connections = {}
+ local positions = {
+ {x=pos.x+1, y=pos.y, z=pos.z},
+ {x=pos.x-1, y=pos.y, z=pos.z},
+ {x=pos.x, y=pos.y+1, z=pos.z},
+ {x=pos.x, y=pos.y-1, z=pos.z},
+ {x=pos.x, y=pos.y, z=pos.z+1},
+ {x=pos.x, y=pos.y, z=pos.z-1}}
+ for _,connected_pos in pairs(positions) do
+ local name = minetest.get_node(connected_pos).name
+ if machines[name] or technic.get_cable_tier(name) then
+ table.insert(connections,connected_pos)
+ end
+ end
+ return connections
+end
+
+local function clear_networks(pos)
+ local node = minetest.get_node(pos)
+ local meta = minetest.get_meta(pos)
+ local placed = node.name ~= "air"
+ local positions = check_connections(pos)
+ if #positions < 1 then return end
+ local dead_end = #positions == 1
+ for _,connected_pos in pairs(positions) do
+ local net = technic.cables[minetest.hash_node_position(connected_pos)]
+ if net and technic.networks[net] then
+ if dead_end and placed then
+ -- Dead end placed, add it to the network
+ -- Get the network
+ local network_id = technic.cables[minetest.hash_node_position(positions[1])]
+ if not network_id then
+ -- We're evidently not on a network, nothing to add ourselves to
+ return
+ end
+ local sw_pos = minetest.get_position_from_hash(network_id)
+ sw_pos.y = sw_pos.y + 1
+ local network = technic.networks[network_id]
+ local tier = network.tier
+
+ -- Actually add it to the (cached) network
+ -- This is similar to check_node_subp
+ technic.cables[minetest.hash_node_position(pos)] = network_id
+ pos.visited = 1
+ if technic.is_tier_cable(name, tier) then
+ table.insert(network.all_nodes,pos)
+ elseif technic.machines[tier][node.name] then
+ meta:set_string(tier.."_network",minetest.pos_to_string(sw_pos))
+ if technic.machines[tier][node.name] == technic.producer then
+ table.insert(network.PR_nodes,pos)
+ elseif technic.machines[tier][node.name] == technic.receiver then
+ table.insert(network.RE_nodes,pos)
+ elseif technic.machines[tier][node.name] == technic.producer_receiver then
+ table.insert(network.PR_nodes,pos)
+ table.insert(network.RE_nodes,pos)
+ elseif technic.machines[tier][node.name] == "SPECIAL" and
+ (pos.x ~= sw_pos.x or pos.y ~= sw_pos.y or pos.z ~= sw_pos.z) and
+ from_below then
+ table.insert(network.SP_nodes,pos)
+ elseif technic.machines[tier][node.name] == technic.battery then
+ table.insert(network.BA_nodes,pos)
+ end
+ end
+ elseif dead_end and not placed then
+ -- Dead end removed, remove it from the network
+ -- Get the network
+ local network_id = technic.cables[minetest.hash_node_position(positions[1])]
+ if not network_id then
+ -- We're evidently not on a network, nothing to add ourselves to
+ return
+ end
+ local network = technic.networks[network_id]
+
+ -- Search for and remove machine
+ technic.cables[minetest.hash_node_position(pos)] = nil
+ for tblname,table in pairs(network) do
+ if tblname ~= "tier" then
+ for machinenum,machine in pairs(table) do
+ if machine.x == pos.x
+ and machine.y == pos.y
+ and machine.z == pos.z then
+ table[machinenum] = nil
+ end
+ end
+ end
+ end
+ else
+ -- Not a dead end, so the whole network needs to be recalculated
+ for _,v in pairs(technic.networks[net].all_nodes) do
+ local pos1 = minetest.hash_node_position(v)
+ technic.cables[pos1] = nil
+ end
+ technic.networks[net] = nil
+ end
+ end
+ end
end
function technic.register_cable(tier, size)
@@ -55,7 +157,7 @@ end
local function clear_nets_if_machine(pos, node)
for tier, machine_list in pairs(technic.machines) do
if machine_list[node.name] ~= nil then
- return clear_networks()
+ return clear_networks(pos)
end
end
end
diff --git a/technic/machines/supply_converter.lua b/technic/machines/supply_converter.lua
index 32597de..15c761d 100644
--- a/technic/machines/supply_converter.lua
+++ b/technic/machines/supply_converter.lua
@@ -9,12 +9,62 @@
local S = technic.getter
+local function set_supply_converter_formspec(meta)
+ local formspec = "size[5,2.25]"..
+ "field[0.3,0.5;2,1;power;"..S("Input Power")..";"..meta:get_int("power").."]"
+ -- The names for these toggle buttons are explicit about which
+ -- state they'll switch to, so that multiple presses (arising
+ -- from the ambiguity between lag and a missed press) only make
+ -- the single change that the user expects.
+ if meta:get_int("mesecon_mode") == 0 then
+ formspec = formspec.."button[0,1;5,1;mesecon_mode_1;"..S("Ignoring Mesecon Signal").."]"
+ else
+ formspec = formspec.."button[0,1;5,1;mesecon_mode_0;"..S("Controlled by Mesecon Signal").."]"
+ end
+ if meta:get_int("enabled") == 0 then
+ formspec = formspec.."button[0,1.75;5,1;enable;"..S("%s Disabled"):format(S("Supply Converter")).."]"
+ else
+ formspec = formspec.."button[0,1.75;5,1;disable;"..S("%s Enabled"):format(S("Supply Converter")).."]"
+ end
+ meta:set_string("formspec", formspec)
+end
+
+local supply_converter_receive_fields = function(pos, formname, fields, sender)
+ local meta = minetest.get_meta(pos)
+ local power = nil
+ if fields.power then
+ power = tonumber(fields.power) or 0
+ power = 100 * math.floor(power / 100)
+ power = math.max(power, 0)
+ power = math.min(power, 10000)
+ if power == meta:get_int("power") then power = nil end
+ end
+ if power then meta:set_int("power", power) end
+ if fields.enable then meta:set_int("enabled", 1) end
+ if fields.disable then meta:set_int("enabled", 0) end
+ if fields.mesecon_mode_0 then meta:set_int("mesecon_mode", 0) end
+ if fields.mesecon_mode_1 then meta:set_int("mesecon_mode", 1) end
+ set_supply_converter_formspec(meta)
+end
+
+local mesecons = {
+ effector = {
+ action_on = function(pos, node)
+ minetest.get_meta(pos):set_int("mesecon_effect", 1)
+ end,
+ action_off = function(pos, node)
+ minetest.get_meta(pos):set_int("mesecon_effect", 0)
+ end
+ }
+}
+
local run = function(pos, node)
- local demand = 10000
local remain = 0.9
-- Machine information
local machine_name = S("Supply Converter")
local meta = minetest.get_meta(pos)
+ local enabled = meta:get_int("enabled") ~= 0 and (meta:get_int("mesecon_mode") == 0 or meta:get_int("mesecon_effect") ~= 0)
+ local demand = enabled and meta:get_int("power") or 10000
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}
@@ -53,12 +103,19 @@ minetest.register_node("technic:supply_converter", {
technic_machine=1, technic_all_tiers=1},
connect_sides = {"top", "bottom"},
sounds = default.node_sound_wood_defaults(),
+ on_receive_fields = supply_converter_receive_fields,
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("infotext", S("Supply Converter"))
- meta:set_float("active", false)
+ meta:set_int("power", 10000)
+ meta:set_int("enabled", 1)
+ meta:set_int("mesecon_mode", 0)
+ meta:set_int("mesecon_effect", 0)
+ set_supply_converter_formspec(meta)
end,
+ mesecons = mesecons,
technic_run = run,
+ technic_on_disable = run,
})
minetest.register_craft({
diff --git a/technic/machines/switching_station.lua b/technic/machines/switching_station.lua
index f7ec0b6..f925817 100644
--- a/technic/machines/switching_station.lua
+++ b/technic/machines/switching_station.lua
@@ -32,6 +32,7 @@
-- This way the supplies are separated per network.
technic.networks = {}
+technic.cables = {}
local S = technic.getter
@@ -57,6 +58,11 @@ minetest.register_node("technic:switching_station",{
meta:set_string("infotext", S("Switching Station"))
meta:set_string("active", 1)
end,
+ after_dig_node = function(pos)
+ minetest.forceload_free_block(pos)
+ pos.y = pos.y - 1
+ minetest.forceload_free_block(pos)
+ end,
})
--------------------------------------------------
@@ -64,7 +70,8 @@ minetest.register_node("technic:switching_station",{
--------------------------------------------------
-- Add a wire node to the LV/MV/HV network
-local add_new_cable_node = function(nodes, pos)
+local add_new_cable_node = function(nodes, pos, network_id)
+ technic.cables[minetest.hash_node_position(pos)] = network_id
-- Ignore if the node has already been added
for i = 1, #nodes do
if pos.x == nodes[i].x and
@@ -78,31 +85,31 @@ local add_new_cable_node = function(nodes, pos)
end
-- Generic function to add found connected nodes to the right classification array
-local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos, from_below)
+local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, pos, machines, tier, sw_pos, from_below, network_id)
technic.get_or_load_node(pos)
local meta = minetest.get_meta(pos)
local name = minetest.get_node(pos).name
if technic.is_tier_cable(name, tier) then
- add_new_cable_node(all_nodes, pos)
+ add_new_cable_node(all_nodes, pos,network_id)
elseif machines[name] then
--dprint(name.." is a "..machines[name])
+ meta:set_string(tier.."_network",minetest.pos_to_string(sw_pos))
if machines[name] == technic.producer then
- add_new_cable_node(PR_nodes, pos)
+ add_new_cable_node(PR_nodes, pos, network_id)
elseif machines[name] == technic.receiver then
- add_new_cable_node(RE_nodes, pos)
+ add_new_cable_node(RE_nodes, pos, network_id)
elseif machines[name] == technic.producer_receiver then
- add_new_cable_node(PR_nodes, pos)
- add_new_cable_node(RE_nodes, pos)
+ add_new_cable_node(PR_nodes, pos, network_id)
+ add_new_cable_node(RE_nodes, pos, network_id)
elseif machines[name] == "SPECIAL" and
(pos.x ~= sw_pos.x or pos.y ~= sw_pos.y or pos.z ~= sw_pos.z) and
from_below then
-- Another switching station -> disable it
- add_new_cable_node(SP_nodes, pos)
+ add_new_cable_node(SP_nodes, pos, network_id)
meta:set_int("active", 0)
- meta:set_string("active_pos", minetest.serialize(sw_pos))
elseif machines[name] == technic.battery then
- add_new_cable_node(BA_nodes, pos)
+ add_new_cable_node(BA_nodes, pos, network_id)
end
meta:set_int(tier.."_EU_timeout", 2) -- Touch node
@@ -110,7 +117,7 @@ local check_node_subp = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nod
end
-- Traverse a network given a list of machines and a cable type name
-local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, i, machines, tier, sw_pos)
+local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, i, machines, tier, sw_pos, network_id)
local pos = all_nodes[i]
local positions = {
{x=pos.x+1, y=pos.y, z=pos.z},
@@ -121,7 +128,7 @@ local traverse_network = function(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_no
{x=pos.x, y=pos.y, z=pos.z-1}}
--print("ON")
for i, cur_pos in pairs(positions) do
- check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, cur_pos, machines, tier, sw_pos, i == 3)
+ check_node_subp(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes, cur_pos, machines, tier, sw_pos, i == 3, network_id)
end
end
@@ -153,11 +160,11 @@ local get_network = function(sw_pos, pos1, tier)
local all_nodes = {pos1}
repeat
traverse_network(PR_nodes, RE_nodes, BA_nodes, SP_nodes, all_nodes,
- i, technic.machines[tier], tier, sw_pos)
+ i, technic.machines[tier], tier, sw_pos, minetest.hash_node_position(pos1))
i = i + 1
until all_nodes[i] == nil
technic.networks[minetest.hash_node_position(pos1)] = {tier = tier, PR_nodes = PR_nodes,
- RE_nodes = RE_nodes, BA_nodes = BA_nodes, SP_nodes = SP_nodes}
+ RE_nodes = RE_nodes, BA_nodes = BA_nodes, SP_nodes = SP_nodes, all_nodes = all_nodes}
return PR_nodes, BA_nodes, RE_nodes
end
@@ -183,27 +190,30 @@ minetest.register_abm({
local BA_nodes
local RE_nodes
local machine_name = S("Switching Station")
+
+ -- Which kind of network are we on:
+ pos1 = {x=pos.x, y=pos.y-1, z=pos.z}
+ --Disable if necessary
if meta:get_int("active") ~= 1 then
- meta:set_int("active", 1)
- local active_pos = minetest.deserialize(meta:get_string("active_pos"))
- if active_pos then
- local meta1 = minetest.get_meta(active_pos)
- meta:set_string("infotext", S("%s (Slave)"):format(meta1:get_string("infotext")))
- end
+ minetest.forceload_free_block(pos)
+ minetest.forceload_free_block(pos1)
+ meta:set_string("infotext",S("%s Already Present"):format(machine_name))
return
end
-
- -- Which kind of network are we on:
- pos1 = {x=pos.x, y=pos.y-1, z=pos.z}
local name = minetest.get_node(pos1).name
local tier = technic.get_cable_tier(name)
if tier then
+ -- Forceload switching station
+ minetest.forceload_block(pos)
+ minetest.forceload_block(pos1)
PR_nodes, BA_nodes, RE_nodes = get_network(pos, pos1, tier)
else
--dprint("Not connected to a network")
meta:set_string("infotext", S("%s Has No Network"):format(machine_name))
+ minetest.forceload_free_block(pos)
+ minetest.forceload_free_block(pos1)
return
end
@@ -291,6 +301,10 @@ minetest.register_abm({
S("@1. Supply: @2 Demand: @3",
machine_name, technic.pretty_num(PR_eu_supply), technic.pretty_num(RE_eu_demand)))
+ -- Data that will be used by the power monitor
+ meta:set_int("supply",PR_eu_supply)
+ meta:set_int("demand",RE_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)
@@ -352,6 +366,7 @@ minetest.register_abm({
meta1 = minetest.get_meta(pos1)
meta1:set_int(eu_input_str, 0)
end
+
end,
})
@@ -374,6 +389,7 @@ minetest.register_abm({
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
+ local meta = minetest.get_meta(pos)
for tier, machines in pairs(technic.machines) do
if machines[node.name] and switching_station_timeout_count(pos, tier) then
local nodedef = minetest.registered_nodes[node.name]
@@ -392,6 +408,23 @@ minetest.register_abm({
end,
})
+--Re-enable disabled switching station if necessary, similar to the timeout above
+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.get_meta(pos)
+ local pos1 = {x=pos.x,y=pos.y-1,z=pos.z}
+ local tier = technic.get_cable_tier(minetest.get_node(pos1).name)
+ if not tier then return end
+ if switching_station_timeout_count(pos, tier) then
+ local meta = minetest.get_meta(pos)
+ meta:set_int("active",1)
+ end
+ end,
+})
+
for tier, machines in pairs(technic.machines) do
-- SPECIAL will not be traversed
technic.register_machine(tier, "technic:switching_station", "SPECIAL")