7 Commits

Author SHA1 Message Date
4db71f88f9 clear metadata value after repair 2024-01-14 14:50:34 +11:00
a02eac82ff restart vacuum tube node timers after repair 2024-01-14 14:50:19 +11:00
04df87a6c2 Delete .editorconfig 2024-01-14 14:29:55 +11:00
360ed9bdde Autocrafter groups support (#74)
* Add support for recipes with groups to autocrafter

* fix autocrafter replacements

* remove unnecessary check and move some code

* reorder and change back var name

* only whitespace changes

* reuse hash that is asigned to variable anyway

* add get_matching_craft

function that looks for the best matching recipe according to what user
put in recipe inventory

some crafts use groups in multiple recipes

* return right away if there is a chached craft

gives us more horizontal space to work with

* indentation adjusting

* use get_matching_craft to get best craft

this line was buggy anyhow

* new craft format: decremented_input

craft.decremented_input now only holds the items. Extra parameters are
dropped

* bugfix: when item has no groups

"" and unknown items have no def and thus no groups

* add function has_room_for_output

moving the output space calculation into its own function
helps keep autocraft() short and overseeable

* use has_room_for_output

* remove double-check of available materials

* add warning to ensure double-check was not needed

* rebuild cache whenever recipe inv changes

no need to check if still current, this only happens when user is
interacting and can only be better to do so.
Otherwise we would have to check groups etc. again just to check, so
might as well reset cache.

* remove unused line

* use minetest.get_item_group()

* whitespace cleanup

make code easier to read and give it a more
"thoughtthrough" look than the "smash it in to make it work" look it has
had.

(I'm holding back, there would be more to do overall through this mod)

* add .editorconfig

this should also help keep consistency throughout this mod

* changelog updated

at least the most recent more important ones

* whitespace changelog (trailing spaces)

---------

Co-authored-by: rubenwardy <rw@rubenwardy.com>
Co-authored-by: OgelGames <olliverdc28@gmail.com>
Co-authored-by: wsor4035 <24964441+wsor4035@users.noreply.github.com>
2024-01-13 20:41:28 -05:00
578e45257b code and registrations cleanup (#101)
* code and registrations cleanup

* don't expose materials to global env

---------

Co-authored-by: BuckarooBanzay <BuckarooBanzay@users.noreply.github.com>
2024-01-13 20:40:01 -05:00
dd6950f7b0 bump min_minetest_version to 5.5.0 for vector.zero()
closes #100
2024-01-05 16:11:23 +11:00
5b0dceb44a add dummy implementations of all current API calls to fake player (#98)
* add dummy implementations of all current API calls to fake player

* fakeplayer: move all stateless API into a metatable

* correctly set metatable
2023-12-29 14:01:08 -05:00
17 changed files with 822 additions and 427 deletions

View File

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

View File

@ -1,11 +1,14 @@
local S = minetest.get_translator("pipeworks") local S = minetest.get_translator("pipeworks")
local autocrafterCache = {} -- caches some recipe data to avoid to call the slow function minetest.get_craft_result() every second -- cache some recipe data to avoid calling the slow function
-- 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()
@ -21,41 +24,152 @@ 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 not craft then if craft then return craft end
local recipe = inventory:get_list("recipe")
local output, decremented_input = minetest.get_craft_result({method = "normal", width = 3, items = recipe}) local example_recipe = inventory:get_list("recipe")
craft = {recipe = recipe, consumption=count_index(recipe), output = output, decremented_input = decremented_input} local output, decremented_input = minetest.get_craft_result({
autocrafterCache[hash] = craft method = "normal", width = 3, items = example_recipe
})
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
local function autocraft(inventory, craft) -- From a consumption table with groups and an inventory index, build
if not craft then return false end -- a consumption table without groups
-- check if we have enough material available local function calculate_consumption(inv_index, consumption_with_groups)
local inv_index = count_index(inventory:get_list("src")) inv_index = table.copy(inv_index)
for itemname, number in pairs(craft.consumption) do consumption_with_groups = table.copy(consumption_with_groups)
if (not inv_index[itemname]) or inv_index[itemname] < number then return false end
end local consumption = {}
-- check if output and all replacements fit in dst local groups = {}
local output = craft.output.item
local out_items = count_index(craft.decremented_input.items) -- First consume all non-group requirements
out_items[output:get_name()] = (out_items[output:get_name()] or 0) + output:get_count() -- This is done to avoid consuming a non-group item which is also
local empty_count = 0 -- in a group
for _,item in pairs(inventory:get_list("dst")) do for key, count in pairs(consumption_with_groups) do
if item:is_empty() then if key:sub(1, 6) == "group:" then
empty_count = empty_count + 1 groups[#groups + 1] = key:sub(7, #key)
else else
local name = item:get_name() if not inv_index[key] or inv_index[key] < count then
if out_items[name] then return nil
out_items[name] = out_items[name] - item:get_free_space() 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
-- Next, resolve groups using the remaining items in the inventory
local take
if #groups > 0 then
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 end
end end
for _,count in pairs(out_items) do
-- 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
for _, item in pairs(list_output) do
if item:is_empty() then
empty_count = empty_count + 1
else
name = item:get_name()
if index_output[name] then
index_output[name] = index_output[name] - item:get_free_space()
end
end
end
for _, count in pairs(index_output) do
if count > 0 then if count > 0 then
empty_count = empty_count - 1 empty_count = empty_count - 1
end end
@ -63,22 +177,54 @@ local function autocraft(inventory, craft)
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(craft.consumption) do for itemname, number in pairs(consumption) do
for _ = 1, number do -- We have to do that since remove_item does not work if count > stack_max -- 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
inventory:add_item("dst", craft.decremented_input.items[i]) leftover = inventory:add_item("dst", craft.decremented_input[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 cached recipe -- is started only from start_autocrafter(pos) after sanity checks and
-- 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()
@ -90,7 +236,7 @@ local function run_autocrafter(pos, elapsed)
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
@ -114,33 +260,17 @@ 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 recipe = inventory:get_list("recipe") local craft = get_craft(pos, inventory, hash)
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))
@ -149,7 +279,8 @@ 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 items in the crafting grid -- clean out unknown items and groups, which would be handled like unknown
-- 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)
@ -180,58 +311,65 @@ 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 result of the new recipe -- we'll set the output slot in after_recipe_change to the actual
-- 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 after this -- returns false if we shouldn't bother attempting to start the timer again
-- 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[".. 0.22+(i*1.25) ..",".. 0.22+(j*1.25) ..";1,1;]" list_backgrounds = list_backgrounds .. "box[" ..
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[".. 5.28+(i*1.25) ..",".. 0.22+(j*1.25) ..";1,1;]" list_backgrounds = list_backgrounds .. "box[" ..
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[".. 0.22+(i*1.25) ..",".. 5+(j*1.25) ..";1,1;]" list_backgrounds = list_backgrounds .. "box[" ..
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;" .. state .. ";;;false;pipeworks_button_interm.png]" .. "image_button[4,2.6;1,0.6;pipeworks_button_" .. state .. ".png;" ..
"list[context;dst;5.28,0.22;4,3;]".. state .. ";;;false;pipeworks_button_interm.png]" ..
"list[context;src;0.22,5;8,3;]".. "list[context;dst;5.28,0.22;4,3;]" ..
pipeworks.fs_helpers.get_inv(9).. "list[context;src;0.22,5;8,3;]" ..
"listring[current_player;main]".. pipeworks.fs_helpers.get_inv(9) ..
"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")..";${channel}]".. fs = fs .. "field[0.22,4.1;4.5,0.75;channel;" .. S("Channel") ..
"button[5,4.1;1.5,0.75;set_channel;"..S("Set").."]".. ";${channel}]" ..
"button_exit[6.8,4.1;2,0.75;close;"..S("Close").."]" "button[5,4.1;1.5,0.75;set_channel;" .. S("Set") .. "]" ..
"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
@ -251,9 +389,12 @@ 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 set "virtual_items" to string "1" -- the 2nd replaced these with virtual items, dropped the content on update and
-- the third added an output inventory, changed the formspec and added a button for enabling/disabling -- set "virtual_items" to string "1"
-- so we work out way backwards on this history and update each single case to the newest version -- the third added an output inventory, changed the formspec and added a button
-- 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()
@ -264,7 +405,8 @@ 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 are not being called again for this node) -- we already dropped stuff, so lets remove the metadatasetting
-- (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")
@ -304,18 +446,23 @@ 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 = {left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1}}, connect_sides = {
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) or not pipeworks.may_configure(pos, sender) then if (fields.quit and not fields.key_enter_field)
or not pipeworks.may_configure(pos, sender)
then
return return
end end
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
@ -362,7 +509,9 @@ 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 autocrafter at %s", player:get_player_name(), minetest.pos_to_string(pos))) minetest.log("action", string.format("%s attempted to take from " ..
"autocrafter at %s",
player:get_player_name(), minetest.pos_to_string(pos)))
return 0 return 0
end end
upgrade_autocrafter(pos) upgrade_autocrafter(pos)
@ -378,7 +527,9 @@ 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(pos, from_list, from_index, to_list, to_index, count, player) allow_metadata_inventory_move = function(
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()
@ -419,13 +570,14 @@ 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(msg[y+1][x])) inv:set_stack("recipe", slot, ItemStack(
msg[y + 1][x]))
else else
inv:set_stack("recipe",slot,ItemStack("")) inv:set_stack("recipe", slot, ItemStack(""))
end end
end end
end end
@ -434,11 +586,12 @@ 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("recipe",slot):get_name()) table.insert(row, inv:get_stack(
"recipe", slot):get_name())
end end
table.insert(recipe, row) table.insert(recipe, row)
end end
@ -465,4 +618,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,6 +3,60 @@ 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.

View File

@ -1,3 +1,96 @@
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 --
---------------------- ----------------------
@ -248,6 +341,183 @@ 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
@ -255,8 +525,6 @@ 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,
@ -277,12 +545,11 @@ 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 {x=0, y=0, z=1}), get_look_dir = delay(def.look_dir or vector.new()),
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({
@ -308,14 +575,11 @@ 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({
punch = delay(), bgcolor = false,
remove = delay(), color = { r = 0, g = 0, b = 0, a = 0 },
right_click = delay(), text = def.name,
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
@ -329,37 +593,10 @@ 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 compatibilty -- Backwards compatibility
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,70 +1,5 @@
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",
@ -194,15 +129,6 @@ 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 = {

155
init.lua
View File

@ -4,21 +4,20 @@
-- and devices that they can connect to. -- and devices that they can connect to.
-- --
pipeworks = {} pipeworks = {
pipeworks.ui_cat_tube_list = {} ui_cat_tube_list = {},
worldpath = minetest.get_worldpath(),
pipeworks.worldpath = minetest.get_worldpath() modpath = minetest.get_modpath("pipeworks"),
pipeworks.modpath = minetest.get_modpath("pipeworks") liquids = {
local S = minetest.get_translator("pipeworks") water = {
source = minetest.registered_nodes["mapgen_water_source"].name,
pipeworks.liquids = {} flowing = minetest.registered_nodes["mapgen_water_source"].liquid_alternative_flowing
pipeworks.liquids.water = { },
source = minetest.registered_nodes["mapgen_water_source"].name, river_water = {
flowing = minetest.registered_nodes["mapgen_water_source"].liquid_alternative_flowing source = minetest.registered_nodes["mapgen_river_water_source"].name,
} 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")
@ -36,97 +35,6 @@ 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
@ -150,15 +58,29 @@ 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.
@ -172,9 +94,6 @@ 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
@ -191,14 +110,8 @@ 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
dofile(pipeworks.modpath.."/crafts.lua") loadfile(pipeworks.modpath.."/crafts.lua")(materials)
minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty") minetest.register_alias("pipeworks:pipe", "pipeworks:pipe_110000_empty")

67
materials.lua Normal file
View File

@ -0,0 +1,67 @@
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.4.0 min_minetest_version = 5.5.0

68
tubes/embedded_tube.lua Normal file
View File

@ -0,0 +1,68 @@
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

@ -1,39 +1,6 @@
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",

View File

@ -93,6 +93,7 @@ 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

@ -32,6 +32,12 @@ 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"),
@ -42,6 +48,9 @@ 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)
@ -68,6 +77,9 @@ 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)