From 835138c0f1122dd10c46b378792dfe8ffe5eae30 Mon Sep 17 00:00:00 2001 From: Joachim Stolberg Date: Sat, 18 Sep 2021 13:12:27 +0200 Subject: [PATCH] built on 18/09/2021 13:12:27 --- README.md | 8 +++ networks/README.md | 3 + networks/hidden.lua | 2 +- networks/init.lua | 2 +- signs_bot/changer.lua | 24 +++++++ signs_bot/cmd_flowers.lua | 4 ++ techage/README.md | 6 +- techage/basic_machines/concentrator.lua | 4 +- techage/basic_machines/pusher.lua | 2 +- techage/basic_machines/ta4_chest.lua | 2 +- techage/basic_machines/ta4_injector.lua | 2 +- techage/basis/command.lua | 25 +++++++ techage/energy_storage/heatexchanger2.lua | 3 +- techage/init.lua | 8 +-- techage/logic/detector.lua | 4 +- techage/logic/node_detector.lua | 17 ++--- techage/power/electric_cable.lua | 68 +++++++++++++++--- techage/power/formspecs.lua | 2 +- techage/power/power_terminal2.lua | 19 +++++ techage/textures/techage_cable_palette.png | Bin 0 -> 134 bytes .../textures/techage_electric_cable_end.png | Bin 248 -> 123 bytes 21 files changed, 171 insertions(+), 34 deletions(-) create mode 100644 techage/textures/techage_cable_palette.png diff --git a/README.md b/README.md index 0238e0d..910a166 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,14 @@ Updated Mods: - minecart (bugfix) +#### 2021-09-18 + +Updated Mods: +- techage (see readme) +- signs_bot (see readme) +- networks (see readme) + + #### 2021-09-03 Updated Mods: diff --git a/networks/README.md b/networks/README.md index 2ab1d24..f9dd8b3 100644 --- a/networks/README.md +++ b/networks/README.md @@ -122,3 +122,6 @@ Required: tubelib2 **2021-07-23 V0.09** - bug fixes and improvements + +**2021-09-18 V0.10** +- Add support for colored cables (PR #1 by Thomas--S) diff --git a/networks/hidden.lua b/networks/hidden.lua index 4e4a3d4..e7549b1 100644 --- a/networks/hidden.lua +++ b/networks/hidden.lua @@ -118,7 +118,7 @@ function networks.open_node(pos, node, placer) else param2 = M(pos):get_int("netw_param2_copy") end - minetest.swap_node(pos, {name = name, param2 = param2 % 32}) + minetest.swap_node(pos, {name = name, param2 = param2 % 32 + M(pos):get_int("netw_color_param2")}) local meta = M(pos) meta:set_string("netw_name", "") local inv = placer:get_inventory() diff --git a/networks/init.lua b/networks/init.lua index 67db832..2f30edb 100644 --- a/networks/init.lua +++ b/networks/init.lua @@ -13,7 +13,7 @@ networks = {} -- Version for compatibility checks, see readme.md/history -networks.version = 0.09 +networks.version = 0.10 if not minetest.global_exists("tubelib2") or tubelib2.version < 2.1 then minetest.log("error", "[networks] Networks requires tubelib2 version 2.1 or newer!") diff --git a/signs_bot/changer.lua b/signs_bot/changer.lua index 6baa9c8..543d13c 100644 --- a/signs_bot/changer.lua +++ b/signs_bot/changer.lua @@ -19,6 +19,7 @@ local M = minetest.get_meta local S = signs_bot.S local lib = signs_bot.lib +local INFO = [[Set the node state: command = 'set', payload = 1..4]] local NodeIdx = { ["signs_bot:changer1"] = "1", @@ -134,6 +135,10 @@ for idx = 1,4 do meta:set_string("formspec", formspec) local node = minetest.get_node(pos) meta:set_int("param2", (node.param2 + 2) % 4) + if minetest.get_modpath("techage") then + techage.logic.after_place_node(pos, placer, node.name, S("Bot Control Unit")) + techage.logic.infotext(meta, S("Bot Control Unit")) + end end, signs_bot_get_signal = signs_bot_get_signal, @@ -182,3 +187,22 @@ if minetest.get_modpath("doc") then }, }) end + +if minetest.get_modpath("techage") then + techage.register_node({"signs_bot:changer1", "signs_bot:changer2", "signs_bot:changer3", "signs_bot:changer4"}, { + on_recv_message = function(pos, src, topic, payload) + if topic == "set" then + local idx = tonumber(payload) or 1 + if idx >= 1 and idx <= 4 then + local node = techage.get_node_lvm(pos) + signs_bot_on_signal(pos, node, idx) + return true + end + elseif topic == "info" then + return INFO + else + return "unsupported" + end + end, + }) +end diff --git a/signs_bot/cmd_flowers.lua b/signs_bot/cmd_flowers.lua index 01fa355..d2e30d8 100644 --- a/signs_bot/cmd_flowers.lua +++ b/signs_bot/cmd_flowers.lua @@ -30,6 +30,10 @@ function signs_bot.register_flower(name) end end +signs_bot.register_flower("default:bush_stem") +signs_bot.register_flower("default:acacia_bush_stem") +signs_bot.register_flower("default:pine_bush_stem") + minetest.after(1, function() for _,def in pairs(minetest.registered_decorations) do local name = def.decoration diff --git a/techage/README.md b/techage/README.md index 9231472..74d0888 100644 --- a/techage/README.md +++ b/techage/README.md @@ -1,4 +1,4 @@ -# Tech Age [techage] (Minetest 5.0+) +# Tech Age [techage] (Minetest 5.3+) Tech Age, a mod to go through 4 tech ages in search of wealth and power. @@ -81,6 +81,10 @@ Available worlds will be converted to 'lsqlite3', but there is no way back, so: ### History +**2021-09-18 V1.02** +- TA4 Chest: Fix items disappearing (PR #64 by Thomas--S) +- Add support for colored cables (PR #63 by Thomas--S) + **2021-08-16 V1.01** - Allow singleplayer to place lava on y>0. - Logic block: allow to use output numbers for the expression diff --git a/techage/basic_machines/concentrator.lua b/techage/basic_machines/concentrator.lua index 2d5217c..eed6f43 100644 --- a/techage/basic_machines/concentrator.lua +++ b/techage/basic_machines/concentrator.lua @@ -62,7 +62,7 @@ local names = networks.register_junction("techage:concentrator", 2/8, Boxes, Tub techage.register_node(names, { on_push_item = function(pos, in_dir, stack) local push_dir = M(pos):get_int("push_dir") - return techage.push_items(pos, push_dir, stack) + return techage.safe_push_items(pos, push_dir, stack) end, is_pusher = true, -- is a pulling/pushing node }) @@ -101,7 +101,7 @@ names = networks.register_junction("techage:ta4_concentrator", 2/8, Boxes, Tube, techage.register_node(names, { on_push_item = function(pos, in_dir, stack) local push_dir = M(pos):get_int("push_dir") - return techage.push_items(pos, push_dir, stack) + return techage.safe_push_items(pos, push_dir, stack) end, is_pusher = true, -- is a pulling/pushing node }) diff --git a/techage/basic_machines/pusher.lua b/techage/basic_machines/pusher.lua index 12f177d..9da7d43 100644 --- a/techage/basic_machines/pusher.lua +++ b/techage/basic_machines/pusher.lua @@ -234,7 +234,7 @@ tiles.act = { local tubing = { -- push item through the pusher in opposit direction on_push_item = function(pos, in_dir, stack) - return in_dir == M(pos):get_int("pull_dir") and techage.push_items(pos, in_dir, stack) + return in_dir == M(pos):get_int("pull_dir") and techage.safe_push_items(pos, in_dir, stack) end, is_pusher = true, -- is a pulling/pushing node diff --git a/techage/basic_machines/ta4_chest.lua b/techage/basic_machines/ta4_chest.lua index 6ae2d34..725035d 100644 --- a/techage/basic_machines/ta4_chest.lua +++ b/techage/basic_machines/ta4_chest.lua @@ -170,7 +170,7 @@ local function take_from_chest(pos, idx, output_stack, max_total_count, keep_ass local nvm_stack = get_stack(nvm, idx) output_stack = output_stack or ItemStack() local assignment_count = keep_assignment and M(pos):get_int("assignment") == 1 and 1 or 0 - local count = math.min(nvm_stack.count - assignment_count, max_stacksize(nvm_stack.name)) + local count = math.min(nvm_stack.count - assignment_count, max_stacksize(nvm_stack.name) - output_stack:get_count()) if max_total_count then count = math.min(count, max_total_count - output_stack:get_count()) end diff --git a/techage/basic_machines/ta4_injector.lua b/techage/basic_machines/ta4_injector.lua index 86cca3d..919926d 100644 --- a/techage/basic_machines/ta4_injector.lua +++ b/techage/basic_machines/ta4_injector.lua @@ -235,7 +235,7 @@ tiles.act = { local tubing = { -- push item through the injector in opposit direction on_push_item = function(pos, in_dir, stack) - return in_dir == M(pos):get_int("pull_dir") and techage.push_items(pos, in_dir, stack) + return in_dir == M(pos):get_int("pull_dir") and techage.safe_push_items(pos, in_dir, stack) end, is_pusher = true, -- is a pulling/pushing node diff --git a/techage/basis/command.lua b/techage/basis/command.lua index 435818b..301cf3b 100644 --- a/techage/basis/command.lua +++ b/techage/basis/command.lua @@ -405,6 +405,31 @@ function techage.push_items(pos, out_dir, stack, idx) return false end +-- Check for recursion and too long distances +local start_pos +function techage.safe_push_items(pos, out_dir, stack, idx) + local mem = techage.get_mem(pos) + if not mem.pushing then + if not start_pos then + start_pos = pos + mem.pushing = true + local res = techage.push_items(pos, out_dir, stack, idx) + mem.pushing = nil + start_pos = nil + return res + else + local npos, in_dir, name = get_dest_node(pos, out_dir) + if vector.distance(start_pos, npos) < (Tube.max_tube_length or 100) then + mem.pushing = true + local res = techage.push_items(pos, out_dir, stack, idx) + mem.pushing = nil + return res + end + end + end + return false +end + function techage.unpull_items(pos, out_dir, stack) local npos, in_dir, name = get_dest_node(pos, out_dir) if npos and NodeDef[name] and NodeDef[name].on_unpull_item then diff --git a/techage/energy_storage/heatexchanger2.lua b/techage/energy_storage/heatexchanger2.lua index 967e26a..591acc8 100644 --- a/techage/energy_storage/heatexchanger2.lua +++ b/techage/energy_storage/heatexchanger2.lua @@ -283,7 +283,8 @@ techage.register_node({"techage:heatexchanger2"}, { return "stopped" end elseif topic == "delivered" then - return -math.max(nvm.needed or 0, 0) + local data = power.get_network_data(pos, Cable, DOWN) + return data.consumed - data.provided elseif topic == "load" then return techage.power.percent(nvm.capa_max, nvm.capa) elseif topic == "on" then diff --git a/techage/init.lua b/techage/init.lua index 53e0ca4..f6414b5 100644 --- a/techage/init.lua +++ b/techage/init.lua @@ -13,7 +13,7 @@ techage = {} -- Version for compatibility checks, see readme.md/history -techage.version = 1.01 +techage.version = 1.02 if minetest.global_exists("tubelib") then minetest.log("error", "[techage] Techage can't be used together with the mod tubelib!") @@ -36,8 +36,8 @@ elseif minetest.global_exists("lcdlib") and lcdlib.version < 1.0 then elseif minetest.global_exists("safer_lua") and safer_lua.version < 1.0 then minetest.log("error", "[techage] Techage requires safer_lua version 1.0 or newer!") return -elseif minetest.global_exists("networks") and networks.version < 0.08 then - minetest.log("error", "[techage] Techage requires networks version 0.08 or newer!") +elseif minetest.global_exists("networks") and networks.version < 0.10 then + minetest.log("error", "[techage] Techage requires networks version 0.10 or newer!") return end @@ -342,9 +342,9 @@ dofile(MP.."/items/petroleum.lua") dofile(MP.."/items/bauxit.lua") dofile(MP.."/items/silicon.lua") dofile(MP.."/items/steelmat.lua") +dofile(MP.."/items/aluminium.lua") dofile(MP.."/items/powder.lua") dofile(MP.."/items/epoxy.lua") -dofile(MP.."/items/aluminium.lua") dofile(MP.."/items/plastic.lua") dofile(MP.."/items/hydrogen.lua") dofile(MP.."/items/electronic.lua") diff --git a/techage/logic/detector.lua b/techage/logic/detector.lua index ec21a84..d9b9ab0 100644 --- a/techage/logic/detector.lua +++ b/techage/logic/detector.lua @@ -203,7 +203,7 @@ minetest.register_craft({ techage.register_node({"techage:ta3_detector_off", "techage:ta3_detector_on"}, { on_push_item = function(pos, in_dir, stack) - if techage.push_items(pos, in_dir, stack) then + if techage.safe_push_items(pos, in_dir, stack) then switch_on(pos) return true end @@ -214,7 +214,7 @@ techage.register_node({"techage:ta3_detector_off", "techage:ta3_detector_on"}, { techage.register_node({"techage:ta4_detector_off", "techage:ta4_detector_on"}, { on_push_item = function(pos, in_dir, stack) - if techage.push_items(pos, in_dir, stack) then + if techage.safe_push_items(pos, in_dir, stack) then switch_on(pos) local nvm = techage.get_nvm(pos) nvm.counter = (nvm.counter or 0) + stack:get_count() diff --git a/techage/logic/node_detector.lua b/techage/logic/node_detector.lua index deb1d26..eed6d7f 100644 --- a/techage/logic/node_detector.lua +++ b/techage/logic/node_detector.lua @@ -60,20 +60,21 @@ local function any_node_changed(pos) nvm.num = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"air"}) return false end - local num = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"air"}) + local num1 = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"air"}) + local num2 = #minetest.find_nodes_in_area(nvm.pos1, nvm.pos2, {"ignore"}) - if nvm.num ~= num then - if nvm.mode == 1 and num < nvm.num then - nvm.num = num + if num2 == 0 and nvm.num ~= num1 then + if nvm.mode == 1 and num1 < nvm.num then + nvm.num = num1 return true - elseif nvm.mode == 2 and num > nvm.num then - nvm.num = num + elseif nvm.mode == 2 and num1 > nvm.num then + nvm.num = num1 return true elseif nvm.mode == 3 then - nvm.num = num + nvm.num = num1 return true end - nvm.num = num + nvm.num = num1 end return false end diff --git a/techage/power/electric_cable.lua b/techage/power/electric_cable.lua index 5e87dca..05cccb5 100644 --- a/techage/power/electric_cable.lua +++ b/techage/power/electric_cable.lua @@ -32,7 +32,9 @@ local Cable = tubelib2.Tube:new({ "techage:power_pole2", "techage:powerswitch_box", "techage:powerswitch_box_on"}, secondary_node_names = {}, after_place_tube = function(pos, param2, tube_type, num_tubes) - local name = minetest.get_node(pos).name + local node = minetest.get_node(pos) + local name = node.name + local color_param2 = math.floor(node.param2 / 32) * 32 if name == "techage:powerswitch_box" or name == "techage:powerswitch_box_on" or name == "techage:powerswitch_box_off" then minetest.swap_node(pos, {name = name, param2 = param2 % 32}) elseif name == "techage:power_line" or name == "techage:power_lineS" or name == "techage:power_lineA" then @@ -40,9 +42,10 @@ local Cable = tubelib2.Tube:new({ elseif name == "techage:power_pole2" then -- nothing elseif not networks.hidden_name(pos) then - minetest.swap_node(pos, {name = "techage:electric_cable"..tube_type, param2 = param2 % 32}) + minetest.swap_node(pos, {name = "techage:electric_cable"..tube_type, param2 = param2 % 32 + color_param2}) end M(pos):set_int("netw_param2", param2) + M(pos):set_int("netw_color_param2", color_param2) end, }) @@ -55,6 +58,15 @@ Cable:register_on_tube_update2(function(pos, outdir, tlib2, node) power.update_network(pos, outdir, tlib2, node) end) +local preserve_metadata = function(pos, oldnode, oldmeta, drops) + for _,drop in ipairs(drops) do + local meta = drop:get_meta() + if meta:get_int("palette_index") == 0 then + meta:set_string("palette_index", "") + end + end +end + minetest.register_node("techage:electric_cableS", { description = S("TA Electric Cable"), tiles = { @@ -63,8 +75,16 @@ minetest.register_node("techage:electric_cableS", { "techage_electric_cable.png", "techage_electric_cable.png", "techage_electric_cable.png", - "techage_electric_cable_end.png", - "techage_electric_cable_end.png", + "techage_electric_cable.png", + "techage_electric_cable.png", + }, + overlay_tiles = { + "", + "", + "", + "", + { name = "techage_electric_cable_end.png", color = "white" }, + { name = "techage_electric_cable_end.png", color = "white" }, }, after_place_node = function(pos, placer, itemstack, pointed_thing) @@ -79,7 +99,8 @@ minetest.register_node("techage:electric_cableS", { Cable:after_dig_tube(pos, oldnode, oldmetadata) end, - paramtype2 = "facedir", -- important! + paramtype2 = "colorfacedir", -- important! + palette = "techage_cable_palette.png", drawtype = "nodebox", node_box = { type = "fixed", @@ -94,6 +115,7 @@ minetest.register_node("techage:electric_cableS", { is_ground_content = false, groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, techage_trowel = 1}, sounds = default.node_sound_defaults(), + preserve_metadata = preserve_metadata, }) minetest.register_node("techage:electric_cableA", { @@ -101,18 +123,27 @@ minetest.register_node("techage:electric_cableA", { tiles = { -- up, down, right, left, back, front "techage_electric_cable.png", - "techage_electric_cable_end.png", "techage_electric_cable.png", "techage_electric_cable.png", "techage_electric_cable.png", - "techage_electric_cable_end.png", + "techage_electric_cable.png", + "techage_electric_cable.png", + }, + overlay_tiles = { + "", + { name = "techage_electric_cable_end.png", color = "white" }, + "", + "", + "", + { name = "techage_electric_cable_end.png", color = "white" }, }, after_dig_node = function(pos, oldnode, oldmetadata, digger) Cable:after_dig_tube(pos, oldnode, oldmetadata) end, - paramtype2 = "facedir", -- important! + paramtype2 = "colorfacedir", -- important! + palette = "techage_cable_palette.png", drawtype = "nodebox", node_box = { type = "fixed", @@ -129,7 +160,12 @@ minetest.register_node("techage:electric_cableA", { groups = {snappy = 2, choppy = 2, oddly_breakable_by_hand = 3, techage_trowel = 1, not_in_creative_inventory = 1}, sounds = default.node_sound_defaults(), - drop = "techage:electric_cableS", + drop = { + items = { + { items = { "techage:electric_cableS" }, inherit_color = true }, + } + }, + preserve_metadata = preserve_metadata, }) minetest.register_craft({ @@ -142,4 +178,16 @@ minetest.register_craft({ }) techage.ElectricCable = Cable -techage.ELE1_MAX_CABLE_LENGHT = ELE1_MAX_CABLE_LENGHT +techage.ELE1_MAX_CABLE_LENGTH = ELE1_MAX_CABLE_LENGTH + + +for idx, color in ipairs({ "white", "grey", "black", "brown", "yellow", "red", "dark_green", "blue" }) do + minetest.register_craft({ + output = idx == 1 and "techage:electric_cableS 8" or minetest.itemstring_with_palette("techage:electric_cableS 8", (idx-1)*32), + recipe = { + { "techage:electric_cableS", "techage:electric_cableS", "techage:electric_cableS", }, + { "techage:electric_cableS", "dye:"..color, "techage:electric_cableS", }, + { "techage:electric_cableS", "techage:electric_cableS", "techage:electric_cableS", }, + } + }) +end \ No newline at end of file diff --git a/techage/power/formspecs.lua b/techage/power/formspecs.lua index c014ab5..81fb87b 100644 --- a/techage/power/formspecs.lua +++ b/techage/power/formspecs.lua @@ -38,7 +38,7 @@ local function round(val) end local function calc_percent(max_val, curr_val) - return math.min(((curr_val or 0) * 100) / (max_val or 1.0), 100) + return round(math.min(((curr_val or 0) * 100) / (max_val or 1.0), 100)) end ------------------------------------------------------------------------------- diff --git a/techage/power/power_terminal2.lua b/techage/power/power_terminal2.lua index e1513b2..9cb8dd4 100644 --- a/techage/power/power_terminal2.lua +++ b/techage/power/power_terminal2.lua @@ -30,6 +30,7 @@ help . . . print this text cls . . . . . clear screen gen . . . . print all generators sto . . . . . print all storage systems +con . . . . . print main consumers ]]) local function row(num, label, data) @@ -137,6 +138,22 @@ local function storages(pos) return table.concat(tbl, "\n") end +local function consumers(pos) + local tbl = {} + local outdir = M(pos):get_int("outdir") + local netw = networks.get_network_table(pos, Cable, outdir) or {} + for _,item in ipairs(netw.con or {}) do + local number = techage.get_node_number(item.pos) + if number then + local name = techage.get_node_lvm(item.pos).name + name = (minetest.registered_nodes[name] or {}).description or "unknown" + tbl[#tbl + 1] = name .. " (" .. number .. ")" + end + end + table.sort(tbl) + return table.concat(tbl, "\n") +end + local function output(pos, command, text) local meta = M(pos) text = meta:get_string("output") .. "\n$ " .. command .. "\n" .. (text or "") @@ -160,6 +177,8 @@ local function command(pos, nvm, command) output(pos, command, generators(pos)) elseif cmd == "sto" then output(pos, command, storages(pos)) + elseif cmd == "con" then + output(pos, command, consumers(pos)) elseif command ~= "" then output(pos, command, "") end diff --git a/techage/textures/techage_cable_palette.png b/techage/textures/techage_cable_palette.png new file mode 100644 index 0000000000000000000000000000000000000000..da528b5df7b4bf8a54c27dfb09c078df805e0ae7 GIT binary patch literal 134 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!73?$#)eFPGa2=EDUU2AP^YHHe&Zt2jV=v2J) z-W0*|^78-x|4&IFMGa!f`!Wqn(M(LYbFKfX7k8!C=Y)hJzffOf1a863&cG e51CjC*ci5l%O1>m^KunX6N9I#pUXO@geCw1$R%$8 literal 0 HcmV?d00001 diff --git a/techage/textures/techage_electric_cable_end.png b/techage/textures/techage_electric_cable_end.png index 97dd46de0d455694b89010577a25a4cd1ebfee01..0b021e101960c2276c4cd4dea724c32c4194fbc7 100644 GIT binary patch delta 93 zcmeytSUo`{oIk)P#MQmPXTkhwXX|ye3$@=p6!km3%aehDfw3gWFPOpM*^M+HN6OR1 wF+}5ha)LysLx6yzopr04tv$r~m)} delta 219 zcmV<103`o=_yLe4e*|YiO+f$vv5yP zyVTRipr4k_e=I9;EAHVHz=RrI00001bW%=J06^y0W&i*HbV)=(R4C7tkaCpl&0|kg) zMIN$LKp~`pGC~A&oEf|w`}Lfjh#AqUY*DhPPW?Za*iOoA_HjbHQ;e59`*V&t^ae&? V75yJmATj^|002ovPDHLkV1lf9R(}8h