1
0
mirror of https://github.com/mt-mods/pipeworks.git synced 2025-07-17 15:50:30 +02:00

28 Commits

Author SHA1 Message Date
2f9f9a7b54 Merge remote-tracking branch 'upstream/master' 2023-11-23 00:15:18 +01:00
02322855d5 Merge remote-tracking branch 'upstream/master' 2023-06-07 22:19:10 +02:00
b11cb37123 Merge remote-tracking branch 'upstream/master' 2022-08-26 15:22:54 +02:00
503c1190ed Merge remote-tracking branch 'upstream/master' 2022-06-25 16:52:37 +02:00
5bba517b03 Merge remote-tracking branch 'upstream/master' 2022-05-27 18:46:28 +02:00
66070dd801 Merge remote-tracking branch 'upstream/master' 2022-03-06 16:37:56 +01:00
7ee74133e1 Merge remote-tracking branch 'upstream/master' 2021-06-20 17:21:30 +02:00
c01bd7b888 Merge remote-tracking branch 'upstream/master' 2021-05-09 21:42:46 +02:00
e2fdcc4fb2 Merge remote-tracking branch 'upstream/master' 2021-04-08 13:32:05 +02:00
e4db1e885e Merge remote-tracking branch 'upstream/master' 2021-04-04 21:02:57 +02:00
f7839444cd Merge remote-tracking branch 'upstream/master' 2021-03-25 21:57:03 +01:00
93f5fb3d87 Merge remote-tracking branch 'upstream/master' 2021-03-12 12:36:16 +01:00
a535bebd2e Merge remote-tracking branch 'upstream/master' 2021-02-13 14:18:53 +01:00
be2776fc46 Merge remote-tracking branch 'upstream/master' 2021-02-07 13:13:20 +01:00
ee03959a65 Merge remote-tracking branch 'upstream/master' 2020-12-20 15:26:00 +01:00
4dd30df37a Merge remote-tracking branch 'upstream/master' 2020-10-29 22:16:20 +01:00
946da11206 Merge remote-tracking branch 'upstream/master' 2020-10-18 02:13:58 +02:00
77c8026400 Merge remote-tracking branch 'upstream/master' 2020-09-26 11:40:25 +02:00
70b521c721 Merge remote-tracking branch 'upstream/master' 2020-09-11 20:50:17 +02:00
6d795b7d34 Merge remote-tracking branch 'upstream/master' 2020-08-11 20:30:19 +02:00
92249b7941 Merge remote-tracking branch 'upstream/master' 2020-07-31 22:18:16 +02:00
e04fb691ad Merge remote-tracking branch 'upstream/master' 2020-07-19 22:41:58 +02:00
ac80224371 Merge remote-tracking branch 'upstream/master' 2020-07-17 22:41:46 +02:00
34262ed8d5 Merge remote-tracking branch 'upstream/master' into nalc-1.2-dev 2020-06-14 21:11:09 +02:00
5cfe8d893f Merge branch 'master' of yunohost.local:mtcontrib/pipeworks into nalc-1.2-dev 2020-03-25 23:00:57 +01:00
975e20f704 Merge branch 'master' of yunohost.local:mtcontrib/pipeworks into nalc-1.2-dev 2019-12-22 14:33:13 +01:00
2693e2ecbb Merge branch 'master' into nalc-1.2 2019-05-04 19:56:03 +02:00
c93df73a5c Rend les items du groupe limitcraft non craftable par l'autocrafter 2019-03-02 19:29:26 +01:00
17 changed files with 427 additions and 819 deletions

View File

@ -1,10 +1,13 @@
name: luacheck name: luacheck
on: [push, pull_request] on: [push, pull_request]
jobs: jobs:
luacheck: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout - uses: actions/checkout@master
uses: actions/checkout@master - name: apt
- name: Luacheck run: sudo apt-get install -y luarocks
uses: lunarmodules/luacheck@master - name: luacheck install
run: luarocks install --local luacheck
- name: luacheck run
run: $HOME/.luarocks/bin/luacheck ./

View File

@ -1,14 +1,11 @@
local S = minetest.get_translator("pipeworks") local S = minetest.get_translator("pipeworks")
-- cache some recipe data to avoid calling the slow function local autocrafterCache = {} -- caches some recipe data to avoid to call the slow function minetest.get_craft_result() every second
-- minetest.get_craft_result() every second
local autocrafterCache = {}
local craft_time = 1 local craft_time = 1
local function count_index(invlist) local function count_index(invlist)
local index = {} local index = {}
for _, stack in pairs(invlist) do for _, stack in pairs(invlist) do
stack = ItemStack(stack)
if not stack:is_empty() then if not stack:is_empty() then
local stack_name = stack:get_name() local stack_name = stack:get_name()
index[stack_name] = (index[stack_name] or 0) + stack:get_count() index[stack_name] = (index[stack_name] or 0) + stack:get_count()
@ -24,152 +21,41 @@ local function get_item_info(stack)
return description, name return description, name
end end
-- Get best matching recipe for what user has put in crafting grid.
-- This function does not consider crafting method (mix vs craft)
local function get_matching_craft(output_name, example_recipe)
local recipes = minetest.get_all_craft_recipes(output_name)
if not recipes then
return example_recipe
end
if 1 == #recipes then
return recipes[1].items
end
local index_example = count_index(example_recipe)
local best_score = 0
local index_recipe, best_index, score, group
for i = 1, #recipes do
score = 0
index_recipe = count_index(recipes[i].items)
for recipe_item_name, _ in pairs(index_recipe) do
if index_example[recipe_item_name] then
score = score + 1
elseif recipe_item_name:sub(1, 6) == "group:" then
group = recipe_item_name:sub(7)
for example_item_name, _ in pairs(index_example) do
if minetest.get_item_group(example_item_name, group) > 0 then
score = score + 1
break
end
end
end
end
if best_score < score then
best_index = i
end
end
return best_index and recipes[best_index].items or example_recipe
end
local function get_craft(pos, inventory, hash) local function get_craft(pos, inventory, hash)
local hash = hash or minetest.hash_node_position(pos) local hash = hash or minetest.hash_node_position(pos)
local craft = autocrafterCache[hash] local craft = autocrafterCache[hash]
if craft then return craft end if not craft then
local recipe = inventory:get_list("recipe")
local example_recipe = inventory:get_list("recipe") local output, decremented_input = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
local output, decremented_input = minetest.get_craft_result({ craft = {recipe = recipe, consumption=count_index(recipe), output = output, decremented_input = decremented_input}
method = "normal", width = 3, items = example_recipe autocrafterCache[hash] = craft
})
local recipe = example_recipe
if output and not output.item:is_empty() then
recipe = get_matching_craft(output.item:get_name(), example_recipe)
end end
craft = {
recipe = recipe,
consumption = count_index(recipe),
output = output,
decremented_input = decremented_input.items
}
autocrafterCache[hash] = craft
return craft return craft
end end
-- From a consumption table with groups and an inventory index, build local function autocraft(inventory, craft)
-- a consumption table without groups if not craft then return false end
local function calculate_consumption(inv_index, consumption_with_groups) -- check if we have enough material available
inv_index = table.copy(inv_index) local inv_index = count_index(inventory:get_list("src"))
consumption_with_groups = table.copy(consumption_with_groups) for itemname, number in pairs(craft.consumption) do
if (not inv_index[itemname]) or inv_index[itemname] < number then return false end
local consumption = {}
local groups = {}
-- First consume all non-group requirements
-- This is done to avoid consuming a non-group item which is also
-- in a group
for key, count in pairs(consumption_with_groups) do
if key:sub(1, 6) == "group:" then
groups[#groups + 1] = key:sub(7, #key)
else
if not inv_index[key] or inv_index[key] < count then
return nil
end
consumption[key] = (consumption[key] or 0) + count
consumption_with_groups[key] = consumption_with_groups[key] - count
assert(consumption_with_groups[key] == 0)
consumption_with_groups[key] = nil
inv_index[key] = inv_index[key] - count
assert(inv_index[key] >= 0)
end
end end
-- check if output and all replacements fit in dst
-- Next, resolve groups using the remaining items in the inventory local output = craft.output.item
local take local out_items = count_index(craft.decremented_input.items)
if #groups > 0 then out_items[output:get_name()] = (out_items[output:get_name()] or 0) + output:get_count()
for itemname, count in pairs(inv_index) do
if count > 0 then
local def = minetest.registered_items[itemname]
local item_groups = def and def.groups or {}
for i = 1, #groups do
local group = groups[i]
local groupname = "group:" .. group
if item_groups[group] and item_groups[group] >= 1
and consumption_with_groups[groupname] > 0
then
take = math.min(count, consumption_with_groups[groupname])
consumption_with_groups[groupname] =
consumption_with_groups[groupname] - take
assert(consumption_with_groups[groupname] >= 0)
consumption[itemname] =
(consumption[itemname] or 0) + take
inv_index[itemname] = inv_index[itemname] - take
assert(inv_index[itemname] >= 0)
end
end
end
end
end
-- Finally, check everything has been consumed
for key, count in pairs(consumption_with_groups) do
if count > 0 then
return nil
end
end
return consumption
end
local function has_room_for_output(list_output, index_output)
local name
local empty_count = 0 local empty_count = 0
for _, item in pairs(list_output) do for _,item in pairs(inventory:get_list("dst")) do
if item:is_empty() then if item:is_empty() then
empty_count = empty_count + 1 empty_count = empty_count + 1
else else
name = item:get_name() local name = item:get_name()
if index_output[name] then if out_items[name] then
index_output[name] = index_output[name] - item:get_free_space() out_items[name] = out_items[name] - item:get_free_space()
end end
end end
end end
for _, count in pairs(index_output) do for _,count in pairs(out_items) do
if count > 0 then if count > 0 then
empty_count = empty_count - 1 empty_count = empty_count - 1
end end
@ -177,66 +63,37 @@ local function has_room_for_output(list_output, index_output)
if empty_count < 0 then if empty_count < 0 then
return false return false
end end
return true
end
local function autocraft(inventory, craft)
if not craft then return false end
-- check if output and all replacements fit in dst
local output = craft.output.item
local out_items = count_index(craft.decremented_input)
out_items[output:get_name()] =
(out_items[output:get_name()] or 0) + output:get_count()
if not has_room_for_output(inventory:get_list("dst"), out_items) then
return false
end
-- check if we have enough material available
local inv_index = count_index(inventory:get_list("src"))
local consumption = calculate_consumption(inv_index, craft.consumption)
if not consumption then
return false
end
-- consume material -- consume material
for itemname, number in pairs(consumption) do for itemname, number in pairs(craft.consumption) do
-- We have to do that since remove_item does not work if count > stack_max for _ = 1, number do -- We have to do that since remove_item does not work if count > stack_max
for _ = 1, number do
inventory:remove_item("src", ItemStack(itemname)) inventory:remove_item("src", ItemStack(itemname))
end end
end end
-- craft the result into the dst inventory and add any "replacements" as well -- craft the result into the dst inventory and add any "replacements" as well
inventory:add_item("dst", output) inventory:add_item("dst", output)
local leftover
for i = 1, 9 do for i = 1, 9 do
leftover = inventory:add_item("dst", craft.decremented_input[i]) inventory:add_item("dst", craft.decremented_input.items[i])
if leftover and not leftover:is_empty() then
minetest.log("warning", "[pipeworks] autocrafter didn't " ..
"calculate output space correctly.")
end
end end
return true return true
end end
-- returns false to stop the timer, true to continue running -- returns false to stop the timer, true to continue running
-- is started only from start_autocrafter(pos) after sanity checks and -- is started only from start_autocrafter(pos) after sanity checks and cached recipe
-- recipe is cached
local function run_autocrafter(pos, elapsed) local function run_autocrafter(pos, elapsed)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inventory = meta:get_inventory() local inventory = meta:get_inventory()
local craft = get_craft(pos, inventory) local craft = get_craft(pos, inventory)
local output_item = craft.output.item local output_item = craft.output.item
-- NALC: existence de limitgroup ?
local limitcraft = minetest.get_item_group(output_item:get_name(), "limitcraft") or 0
-- only use crafts that have an actual result -- only use crafts that have an actual result
if output_item:is_empty() then -- NALC: ou si l'item n'est pas dans le group limitcraft
if output_item:is_empty() or limitcraft > 0 then
meta:set_string("infotext", S("unconfigured Autocrafter: unknown recipe")) meta:set_string("infotext", S("unconfigured Autocrafter: unknown recipe"))
return false return false
end end
for _ = 1, math.floor(elapsed / craft_time) do for _ = 1, math.floor(elapsed/craft_time) do
local continue = autocraft(inventory, craft) local continue = autocraft(inventory, craft)
if not continue then return false end if not continue then return false end
end end
@ -260,17 +117,33 @@ end
-- note, that this function assumes allready being updated to virtual items -- note, that this function assumes allready being updated to virtual items
-- and doesn't handle recipes with stacksizes > 1 -- and doesn't handle recipes with stacksizes > 1
local function after_recipe_change(pos, inventory) local function after_recipe_change(pos, inventory)
local hash = minetest.hash_node_position(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
autocrafterCache[hash] = nil
-- if we emptied the grid, there's no point in keeping it running or cached -- if we emptied the grid, there's no point in keeping it running or cached
if inventory:is_empty("recipe") then if inventory:is_empty("recipe") then
minetest.get_node_timer(pos):stop() minetest.get_node_timer(pos):stop()
autocrafterCache[minetest.hash_node_position(pos)] = nil
meta:set_string("infotext", S("unconfigured Autocrafter")) meta:set_string("infotext", S("unconfigured Autocrafter"))
inventory:set_stack("output", 1, "") inventory:set_stack("output", 1, "")
return return
end end
local craft = get_craft(pos, inventory, hash) local recipe = inventory:get_list("recipe")
local hash = minetest.hash_node_position(pos)
local craft = autocrafterCache[hash]
if craft then
-- check if it changed
local cached_recipe = craft.recipe
for i = 1, 9 do
if recipe[i]:get_name() ~= cached_recipe[i]:get_name() then
autocrafterCache[hash] = nil -- invalidate recipe
craft = nil
break
end
end
end
craft = craft or get_craft(pos, inventory, hash)
local output_item = craft.output.item local output_item = craft.output.item
local description, name = get_item_info(output_item) local description, name = get_item_info(output_item)
meta:set_string("infotext", S("'@1' Autocrafter (@2)", description, name)) meta:set_string("infotext", S("'@1' Autocrafter (@2)", description, name))
@ -279,8 +152,7 @@ local function after_recipe_change(pos, inventory)
after_inventory_change(pos) after_inventory_change(pos)
end end
-- clean out unknown items and groups, which would be handled like unknown -- clean out unknown items and groups, which would be handled like unknown items in the crafting grid
-- items in the crafting grid
-- if minetest supports query by group one day, this might replace them -- if minetest supports query by group one day, this might replace them
-- with a canonical version instead -- with a canonical version instead
local function normalize(item_list) local function normalize(item_list)
@ -311,65 +183,58 @@ local function on_output_change(pos, inventory, stack)
end end
width_idx = (width_idx < 3) and (width_idx + 1) or 1 width_idx = (width_idx < 3) and (width_idx + 1) or 1
end end
-- we'll set the output slot in after_recipe_change to the actual -- we'll set the output slot in after_recipe_change to the actual result of the new recipe
-- result of the new recipe
end end
after_recipe_change(pos, inventory) after_recipe_change(pos, inventory)
end end
-- returns false if we shouldn't bother attempting to start the timer again -- returns false if we shouldn't bother attempting to start the timer again after this
-- after this
local function update_meta(meta, enabled) local function update_meta(meta, enabled)
local state = enabled and "on" or "off" local state = enabled and "on" or "off"
meta:set_int("enabled", enabled and 1 or 0) meta:set_int("enabled", enabled and 1 or 0)
local list_backgrounds = "" local list_backgrounds = ""
if minetest.get_modpath("i3") or minetest.get_modpath("mcl_formspec") then if minetest.get_modpath("i3") or minetest.get_modpath("mcl_formspec") then
list_backgrounds = "style_type[box;colors=#666]" list_backgrounds = "style_type[box;colors=#666]"
for i = 0, 2 do for i=0, 2 do
for j = 0, 2 do for j=0, 2 do
list_backgrounds = list_backgrounds .. "box[" .. list_backgrounds = list_backgrounds .. "box[".. 0.22+(i*1.25) ..",".. 0.22+(j*1.25) ..";1,1;]"
0.22 + (i * 1.25) .. "," .. 0.22 + (j * 1.25) .. ";1,1;]"
end end
end end
for i = 0, 3 do for i=0, 3 do
for j = 0, 2 do for j=0, 2 do
list_backgrounds = list_backgrounds .. "box[" .. list_backgrounds = list_backgrounds .. "box[".. 5.28+(i*1.25) ..",".. 0.22+(j*1.25) ..";1,1;]"
5.28 + (i * 1.25) .. "," .. 0.22 + (j * 1.25) .. ";1,1;]"
end end
end end
for i = 0, 7 do for i=0, 7 do
for j = 0, 2 do for j=0, 2 do
list_backgrounds = list_backgrounds .. "box[" .. list_backgrounds = list_backgrounds .. "box[".. 0.22+(i*1.25) ..",".. 5+(j*1.25) ..";1,1;]"
0.22 + (i * 1.25) .. "," .. 5 + (j * 1.25) .. ";1,1;]"
end end
end end
end end
local size = "10.2,14" local size = "10.2,14"
local fs = local fs =
"formspec_version[2]" .. "formspec_version[2]"..
"size[" .. size .. "]" .. "size["..size.."]"..
pipeworks.fs_helpers.get_prepends(size) .. pipeworks.fs_helpers.get_prepends(size)..
list_backgrounds .. list_backgrounds..
"list[context;recipe;0.22,0.22;3,3;]" .. "list[context;recipe;0.22,0.22;3,3;]"..
"image[4,1.45;1,1;[combine:16x16^[noalpha^[colorize:#141318:255]" .. "image[4,1.45;1,1;[combine:16x16^[noalpha^[colorize:#141318:255]"..
"list[context;output;4,1.45;1,1;]" .. "list[context;output;4,1.45;1,1;]"..
"image_button[4,2.6;1,0.6;pipeworks_button_" .. state .. ".png;" .. "image_button[4,2.6;1,0.6;pipeworks_button_" .. state .. ".png;" .. state .. ";;;false;pipeworks_button_interm.png]" ..
state .. ";;;false;pipeworks_button_interm.png]" .. "list[context;dst;5.28,0.22;4,3;]"..
"list[context;dst;5.28,0.22;4,3;]" .. "list[context;src;0.22,5;8,3;]"..
"list[context;src;0.22,5;8,3;]" .. pipeworks.fs_helpers.get_inv(9)..
pipeworks.fs_helpers.get_inv(9) .. "listring[current_player;main]"..
"listring[current_player;main]" ..
"listring[context;src]" .. "listring[context;src]" ..
"listring[current_player;main]" .. "listring[current_player;main]"..
"listring[context;dst]" .. "listring[context;dst]" ..
"listring[current_player;main]" "listring[current_player;main]"
if minetest.get_modpath("digilines") then if minetest.get_modpath("digilines") then
fs = fs .. "field[0.22,4.1;4.5,0.75;channel;" .. S("Channel") .. fs = fs.."field[0.22,4.1;4.5,0.75;channel;"..S("Channel")..";${channel}]"..
";${channel}]" .. "button[5,4.1;1.5,0.75;set_channel;"..S("Set").."]"..
"button[5,4.1;1.5,0.75;set_channel;" .. S("Set") .. "]" .. "button_exit[6.8,4.1;2,0.75;close;"..S("Close").."]"
"button_exit[6.8,4.1;2,0.75;close;" .. S("Close") .. "]"
end end
meta:set_string("formspec", fs) meta:set_string("formspec",fs)
-- toggling the button doesn't quite call for running a recipe change check -- toggling the button doesn't quite call for running a recipe change check
-- so instead we run a minimal version for infotext setting only -- so instead we run a minimal version for infotext setting only
@ -389,12 +254,9 @@ local function update_meta(meta, enabled)
end end
-- 1st version of the autocrafter had actual items in the crafting grid -- 1st version of the autocrafter had actual items in the crafting grid
-- the 2nd replaced these with virtual items, dropped the content on update and -- the 2nd replaced these with virtual items, dropped the content on update and set "virtual_items" to string "1"
-- set "virtual_items" to string "1" -- the third added an output inventory, changed the formspec and added a button for enabling/disabling
-- the third added an output inventory, changed the formspec and added a button -- so we work out way backwards on this history and update each single case to the newest version
-- for enabling/disabling
-- so we work out way backwards on this history and update each single case
-- to the newest version
local function upgrade_autocrafter(pos, meta) local function upgrade_autocrafter(pos, meta)
local meta = meta or minetest.get_meta(pos) local meta = meta or minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
@ -405,8 +267,7 @@ local function upgrade_autocrafter(pos, meta)
update_meta(meta, true) update_meta(meta, true)
if meta:get_string("virtual_items") == "1" then -- we are version 2 if meta:get_string("virtual_items") == "1" then -- we are version 2
-- we already dropped stuff, so lets remove the metadatasetting -- we already dropped stuff, so lets remove the metadatasetting (we are not being called again for this node)
-- (we are not being called again for this node)
meta:set_string("virtual_items", "") meta:set_string("virtual_items", "")
else -- we are version 1 else -- we are version 1
local recipe = inv:get_list("recipe") local recipe = inv:get_list("recipe")
@ -446,23 +307,18 @@ minetest.register_node("pipeworks:autocrafter", {
return inv:room_for_item("src", stack) return inv:room_for_item("src", stack)
end, end,
input_inventory = "dst", input_inventory = "dst",
connect_sides = { connect_sides = {left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1}},
left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1
}
},
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size("src", 3 * 8) inv:set_size("src", 3*8)
inv:set_size("recipe", 3 * 3) inv:set_size("recipe", 3*3)
inv:set_size("dst", 4 * 3) inv:set_size("dst", 4*3)
inv:set_size("output", 1) inv:set_size("output", 1)
update_meta(meta, false) update_meta(meta, false)
end, end,
on_receive_fields = function(pos, formname, fields, sender) on_receive_fields = function(pos, formname, fields, sender)
if (fields.quit and not fields.key_enter_field) if (fields.quit and not fields.key_enter_field) or not pipeworks.may_configure(pos, sender) then
or not pipeworks.may_configure(pos, sender)
then
return return
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -509,9 +365,7 @@ minetest.register_node("pipeworks:autocrafter", {
end, end,
allow_metadata_inventory_take = function(pos, listname, index, stack, player) allow_metadata_inventory_take = function(pos, listname, index, stack, player)
if not pipeworks.may_configure(pos, player) then if not pipeworks.may_configure(pos, player) then
minetest.log("action", string.format("%s attempted to take from " .. minetest.log("action", string.format("%s attempted to take from autocrafter at %s", player:get_player_name(), minetest.pos_to_string(pos)))
"autocrafter at %s",
player:get_player_name(), minetest.pos_to_string(pos)))
return 0 return 0
end end
upgrade_autocrafter(pos) upgrade_autocrafter(pos)
@ -527,9 +381,7 @@ minetest.register_node("pipeworks:autocrafter", {
after_inventory_change(pos) after_inventory_change(pos)
return stack:get_count() return stack:get_count()
end, end,
allow_metadata_inventory_move = function( allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
pos, from_list, from_index, to_list, to_index, count, player)
if not pipeworks.may_configure(pos, player) then return 0 end if not pipeworks.may_configure(pos, player) then return 0 end
upgrade_autocrafter(pos) upgrade_autocrafter(pos)
local inv = minetest.get_meta(pos):get_inventory() local inv = minetest.get_meta(pos):get_inventory()
@ -570,14 +422,13 @@ minetest.register_node("pipeworks:autocrafter", {
if type(msg) == "table" then if type(msg) == "table" then
if #msg < 3 then return end if #msg < 3 then return end
local inv = meta:get_inventory() local inv = meta:get_inventory()
for y = 0, 2, 1 do for y=0,2,1 do
for x = 1, 3, 1 do for x=1,3,1 do
local slot = y * 3 + x local slot = y*3+x
if minetest.registered_items[msg[y + 1][x]] then if minetest.registered_items[msg[y+1][x]] then
inv:set_stack("recipe", slot, ItemStack( inv:set_stack("recipe",slot,ItemStack(msg[y+1][x]))
msg[y + 1][x]))
else else
inv:set_stack("recipe", slot, ItemStack("")) inv:set_stack("recipe",slot,ItemStack(""))
end end
end end
end end
@ -586,12 +437,11 @@ minetest.register_node("pipeworks:autocrafter", {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local recipe = {} local recipe = {}
for y = 0, 2, 1 do for y=0,2,1 do
local row = {} local row = {}
for x = 1, 3, 1 do for x=1,3,1 do
local slot = y * 3 + x local slot = y*3+x
table.insert(row, inv:get_stack( table.insert(row, inv:get_stack("recipe",slot):get_name())
"recipe", slot):get_name())
end end
table.insert(recipe, row) table.insert(recipe, row)
end end
@ -618,4 +468,4 @@ minetest.register_node("pipeworks:autocrafter", {
}, },
}, },
}) })
pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list + 1] = "pipeworks:autocrafter" pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = "pipeworks:autocrafter"

View File

@ -3,60 +3,6 @@ Changelog
2023-06-22 (SwissalpS, rubenwardy)
groups support in recipe. Set recipe as usual via recipe formspec or digilines.
Autocrafter now resolves matching recipe using groups so that items in input
inventory are used, that match group and no longer only strictly what user
has in recipe-inventory
2023-06-21 (OgelGames, BuckarooBanzay)
fix autocrafter destroying replacement items (OG)
remove facedir debugging logs (BB)
2023-05-28 (SwissalpS)
support setting 'can_receive' for teleport tubes via digiline
2023-05-19 (fluxionary, OgelGames)
log items going through teleport tubes
2022-12-02 (wsor4035)
bring back compatibility with mineclone2
2022-11-11 (OgelGames)
prevent tp- and sand-tubes from breaking themselves and refactor part of code
2022-09-18 (fluxionary)
protection checks before break-/placeing a node -> less violation logs
2022-08-14 (wsor4035)
prevent tubes from connecting to furnace front
2022-08-13 (TurkeyMcMac)
moved teleport-tube database to mod-storage
2022-06-23 (S-S-X)
on_repair tweak, improved repairing tubes
* many updates not mentioned here *
2017-10-19 (thetaepsilon) 2017-10-19 (thetaepsilon)
Directional flowables are now implemented. Directional flowables are now implemented.
All devices for which it is relevant (valve, flow sensor etc.) have been converted so that they only flow on their connecting sides, so pressure propogation now works as expected for these devices when pressure logic is enabled. All devices for which it is relevant (valve, flow sensor etc.) have been converted so that they only flow on their connecting sides, so pressure propogation now works as expected for these devices when pressure logic is enabled.
@ -104,91 +50,91 @@ What *does not* work:
*seems this hasn't been updated in a while* *seems this hasn't been updated in a while*
2013-01-13: Tubes can transport items now! Namely, I added Novatux/Nore's item 2013-01-13: Tubes can transport items now! Namely, I added Novatux/Nore's item
transport mod as a default part of this mod, to make tubes do something useful! transport mod as a default part of this mod, to make tubes do something useful!
Thanks to Nore and RealBadAngel for the code contributions! Thanks to Nore and RealBadAngel for the code contributions!
2013-01-05: made storage tanks connect from top/bottom, made storage tank and 2013-01-05: made storage tanks connect from top/bottom, made storage tank and
pipe textures use the ^ combine operator so they can show the actual liquid pipe textures use the ^ combine operator so they can show the actual liquid
going through the pipes/tanks. going through the pipes/tanks.
2013-01-04 (a bit later): Made pipes able to carry water! It was just a minor 2013-01-04 (a bit later): Made pipes able to carry water! It was just a minor
logic error resulting from moving the water flowing code into it's own file logic error resulting from moving the water flowing code into it's own file
when I originally imported it. Many thanks to Mauvebic for writing it! when I originally imported it. Many thanks to Mauvebic for writing it!
2013-01-04: First stage of integrating Mauvebic's water flowing code. This is 2013-01-04: First stage of integrating Mauvebic's water flowing code. This is
experimental and doesn't move water yet - but at least it doesn't break experimental and doesn't move water yet - but at least it doesn't break
anything :-) anything :-)
2013-01-01: Various minor tweaks to textures, facedir settings, some other 2013-01-01: Various minor tweaks to textures, facedir settings, some other
stuff. Changed crafting recipes to account for revamped pumps, valves, etc. stuff. Changed crafting recipes to account for revamped pumps, valves, etc.
Now requires the moreores mod and most recent git (for mese crystal fragments) Now requires the moreores mod and most recent git (for mese crystal fragments)
to craft a pump. Added a "sealed" entry/exit panel (really just a horizontal to craft a pump. Added a "sealed" entry/exit panel (really just a horizontal
pipe with a metal panel overlayed into the middle). Also, tweaked pipes to pipe with a metal panel overlayed into the middle). Also, tweaked pipes to
always drop the empty ones. Revamped pumps so that now they should sit in/on always drop the empty ones. Revamped pumps so that now they should sit in/on
liquid and be connected only from the top, relegated grates to decorational- liquid and be connected only from the top, relegated grates to decorational-
only, added outlet spigot. Got rid of a few obsolete textures. Got rid of only, added outlet spigot. Got rid of a few obsolete textures. Got rid of
that whole _x and _z naming thing - now all directional devices (pumps, valves, that whole _x and _z naming thing - now all directional devices (pumps, valves,
spigots, tanks) use facedir. Valves, spigots no longer auto-rotate to find spigots, tanks) use facedir. Valves, spigots no longer auto-rotate to find
nearby pipes. nearby pipes.
2012-09-17: Added test object for pneumatic tube autorouting code, made tubes 2012-09-17: Added test object for pneumatic tube autorouting code, made tubes
connect to it and any object that bears groups={tubedevice=1} (connects to any connect to it and any object that bears groups={tubedevice=1} (connects to any
side) side)
2012-09-05: All recipes doubled except for junglegrass -> plastic sheet (since 2012-09-05: All recipes doubled except for junglegrass -> plastic sheet (since
that is derived from home decor) that is derived from home decor)
2012-09-02: Fixed plastic sheeting recipe. Added crafting recipes for various 2012-09-02: Fixed plastic sheeting recipe. Added crafting recipes for various
objects, with options: If homedecor is installed, use the plastic sheeting objects, with options: If homedecor is installed, use the plastic sheeting
therein. If not, we define it manually. If the Technic mod is installed, therein. If not, we define it manually. If the Technic mod is installed,
don't define any recipes at all. Also removed the extra "loaded!" messages and don't define any recipes at all. Also removed the extra "loaded!" messages and
tweaked the default pipe alias to point to something that is actually visible tweaked the default pipe alias to point to something that is actually visible
:-) :-)
2012-09-01: flattened wielded pipe segment. 2012-09-01: flattened wielded pipe segment.
2012-08-24: Added square-ish pneumatic tubes with their own autoplace code 2012-08-24: Added square-ish pneumatic tubes with their own autoplace code
(does not connect to steel pipes or pipe-oriented devices), then revised their (does not connect to steel pipes or pipe-oriented devices), then revised their
textures shortly after. Fixed a recursion bug that sometimes caused a stack textures shortly after. Fixed a recursion bug that sometimes caused a stack
overflow. Old pipes were overriding the pipeworks:pipe defintion that belongs overflow. Old pipes were overriding the pipeworks:pipe defintion that belongs
with the new pipes. with the new pipes.
2012-08-22: Added outlet grate, made it participate in autoplace algorithm. 2012-08-22: Added outlet grate, made it participate in autoplace algorithm.
Extended storage tank to show fill level in 10% steps (0% to 100%). Added Extended storage tank to show fill level in 10% steps (0% to 100%). Added
"expansion tank" that appears if the user stacks tanks upwards. (Downwards is "expansion tank" that appears if the user stacks tanks upwards. (Downwards is
not checked). not checked).
2012-08-21: Made storage tank participate in autoplace algorithm. Tuned API a 2012-08-21: Made storage tank participate in autoplace algorithm. Tuned API a
little to allow for more flexible placement. Re-organized code a bit to allow little to allow for more flexible placement. Re-organized code a bit to allow
for some upcoming rules changes. Made storage tanks' upper/lower fittins and for some upcoming rules changes. Made storage tanks' upper/lower fittins and
intake grate participate in autoplace algorithm. intake grate participate in autoplace algorithm.
2012-08-20: Added temporary nodes for storage tank and intake grating, but 2012-08-20: Added temporary nodes for storage tank and intake grating, but
without autoplace. without autoplace.
2012-08-19: Pumps and valves now fully participate in the 2012-08-19: Pumps and valves now fully participate in the
auto-rotate/auto-place algorithm. auto-rotate/auto-place algorithm.
2012-08-18: Total rewrite again. All pipes are now nice and round-looking, and 2012-08-18: Total rewrite again. All pipes are now nice and round-looking, and
they auto-connect! Also added temporary nodes for pump and valve (each with an they auto-connect! Also added temporary nodes for pump and valve (each with an
on/off setting - punch to change). No crafting recipes yet and the pipes still on/off setting - punch to change). No crafting recipes yet and the pipes still
don't do anything useful yet. Soon. don't do anything useful yet. Soon.
2012-08-06: Moved this changelog off the forum post and into a separate file. 2012-08-06: Moved this changelog off the forum post and into a separate file.
2012-08-05 (multiple updates): Rewrote pipeworks to use loops and tables to 2012-08-05 (multiple updates): Rewrote pipeworks to use loops and tables to
create the nodes. Requires far less code now. Added -X, +X, -Y, +Y, -Z, +Z create the nodes. Requires far less code now. Added -X, +X, -Y, +Y, -Z, +Z
capped stubs and a short centered horizontal segment. Changed node definitions capped stubs and a short centered horizontal segment. Changed node definitions
so that the aforementioned "short centered" segment is given on dig/drop. so that the aforementioned "short centered" segment is given on dig/drop.
Renamed it to just "pipeworks:pipe" (and pipe_loaded). Added empty/loaded Renamed it to just "pipeworks:pipe" (and pipe_loaded). Added empty/loaded
indicator images to the capped ends, removed some redundant comments. Made the indicator images to the capped ends, removed some redundant comments. Made the
empty/loaded indication at the capped end more prominent. empty/loaded indication at the capped end more prominent.
2012-07-21: Added screenshot showing pipes as they look now that nodebox 2012-07-21: Added screenshot showing pipes as they look now that nodebox
texture rotation is fixed. texture rotation is fixed.
2012-07-18: Changed the mod name and all internals to 'pipeworks' instead of 2012-07-18: Changed the mod name and all internals to 'pipeworks' instead of
'pipes'... after a couple of mistakes :-) 'pipes'... after a couple of mistakes :-)
2012-07-12: moved project to github. 2012-07-12: moved project to github.

View File

@ -1,96 +1,3 @@
local S = minetest.get_translator("pipeworks")
-- Random variables
pipeworks.expect_infinite_stacks = true
if minetest.get_modpath("unified_inventory") or not minetest.settings:get_bool("creative_mode") then
pipeworks.expect_infinite_stacks = false
end
pipeworks.meseadjlist={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=0,y=1,z=0},{x=0,y=-1,z=0},{x=1,y=0,z=0},{x=-1,y=0,z=0}}
pipeworks.rules_all = {{x=0, y=0, z=1},{x=0, y=0, z=-1},{x=1, y=0, z=0},{x=-1, y=0, z=0},
{x=0, y=1, z=1},{x=0, y=1, z=-1},{x=1, y=1, z=0},{x=-1, y=1, z=0},
{x=0, y=-1, z=1},{x=0, y=-1, z=-1},{x=1, y=-1, z=0},{x=-1, y=-1, z=0},
{x=0, y=1, z=0}, {x=0, y=-1, z=0}}
pipeworks.mesecons_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
pipeworks.digilines_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
pipeworks.liquid_texture = minetest.registered_nodes[pipeworks.liquids.water.flowing].tiles[1]
if type(pipeworks.liquid_texture) == "table" then pipeworks.liquid_texture = pipeworks.liquid_texture.name end
pipeworks.button_off = {text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"}
pipeworks.button_on = {text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"}
pipeworks.button_base = "image_button[0,4.3;1,0.6"
pipeworks.button_label = "label[0.9,4.31;"..S("Allow splitting incoming stacks from tubes").."]"
-- Helper functions
function pipeworks.fix_image_names(table, replacement)
local outtable={}
for i in ipairs(table) do
outtable[i]=string.gsub(table[i], "_XXXXX", replacement)
end
return outtable
end
local function overlay_tube_texture(texture)
-- The texture appears the first time to be colorized as the opaque background.
return ("(%s)^[noalpha^[colorize:#dadada^(%s)"):format(texture, texture)
end
function pipeworks.make_tube_tile(tile)
if pipeworks.use_real_entities then
return tile
elseif type(tile) == "string" then
return overlay_tube_texture(tile)
else
tile = table.copy(tile)
if tile.color then
-- Won't work 100% of the time, but good enough.
tile.name = tile.name .. "^[multiply:" .. minetest.colorspec_to_colorstring(tile.color)
tile.color = nil
end
tile.name = overlay_tube_texture(tile.name)
tile.backface_culling = nil -- The texture is opaque
return tile
end
end
function pipeworks.add_node_box(t, b)
if not t or not b then return end
for i in ipairs(b)
do table.insert(t, b[i])
end
end
function pipeworks.may_configure(pos, player)
local name = player:get_player_name()
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
if owner ~= "" and owner == name then -- wielders and filters
return true
end
return not minetest.is_protected(pos, name)
end
function pipeworks.replace_name(tbl,tr,name)
local ntbl={}
for key,i in pairs(tbl) do
if type(i)=="string" then
ntbl[key]=string.gsub(i,tr,name)
elseif type(i)=="table" then
ntbl[key]=pipeworks.replace_name(i,tr,name)
else
ntbl[key]=i
end
end
return ntbl
end
---------------------- ----------------------
-- Vector functions -- -- Vector functions --
---------------------- ----------------------
@ -341,183 +248,6 @@ local function get_set_wrap(name, is_dynamic)
end) end)
end end
local fake_player_metatable = {
is_player = delay(true),
is_fake_player = true,
-- dummy implementation of the rest of the player API:
add_player_velocity = delay(), -- deprecated
add_velocity = delay(),
get_acceleration = delay(), -- no-op for players
get_animation = delay({x = 0, y = 0}, 0, 0, false),
get_armor_groups = delay({}),
get_attach = delay(),
get_attribute = delay(), -- deprecated
get_bone_position = delay(vector.zero(), vector.zero()),
get_children = delay({}),
get_clouds = delay({
ambient = { r = 0, b = 0, g = 0, a = 0 },
color = { r = 0, b = 0, g = 0, a = 0 },
density = 0,
height = 120,
thickness = 10,
speed = vector.zero(),
}),
get_day_night_ratio = delay(),
get_entity_name = delay(),
get_formspec_prepend = delay(""),
get_fov = delay(0, false, 0),
get_lighting = delay({
exposure = {
center_weight_power = 1,
exposure_correction = 0,
luminance_max = -3,
luminance_min = -3,
speed_bright_dark = 1000,
speed_dark_bright = 1000,
},
saturation = 1,
shadows = {
intensity = .6212,
},
}),
get_local_animation = delay({x = 0, y = 0}, {x = 0, y = 0}, {x = 0, y = 0}, {x = 0, y = 0}, 30),
get_luaentity = delay(),
get_meta = delay({
contains = delay(false),
get = delay(),
set_string = delay(),
get_string = delay(""),
set_int = delay(),
get_int = delay(0),
set_float = delay(),
get_float = delay(0),
get_keys = delay({}),
to_table = delay({fields = {}}),
from_table = delay(false),
equals = delay(false),
}),
get_moon = delay({
scale = 1,
texture = "",
tonemap = "",
visible = false,
}),
get_physics_override = delay({
acceleration_air = 1,
acceleration_default = 1,
gravity = 1,
jump = 1,
liquid_fluidity = 1,
liquid_fluidity_smooth = 1,
liquid_sink = 1,
new_move = true,
sneak = true,
sneak_glitch = false,
speed = 1,
speed_climb = 1,
speed_crouch = 1,
}),
get_player_velocity = vector.zero, -- deprecated
get_rotation = delay(), -- no-op for players
get_sky = delay({ r = 0, g = 0, b = 0, a = 0 }, "regular", {}, true),
get_sky_color = delay({
dawn_horizon = { r = 0, g = 0, b = 0, a = 0 },
dawn_sky = { r = 0, g = 0, b = 0, a = 0 },
day_horizon = { r = 0, g = 0, b = 0, a = 0 },
day_sky = { r = 0, g = 0, b = 0, a = 0 },
fog_moon_tint = { r = 0, g = 0, b = 0, a = 0 },
fog_sun_tint = { r = 0, g = 0, b = 0, a = 0 },
fog_tint_type = "default",
indoors = { r = 0, g = 0, b = 0, a = 0 },
night_horizon = { r = 0, g = 0, b = 0, a = 0 },
night_sky = { r = 0, g = 0, b = 0, a = 0 },
}),
get_stars = delay({
count = 1000,
day_opacity = 0,
scale = 1,
star_color = { r = 0, g = 0, b = 0, a = 0 },
visible = true,
}),
get_sun = delay({
scale = 1,
sunrise = "",
sunrise_visible = true,
texture = "",
tonemap = "",
visible = true,
}),
get_texture_mod = delay(), -- no-op for players
get_velocity = vector.zero,
get_yaw = delay(), -- no-op for players
getacceleration = delay(), -- backward compatibility
getvelocity = vector.zero, -- backward compatibility
getyaw = delay(), -- backward compatibility
hud_add = delay(),
hud_change = delay(),
hud_get = delay(),
hud_get_flags = delay({
basic_debug = false,
breathbar = false,
chat = false,
crosshair = false,
healthbar = false,
hotbar = false,
minimap = false,
minimap_radar = false,
wielditem = false,
}),
hud_get_hotbar_image = delay(""),
hud_get_hotbar_itemcount = delay(1),
hud_get_hotbar_selected_image = delay(""),
hud_remove = delay(),
hud_set_flags = delay(),
hud_set_hotbar_image = delay(),
hud_set_hotbar_itemcount = delay(),
hud_set_hotbar_selected_image = delay(),
override_day_night_ratio = delay(),
punch = delay(),
remove = delay(),
respawn = delay(),
right_click = delay(),
send_mapblock = delay(),
set_acceleration = delay(),
set_animation = delay(),
set_animation_frame_speed = delay(),
set_armor_groups = delay(),
set_attach = delay(),
set_attribute = delay(), -- deprecated
set_bone_position = delay(),
set_clouds = delay(),
set_detach = delay(),
set_formspec_prepend = delay(),
set_fov = delay(),
set_lighting = delay(),
set_local_animation = delay(),
set_look_horizontal = delay(),
set_look_pitch = delay(),
set_look_vertical = delay(),
set_look_yaw = delay(),
set_minimap_modes = delay(),
set_moon = delay(),
set_nametag_attributes = delay(),
set_physics_override = delay(),
set_rotation = delay(), -- no-op for players
set_sky = delay(),
set_sprite = delay(), -- no-op for players
set_stars = delay(),
set_sun = delay(),
set_texture_mod = delay(), -- no-op for players
set_velocity = delay(), -- no-op for players
set_yaw = delay(), -- no-op for players
setacceleration = delay(), -- backward compatibility
setsprite = delay(), -- backward compatibility
settexturemod = delay(), -- backward compatibility
setvelocity = delay(), -- backward compatibility
setyaw = delay(), -- backward compatibility
}
function pipeworks.create_fake_player(def, is_dynamic) function pipeworks.create_fake_player(def, is_dynamic)
local wielded_item = ItemStack("") local wielded_item = ItemStack("")
if def.inventory and def.wield_list then if def.inventory and def.wield_list then
@ -525,6 +255,8 @@ function pipeworks.create_fake_player(def, is_dynamic)
end end
local p = { local p = {
get_player_name = delay(def.name), get_player_name = delay(def.name),
is_player = delay(true),
is_fake_player = true,
_formspec = def.formspec or "", _formspec = def.formspec or "",
_hp = def.hp or 20, _hp = def.hp or 20,
@ -545,11 +277,12 @@ function pipeworks.create_fake_player(def, is_dynamic)
get_eye_offset = function(self) get_eye_offset = function(self)
return self._eye_offset1, self._eye_offset3 return self._eye_offset1, self._eye_offset3
end, end,
get_look_dir = delay(def.look_dir or vector.new()), get_look_dir = delay(def.look_dir or {x=0, y=0, z=1}),
get_look_pitch = delay(def.look_pitch or 0), get_look_pitch = delay(def.look_pitch or 0),
get_look_yaw = delay(def.look_yaw or 0), get_look_yaw = delay(def.look_yaw or 0),
get_look_horizontal = delay(def.look_yaw or 0), get_look_horizontal = delay(def.look_yaw or 0),
get_look_vertical = delay(-(def.look_pitch or 0)), get_look_vertical = delay(-(def.look_pitch or 0)),
set_animation = delay(),
-- Controls -- Controls
get_player_control = delay({ get_player_control = delay({
@ -575,11 +308,14 @@ function pipeworks.create_fake_player(def, is_dynamic)
return ItemStack(self._wielded_item) return ItemStack(self._wielded_item)
end, end,
get_wield_list = delay(def.wield_list), get_wield_list = delay(def.wield_list),
get_nametag_attributes = delay({
bgcolor = false, punch = delay(),
color = { r = 0, g = 0, b = 0, a = 0 }, remove = delay(),
text = def.name, right_click = delay(),
}), set_attach = delay(),
set_detach = delay(),
set_bone_position = delay(),
hud_change = delay(),
} }
-- Getter & setter functions -- Getter & setter functions
p.get_inventory_formspec, p.set_inventory_formspec p.get_inventory_formspec, p.set_inventory_formspec
@ -593,10 +329,37 @@ function pipeworks.create_fake_player(def, is_dynamic)
-- For players, move_to and get_pos do the same -- For players, move_to and get_pos do the same
p.move_to = p.get_pos p.move_to = p.get_pos
-- Backwards compatibility -- Backwards compatibilty
p.getpos = p.get_pos p.getpos = p.get_pos
p.setpos = p.set_pos p.setpos = p.set_pos
p.moveto = p.move_to p.moveto = p.move_to
setmetatable(p, { __index = fake_player_metatable })
-- TODO "implement" all these
-- set_armor_groups
-- get_armor_groups
-- get_animation
-- get_bone_position
-- get_player_velocity
-- set_look_pitch
-- set_look_yaw
-- set_physics_override
-- get_physics_override
-- hud_add
-- hud_remove
-- hud_get
-- hud_set_flags
-- hud_get_flags
-- hud_set_hotbar_itemcount
-- hud_get_hotbar_itemcount
-- hud_set_hotbar_image
-- hud_get_hotbar_image
-- hud_set_hotbar_selected_image
-- hud_get_hotbar_selected_image
-- hud_replace_builtin
-- set_sky
-- get_sky
-- override_day_night_ratio
-- get_day_night_ratio
-- set_local_animation
return p return p
end end

View File

@ -1,5 +1,70 @@
local materials = {
stone = "default:stone",
desert_stone = "default:desert_stone",
desert_sand = "default:desert_sand",
chest = "default:chest",
copper_ingot = "default:copper_ingot",
steel_ingot = "default:steel_ingot",
gold_ingot = "default:gold_ingot",
mese = "default:mese",
mese_crystal = "default:mese_crystal",
mese_crystal_fragment = "default:mese_crystal_fragment",
teleporter = "default:mese",
glass = "default:glass",
}
if minetest.get_modpath("mcl_core") then
materials = {
stone = "mcl_core:stone",
desert_stone = "mcl_core:redsandstone",
desert_sand = "mcl_core:sand",
chest = "mcl_chests:chest",
steel_ingot = "mcl_core:iron_ingot",
gold_ingot = "mcl_core:gold_ingot",
mese = "mesecons_torch:redstoneblock",
mese_crystal = "mesecons:redstone",
mese_crystal_fragment = "mesecons:redstone",
teleporter = "mesecons_torch:redstoneblock",
copper_ingot = "mcl_copper:copper_ingot",
glass = "mcl_core:glass",
}
elseif minetest.get_modpath("fl_ores") and minetest.get_modpath("fl_stone") then
materials = {
stone = "fl_stone:stone",
desert_stone = "fl_stone:desert_stone",
desert_sand = "fl_stone:desert_sand",
chest = "fl_storage:wood_chest",
steel_ingot = "fl_ores:iron_ingot",
gold_ingot = "fl_ores:gold_ingot",
mese = "fl_ores:iron_ingot",
mese_crystal = "fl_ores:iron_ingot",
mese_crystal_fragment = "fl_ores:iron_ingot",
teleporter = "fl_ores:iron_ingot",
copper_ingot = "fl_ores:copper_ingot",
glass = "fl_glass:framed_glass",
}
elseif minetest.get_modpath("hades_core") then
materials = {
stone = "hades_core:stone",
desert_stone = "hades_core:stone_baked",
desert_sand = "hades_core:volcanic_sand",
chest = "hades_chests:chest";
steel_ingot = "hades_core:steel_ingot",
gold_ingot = "hades_core:gold_ingot",
mese = "hades_core:mese",
mese_crystal = "hades_core:mese_crystal",
mese_crystal_fragment = "hades_core:mese_crystal_fragment",
teleporter = "hades_materials:teleporter_device",
copper_ingot = "hades_core:copper_ingot",
tin_ingot = "hades_core:tin_ingot",
glass = "hades_core:glass",
}
if minetest.get_modpath("hades_default") then
materials.desert_sand = "hades_default:desert_sand"
end
end
-- Crafting recipes for pipes -- Crafting recipes for pipes
local materials = ...
minetest.register_craft( { minetest.register_craft( {
output = "pipeworks:pipe_1_empty 12", output = "pipeworks:pipe_1_empty 12",
@ -129,6 +194,15 @@ minetest.register_craft( {
}, },
}) })
minetest.register_craft( {
output = "pipeworks:steel_block_embedded_tube 1",
recipe = {
{ materials.steel_ingot, materials.steel_ingot, materials.steel_ingot },
{ materials.steel_ingot, "pipeworks:tube_1", materials.steel_ingot },
{ materials.steel_ingot, materials.steel_ingot, materials.steel_ingot }
},
})
minetest.register_craft( { minetest.register_craft( {
output = "pipeworks:steel_pane_embedded_tube 1", output = "pipeworks:steel_pane_embedded_tube 1",
recipe = { recipe = {

View File

@ -1,6 +1,39 @@
local S = minetest.get_translator("pipeworks") local S = minetest.get_translator("pipeworks")
local straight = function(pos, node, velocity, stack) return {velocity} end local straight = function(pos, node, velocity, stack) return {velocity} end
local steel_tex = "[combine:16x16^[noalpha^[colorize:#D3D3D3"
if minetest.get_modpath("default") then steel_tex = "default_steel_block.png" end
minetest.register_node("pipeworks:steel_block_embedded_tube", {
description = S("Airtight steelblock embedded tube"),
tiles = {
steel_tex, steel_tex,
steel_tex, steel_tex,
steel_tex .. "^pipeworks_tube_connection_metallic.png",
steel_tex .. "^pipeworks_tube_connection_metallic.png",
},
paramtype = "light",
paramtype2 = "facedir",
groups = {cracky=1, oddly_breakable_by_hand = 1, tubedevice = 1, dig_glass = 2, pickaxey=1, handy=1},
_mcl_hardness=0.8,
legacy_facedir_simple = true,
_sound_def = {
key = "node_sound_stone_defaults",
},
tube = {
connect_sides = {front = 1, back = 1,},
priority = 50,
can_go = straight,
can_insert = function(pos, node, stack, direction)
local dir = minetest.facedir_to_dir(node.param2)
return vector.equals(dir, direction) or vector.equals(vector.multiply(dir, -1), direction)
end,
},
after_place_node = pipeworks.after_place,
after_dig_node = pipeworks.after_dig,
on_rotate = pipeworks.on_rotate,
})
pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = "pipeworks:steel_block_embedded_tube"
local pane_box = { local pane_box = {
type = "fixed", type = "fixed",

155
init.lua
View File

@ -4,20 +4,21 @@
-- and devices that they can connect to. -- and devices that they can connect to.
-- --
pipeworks = { pipeworks = {}
ui_cat_tube_list = {}, pipeworks.ui_cat_tube_list = {}
worldpath = minetest.get_worldpath(),
modpath = minetest.get_modpath("pipeworks"), pipeworks.worldpath = minetest.get_worldpath()
liquids = { pipeworks.modpath = minetest.get_modpath("pipeworks")
water = { local S = minetest.get_translator("pipeworks")
source = minetest.registered_nodes["mapgen_water_source"].name,
flowing = minetest.registered_nodes["mapgen_water_source"].liquid_alternative_flowing pipeworks.liquids = {}
}, pipeworks.liquids.water = {
river_water = { source = minetest.registered_nodes["mapgen_water_source"].name,
source = minetest.registered_nodes["mapgen_river_water_source"].name, flowing = minetest.registered_nodes["mapgen_water_source"].liquid_alternative_flowing
flowing = minetest.registered_nodes["mapgen_river_water_source"].liquid_alternative_flowing }
} pipeworks.liquids.river_water = {
} source = minetest.registered_nodes["mapgen_river_water_source"].name,
flowing = minetest.registered_nodes["mapgen_river_water_source"].liquid_alternative_flowing
} }
dofile(pipeworks.modpath.."/default_settings.lua") dofile(pipeworks.modpath.."/default_settings.lua")
@ -35,6 +36,97 @@ if pipeworks.entity_update_interval >= 0.2 and pipeworks.enable_accelerator_tube
minetest.log("warning", "pipeworks accelerator tubes will not entirely work with an entity update interval 0.2 or above.") minetest.log("warning", "pipeworks accelerator tubes will not entirely work with an entity update interval 0.2 or above.")
end end
-- Random variables
pipeworks.expect_infinite_stacks = true
if minetest.get_modpath("unified_inventory") or not minetest.settings:get_bool("creative_mode") then
pipeworks.expect_infinite_stacks = false
end
pipeworks.meseadjlist={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=0,y=1,z=0},{x=0,y=-1,z=0},{x=1,y=0,z=0},{x=-1,y=0,z=0}}
pipeworks.rules_all = {{x=0, y=0, z=1},{x=0, y=0, z=-1},{x=1, y=0, z=0},{x=-1, y=0, z=0},
{x=0, y=1, z=1},{x=0, y=1, z=-1},{x=1, y=1, z=0},{x=-1, y=1, z=0},
{x=0, y=-1, z=1},{x=0, y=-1, z=-1},{x=1, y=-1, z=0},{x=-1, y=-1, z=0},
{x=0, y=1, z=0}, {x=0, y=-1, z=0}}
pipeworks.mesecons_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
pipeworks.digilines_rules={{x=0,y=0,z=1},{x=0,y=0,z=-1},{x=1,y=0,z=0},{x=-1,y=0,z=0},{x=0,y=1,z=0},{x=0,y=-1,z=0}}
pipeworks.liquid_texture = minetest.registered_nodes[pipeworks.liquids.water.flowing].tiles[1]
if type(pipeworks.liquid_texture) == "table" then pipeworks.liquid_texture = pipeworks.liquid_texture.name end
pipeworks.button_off = {text="", texture="pipeworks_button_off.png", addopts="false;false;pipeworks_button_interm.png"}
pipeworks.button_on = {text="", texture="pipeworks_button_on.png", addopts="false;false;pipeworks_button_interm.png"}
pipeworks.button_base = "image_button[0,4.3;1,0.6"
pipeworks.button_label = "label[0.9,4.31;"..S("Allow splitting incoming stacks from tubes").."]"
-- Helper functions
function pipeworks.fix_image_names(table, replacement)
local outtable={}
for i in ipairs(table) do
outtable[i]=string.gsub(table[i], "_XXXXX", replacement)
end
return outtable
end
local function overlay_tube_texture(texture)
-- The texture appears the first time to be colorized as the opaque background.
return ("(%s)^[noalpha^[colorize:#dadada^(%s)"):format(texture, texture)
end
function pipeworks.make_tube_tile(tile)
if pipeworks.use_real_entities then
return tile
elseif type(tile) == "string" then
return overlay_tube_texture(tile)
else
tile = table.copy(tile)
if tile.color then
-- Won't work 100% of the time, but good enough.
tile.name = tile.name .. "^[multiply:" .. minetest.colorspec_to_colorstring(tile.color)
tile.color = nil
end
tile.name = overlay_tube_texture(tile.name)
tile.backface_culling = nil -- The texture is opaque
return tile
end
end
function pipeworks.add_node_box(t, b)
if not t or not b then return end
for i in ipairs(b)
do table.insert(t, b[i])
end
end
function pipeworks.may_configure(pos, player)
local name = player:get_player_name()
local meta = minetest.get_meta(pos)
local owner = meta:get_string("owner")
if owner ~= "" and owner == name then -- wielders and filters
return true
end
return not minetest.is_protected(pos, name)
end
function pipeworks.replace_name(tbl,tr,name)
local ntbl={}
for key,i in pairs(tbl) do
if type(i)=="string" then
ntbl[key]=string.gsub(i,tr,name)
elseif type(i)=="table" then
ntbl[key]=pipeworks.replace_name(i,tr,name)
else
ntbl[key]=i
end
end
return ntbl
end
pipeworks.logger = function(msg) pipeworks.logger = function(msg)
minetest.log("action", "[pipeworks] "..msg) minetest.log("action", "[pipeworks] "..msg)
end end
@ -58,29 +150,15 @@ dofile(pipeworks.modpath.."/autoplace_tubes.lua")
dofile(pipeworks.modpath.."/luaentity.lua") dofile(pipeworks.modpath.."/luaentity.lua")
dofile(pipeworks.modpath.."/item_transport.lua") dofile(pipeworks.modpath.."/item_transport.lua")
dofile(pipeworks.modpath.."/flowing_logic.lua") dofile(pipeworks.modpath.."/flowing_logic.lua")
dofile(pipeworks.modpath.."/tube_registration.lua")
dofile(pipeworks.modpath.."/routing_tubes.lua")
dofile(pipeworks.modpath.."/sorting_tubes.lua")
dofile(pipeworks.modpath.."/signal_tubes.lua")
dofile(pipeworks.modpath.."/decorative_tubes.lua")
dofile(pipeworks.modpath.."/filter-injector.lua") dofile(pipeworks.modpath.."/filter-injector.lua")
dofile(pipeworks.modpath.."/trashcan.lua") dofile(pipeworks.modpath.."/trashcan.lua")
dofile(pipeworks.modpath.."/wielder.lua") dofile(pipeworks.modpath.."/wielder.lua")
local materials = loadfile(pipeworks.modpath.."/materials.lua")()
dofile(pipeworks.modpath.."/tubes/registration.lua")
dofile(pipeworks.modpath.."/tubes/routing.lua")
dofile(pipeworks.modpath.."/tubes/sorting.lua")
dofile(pipeworks.modpath.."/tubes/signal.lua")
loadfile(pipeworks.modpath.."/tubes/embedded_tube.lua")(materials)
dofile(pipeworks.modpath.."/tubes/pane_embedded_tube.lua")
if pipeworks.enable_teleport_tube then
dofile(pipeworks.modpath.."/tubes/teleport.lua")
end
if pipeworks.enable_lua_tube and minetest.get_modpath("mesecons") then
dofile(pipeworks.modpath.."/tubes/lua.lua")
end
if pipeworks.enable_sand_tube or pipeworks.enable_mese_sand_tube then
dofile(pipeworks.modpath.."/tubes/vacuum.lua")
end
local logicdir = "/pressure_logic/" local logicdir = "/pressure_logic/"
-- note that even with these files the new flow logic is not yet default. -- note that even with these files the new flow logic is not yet default.
@ -94,6 +172,9 @@ dofile(pipeworks.modpath..logicdir.."flowable_node_registry_install.lua")
if pipeworks.enable_pipes then if pipeworks.enable_pipes then
dofile(pipeworks.modpath.."/pipes.lua") dofile(pipeworks.modpath.."/pipes.lua")
end end
if pipeworks.enable_teleport_tube then
dofile(pipeworks.modpath.."/teleport_tube.lua")
end
if pipeworks.enable_pipe_devices then if pipeworks.enable_pipe_devices then
dofile(pipeworks.modpath.."/devices.lua") dofile(pipeworks.modpath.."/devices.lua")
end end
@ -110,8 +191,14 @@ end
if pipeworks.enable_autocrafter then if pipeworks.enable_autocrafter then
dofile(pipeworks.modpath.."/autocrafter.lua") dofile(pipeworks.modpath.."/autocrafter.lua")
end end
if pipeworks.enable_lua_tube and minetest.get_modpath("mesecons") then
dofile(pipeworks.modpath.."/lua_tube.lua")
end
if pipeworks.enable_sand_tube or pipeworks.enable_mese_sand_tube then
dofile(pipeworks.modpath.."/vacuum_tubes.lua")
end
loadfile(pipeworks.modpath.."/crafts.lua")(materials) dofile(pipeworks.modpath.."/crafts.lua")
minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty") minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")

View File

@ -1,67 +0,0 @@
local materials = {
stone = "default:stone",
desert_stone = "default:desert_stone",
desert_sand = "default:desert_sand",
chest = "default:chest",
copper_ingot = "default:copper_ingot",
steel_ingot = "default:steel_ingot",
gold_ingot = "default:gold_ingot",
mese = "default:mese",
mese_crystal = "default:mese_crystal",
mese_crystal_fragment = "default:mese_crystal_fragment",
teleporter = "default:mese",
glass = "default:glass"
}
if minetest.get_modpath("mcl_core") then
materials = {
stone = "mcl_core:stone",
desert_stone = "mcl_core:redsandstone",
desert_sand = "mcl_core:sand",
chest = "mcl_chests:chest",
steel_ingot = "mcl_core:iron_ingot",
gold_ingot = "mcl_core:gold_ingot",
mese = "mesecons_torch:redstoneblock",
mese_crystal = "mesecons:redstone",
mese_crystal_fragment = "mesecons:redstone",
teleporter = "mesecons_torch:redstoneblock",
copper_ingot = "mcl_copper:copper_ingot",
glass = "mcl_core:glass",
}
elseif minetest.get_modpath("fl_ores") and minetest.get_modpath("fl_stone") then
materials = {
stone = "fl_stone:stone",
desert_stone = "fl_stone:desert_stone",
desert_sand = "fl_stone:desert_sand",
chest = "fl_storage:wood_chest",
steel_ingot = "fl_ores:iron_ingot",
gold_ingot = "fl_ores:gold_ingot",
mese = "fl_ores:iron_ingot",
mese_crystal = "fl_ores:iron_ingot",
mese_crystal_fragment = "fl_ores:iron_ingot",
teleporter = "fl_ores:iron_ingot",
copper_ingot = "fl_ores:copper_ingot",
glass = "fl_glass:framed_glass",
}
elseif minetest.get_modpath("hades_core") then
materials = {
stone = "hades_core:stone",
desert_stone = "hades_core:stone_baked",
desert_sand = "hades_core:volcanic_sand",
chest = "hades_chests:chest";
steel_ingot = "hades_core:steel_ingot",
gold_ingot = "hades_core:gold_ingot",
mese = "hades_core:mese",
mese_crystal = "hades_core:mese_crystal",
mese_crystal_fragment = "hades_core:mese_crystal_fragment",
teleporter = "hades_materials:teleporter_device",
copper_ingot = "hades_core:copper_ingot",
tin_ingot = "hades_core:tin_ingot",
glass = "hades_core:glass",
}
if minetest.get_modpath("hades_default") then
materials.desert_sand = "hades_default:desert_sand"
end
end
return materials

View File

@ -2,4 +2,4 @@ name = pipeworks
description = This mod uses mesh nodes and nodeboxes to supply a complete set of 3D pipes and tubes, along with devices that work with them. description = This mod uses mesh nodes and nodeboxes to supply a complete set of 3D pipes and tubes, along with devices that work with them.
depends = basic_materials depends = basic_materials
optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api, i3, hades_core, hades_furnaces, hades_chests, mcl_mapgen_core, mcl_barrels, mcl_furnaces, mcl_experience optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api, i3, hades_core, hades_furnaces, hades_chests, mcl_mapgen_core, mcl_barrels, mcl_furnaces, mcl_experience
min_minetest_version = 5.5.0 min_minetest_version = 5.4.0

View File

@ -93,7 +93,6 @@ pipeworks.register_tube("pipeworks:broken_tube", {
minetest.swap_node(pos, { name = was_node.name, param2 = was_node.param2 }) minetest.swap_node(pos, { name = was_node.name, param2 = was_node.param2 })
pipeworks.scan_for_tube_objects(pos) pipeworks.scan_for_tube_objects(pos)
end end
meta:set_string("the_tube_was", "")
else else
pipeworks.logger(log_msg.." but original node "..was_node.name.." is not registered anymore.") pipeworks.logger(log_msg.." but original node "..was_node.name.." is not registered anymore.")
minetest.chat_send_player(playername, S("This tube cannot be repaired.")) minetest.chat_send_player(playername, S("This tube cannot be repaired."))

View File

@ -1,68 +0,0 @@
local materials = ...
local S = minetest.get_translator("pipeworks")
local straight = function(pos, node, velocity, stack) return {velocity} end
local steel_tex = "[combine:16x16^[noalpha^[colorize:#D3D3D3"
if minetest.get_modpath("default") then steel_tex = "default_steel_block.png" end
-- register an embedded tube
function pipeworks.register_embedded_tube(nodename, opts)
minetest.register_node(nodename, {
description = opts.description,
tiles = {
opts.base_texture,
opts.base_texture,
opts.base_texture,
opts.base_texture,
opts.base_texture .. "^pipeworks_tube_connection_metallic.png",
opts.base_texture .. "^pipeworks_tube_connection_metallic.png",
},
paramtype = "light",
paramtype2 = "facedir",
groups = {
cracky = 1,
oddly_breakable_by_hand = 1,
tubedevice = 1,
dig_glass = 2,
pickaxey=1,
handy=1
},
_mcl_hardness = 0.8,
legacy_facedir_simple = true,
_sound_def = {
key = "node_sound_stone_defaults",
},
tube = {
connect_sides = {
front = 1,
back = 1
},
priority = 50,
can_go = straight,
can_insert = function(pos, node, stack, direction)
local dir = minetest.facedir_to_dir(node.param2)
return vector.equals(dir, direction) or vector.equals(vector.multiply(dir, -1), direction)
end
},
after_place_node = pipeworks.after_place,
after_dig_node = pipeworks.after_dig,
on_rotate = pipeworks.on_rotate,
})
minetest.register_craft( {
output = nodename .. " 1",
recipe = {
{ opts.base_ingredient, opts.base_ingredient, opts.base_ingredient },
{ opts.base_ingredient, "pipeworks:tube_1", opts.base_ingredient },
{ opts.base_ingredient, opts.base_ingredient, opts.base_ingredient }
},
})
pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = nodename
end
-- steelblock embedded tube
pipeworks.register_embedded_tube("pipeworks:steel_block_embedded_tube", {
description = S("Airtight steelblock embedded tube"),
base_texture = steel_tex,
base_ingredient = materials.steel_ingot
})

View File

@ -32,12 +32,6 @@ local function set_timer(pos)
timer:start(math.random(10, 20) * 0.1) timer:start(math.random(10, 20) * 0.1)
end end
local function repair_tube(pos, was_node)
minetest.swap_node(pos, {name = was_node.name, param2 = was_node.param2})
pipeworks.scan_for_tube_objects(pos)
set_timer(pos)
end
if pipeworks.enable_sand_tube then if pipeworks.enable_sand_tube then
pipeworks.register_tube("pipeworks:sand_tube", { pipeworks.register_tube("pipeworks:sand_tube", {
description = S("Vacuuming Pneumatic Tube Segment"), description = S("Vacuuming Pneumatic Tube Segment"),
@ -48,9 +42,6 @@ if pipeworks.enable_sand_tube then
ends = {"pipeworks_sand_tube_end.png"}, ends = {"pipeworks_sand_tube_end.png"},
node_def = { node_def = {
groups = {vacuum_tube = 1}, groups = {vacuum_tube = 1},
tube = {
on_repair = repair_tube,
},
on_construct = set_timer, on_construct = set_timer,
on_timer = function(pos, elapsed) on_timer = function(pos, elapsed)
vacuum(pos, 2) vacuum(pos, 2)
@ -77,9 +68,6 @@ if pipeworks.enable_mese_sand_tube then
ends = {"pipeworks_mese_sand_tube_end.png"}, ends = {"pipeworks_mese_sand_tube_end.png"},
node_def = { node_def = {
groups = {vacuum_tube = 1}, groups = {vacuum_tube = 1},
tube = {
on_repair = repair_tube,
},
on_construct = function(pos) on_construct = function(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
meta:set_int("dist", 2) meta:set_int("dist", 2)