Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
1701671
trashcan voids water
The4codeblocks Apr 25, 2025
5ba89d0
trashcan updates pipes
The4codeblocks Apr 25, 2025
392677f
trash can needs pipe logic now
The4codeblocks Apr 25, 2025
52aca25
offsets
The4codeblocks Apr 25, 2025
5a543ce
pressure default
The4codeblocks Apr 25, 2025
54c40b6
creative water source
The4codeblocks Apr 25, 2025
f7dbcbe
fluid crafts
The4codeblocks Apr 25, 2025
2e2a63a
autocrafter with fluids
The4codeblocks Apr 25, 2025
0fab0c2
Add files via upload
The4codeblocks Apr 25, 2025
8d5d92d
fluid crafts without core
The4codeblocks Apr 26, 2025
02bb507
update crafts
The4codeblocks Apr 26, 2025
4348a21
fix offsets
The4codeblocks Apr 26, 2025
8961f1a
flow sensor info
The4codeblocks Apr 26, 2025
976c971
don't global
The4codeblocks Apr 26, 2025
a4f1a35
stuff
The4codeblocks Apr 26, 2025
ff5015d
add lava and defs
The4codeblocks Apr 26, 2025
c023b39
Update autocrafter.lua
The4codeblocks Apr 26, 2025
1e70b48
remove unnecessary registration
The4codeblocks Apr 26, 2025
4a8bf02
Add files via upload
The4codeblocks Apr 26, 2025
fadcae3
recipes
The4codeblocks Apr 26, 2025
f1e78f0
Update crafts.lua
The4codeblocks Apr 26, 2025
70bf3ef
enforcing load order
The4codeblocks Apr 26, 2025
9407ba3
merge on_place and on_dig (contains leak from wip)
The4codeblocks Apr 28, 2025
0a0bd36
fix luacheck again
The4codeblocks Apr 28, 2025
d72b540
remove space-only lines
The4codeblocks Apr 28, 2025
92e7f29
Update .luacheckrc
The4codeblocks Apr 28, 2025
ba8dc61
generalize flag
The4codeblocks Apr 28, 2025
0302121
Update init.lua
The4codeblocks Apr 28, 2025
a5439f2
actual multifluid support
The4codeblocks Apr 28, 2025
fe984ad
casewise finity
The4codeblocks Apr 28, 2025
5e57cc3
try dehardcoding possibly useless code
The4codeblocks Apr 28, 2025
e221eca
sensor show type
The4codeblocks Apr 28, 2025
fb5aa1f
semantic changes (water → fluid)
The4codeblocks Apr 28, 2025
329bff4
support for existing stuff for multitype
The4codeblocks Apr 28, 2025
35ab87d
a WHOLE lot
The4codeblocks Apr 28, 2025
253e1ef
fix, bad copy
The4codeblocks Apr 28, 2025
5333b2e
fix allowing fluid outs to change stored type for some reason
The4codeblocks Apr 28, 2025
2543866
last commit summary was a bit vague
The4codeblocks Apr 28, 2025
4989f96
Update pressure_logic.txt
The4codeblocks Apr 28, 2025
161f367
did that not fix? hmm
The4codeblocks Apr 28, 2025
bc4a489
oops, forgot to remove that logger
The4codeblocks Apr 29, 2025
c21f4be
oops, forgot to remove that logger
The4codeblocks Apr 29, 2025
8cc9465
multifluid source
The4codeblocks Apr 30, 2025
60fe317
check for definitions 1st
The4codeblocks Apr 30, 2025
0e6ff9e
shut luacheck up
The4codeblocks Apr 30, 2025
4d8c9c3
stop with the manually constructed vector
The4codeblocks May 7, 2025
e2c0d3f
shut luacheck up
The4codeblocks May 7, 2025
22e4522
fix crash
The4codeblocks Jun 16, 2025
42975f7
forgot a paren
The4codeblocks Jun 16, 2025
3c2ea2c
Merge branch 'master' into patch-1
The4codeblocks Aug 14, 2025
2116395
Merge branch 'master' into patch-1
The4codeblocks Dec 29, 2025
fc00172
readability
The4codeblocks Dec 30, 2025
4a6a0f3
xcompat where possible
The4codeblocks Dec 30, 2025
c254776
announce deprecation
The4codeblocks Dec 30, 2025
4890374
reduce loading baggage
The4codeblocks Dec 30, 2025
86cf653
fix styling
The4codeblocks Dec 31, 2025
b78d079
update
The4codeblocks May 13, 2026
e317ca8
fix luacheck
The4codeblocks May 13, 2026
1c5e472
translation
The4codeblocks May 13, 2026
76dedf3
more translation, tooltip
The4codeblocks May 13, 2026
e2e9cde
namespace fluid information fields, unify field name definition a little
The4codeblocks Jun 19, 2026
3faf242
Merge branch 'master' into patch-1
The4codeblocks Jul 3, 2026
5ad1804
avoid water dependency when water is absent, use dummy texture instead
The4codeblocks Jul 24, 2026
b525102
Merge remote-tracking branch 'origin/patch-1' into patch-1
The4codeblocks Jul 24, 2026
d425b96
Merge branch 'master' into patch-1
The4codeblocks Aug 1, 2026
172af76
Merge remote-tracking branch 'parent/master' into patch-1
The4codeblocks Aug 18, 2026
27d5caf
reimplement fluid crafting for autocrafter redo
The4codeblocks Aug 18, 2026
7627aee
unused local
The4codeblocks Aug 18, 2026
2b2e572
missed the translator
The4codeblocks Aug 18, 2026
be2f34a
missed the unneeded init
The4codeblocks Aug 18, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ std = "minetest+max"

globals = {
"pipeworks",
"luaentity"
"luaentity",
"core"
}

read_globals = {
Expand Down
147 changes: 107 additions & 40 deletions autocrafter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ local autocrafter_cache = {}
-- Index of group items used in recipes, self-populating when accessed
local group_index = {}

local devicename = "pipeworks:autocrafter"

local fluid_type_meta_key = "pipeworks:fluid_type"
local fluid_amount_meta_key = "pipeworks:fluid_amount"
local max_fluid_meta_key = "pipeworks:max_fluid"

----------------------
-- Helper functions --
----------------------
Expand Down Expand Up @@ -130,12 +136,26 @@ local function get_fake_player(pos)
return fake_player
end

local function get_craft_result(items, fake_player)
local function get_craft_result(items, fake_player, fluid)
local output, leftover = core.get_craft_result({method = "normal", width = 3, items = items})
output, leftover = output.item, leftover.items
local fluid_cost, leftover_fluid = nil, fluid
local is_fluid_recipe = false
if output:is_empty() then
return
if not fluid then return end
local not_enough
output, leftover, fluid_cost, leftover_fluid, not_enough = pipeworks.fluid_recipes:get({items = items}, fluid)
output, leftover = output.item, leftover.items
if not_enough then return false end
if output:is_empty() then
return
end
end

if is_fluid_recipe then
return {output}, {}, fluid_cost, leftover_fluid
end

-- Execute on_craft callbacks using a fake inventory and player
local fake_inv = fake_player:get_inventory()
fake_inv:set_list("craft", leftover)
Expand All @@ -158,7 +178,7 @@ local function get_craft_result(items, fake_player)
end
end
end
return outputs, replacements
return outputs, replacements, fluid_cost, leftover_fluid
end

local function start_autocrafter(pos)
Expand All @@ -183,21 +203,30 @@ local function set_craft(pos, recipe, output)
start_autocrafter(pos)
end

local function get_fluid(meta)
return {
amount = meta:get_float(fluid_amount_meta_key),
type = meta:get_string(fluid_type_meta_key),
}
end

local function set_craft_by_input(pos, input)
local recipe = normalize_items(input)
if not recipe then
return
end
local outputs = get_craft_result(recipe, get_fake_player(pos))
local outputs = get_craft_result(recipe, get_fake_player(pos), {type = input.fluid_type or core.get_meta(pos):get_string(fluid_type_meta_key), amount = math.huge})
if not outputs then
return
end
set_craft(pos, recipe, outputs[1])
return true
end

local function set_craft_by_output(pos, output)
local recipes = core.get_all_craft_recipes(output:get_name())
local function set_craft_by_output(pos, output, fluid_type)
local output_name = output:get_name()
local recipes = core.get_all_craft_recipes(output_name) or
fluid_type and pipeworks.fluid_recipes:get_all_with(output_name, fluid_type) or pipeworks.fluid_recipes:get_all(output_name)
if not recipes then
return
end
Expand Down Expand Up @@ -275,14 +304,52 @@ local function get_ingredients(src, recipe)
return ingredients
end

local function autocraft(inv, recipe, fake_player, keep_items)
local base_formspec = table.concat({
fs_helpers.prepends(11.5, has_digilines and 14.25 or 13.25),
fs_helpers.inv_list(1.5, has_digilines and 5.25 or 4.25, 8, 3, "src", S("Input inventory")),
fs_helpers.inv_list(1.5, 0.25, 3, 3, "recipe", S("Recipe")),
fs_helpers.inv_list(5.25, 1.5, 1, 1, "output", S("Output preview")),
"image[5.25,1.5;1,1;[combine:16x16^[noalpha^[colorize:#141318:255]",
fs_helpers.inv_list(6.5, 0.25, 4, 3, "dst", S("Crafted items")),
has_digilines and fs_helpers.field(2.75, 4.25, 7.25, "channel", S("Digiline Channel")) or "",
fs_helpers.player_inv(1.5, has_digilines and 9.25 or 8.25),
})

local tooltip_text = {
[0] = S("Output all items"),
[1] = S("Keep non-consumables"),
[2] = S("Keep all items"),
}

local function update_formspec(meta)
local keep_items = meta:get_int("keep_items")
local fluid = meta:get(fluid_type_meta_key)
local amount = meta:get_float(fluid_amount_meta_key)
local fluid_cap = meta:get_float(max_fluid_meta_key)
local bar_height = 8.25 * amount / fluid_cap
local fs = table.concat({
base_formspec,
fs_helpers.toggle_button(5.25, 0.45, meta, "enabled", true),
"image_button[5.25,2.75;1,1;pipeworks_arrow_"..keep_items..".png;keep_items;;;false;]",
"tooltip[keep_items;"..tooltip_text[keep_items].."]",
"image[0.25," .. (8.5 - bar_height) .. ";1," .. bar_height .. ";" .. (fluid and ("pipeworks_fluid_" .. fluid) or "blank") .. ".png]",
"image[0.25,0.25;1,8.25;pipeworks_fluidbar.png]",
"tooltip[0.25,0.25;1,8.25;" .. S("@1L @2", ("%d"):format(amount*1000), (pipeworks.liquids[fluid] or {description = S("Empty")}).description) .. "]",
})
meta:set_string("formspec", fs)
end

local function autocraft(inv, recipe, fake_player, keep_items, meta)
local src = inv:get_list("src")
local ingredients = get_ingredients(src, recipe)
if not ingredients then
return
end
local outputs, replacements = get_craft_result(ingredients, fake_player)
if not outputs then
local outputs, replacements, _, leftover_fluid = get_craft_result(ingredients, fake_player, get_fluid(meta))
if outputs == false then
-- Insufficient fluid, don't clear the output
return
elseif outputs == nil then
-- Broken recipe, clear the output
inv:set_stack("output", 1, "")
return
Expand All @@ -306,6 +373,8 @@ local function autocraft(inv, recipe, fake_player, keep_items)
-- Crafting was sucessful, so the modified lists can be saved
inv:set_list("src", src)
inv:set_list("dst", dst)
meta:set_float(fluid_amount_meta_key, leftover_fluid.amount)
update_formspec(meta)
return true
end

Expand Down Expand Up @@ -339,7 +408,7 @@ local function run_autocrafter(pos, elapsed)
local keep_items = meta:get_int("keep_items")
local continue = true
for _=1, math.min(crafts_remaining, batch_size) do
if not autocraft(inv, recipe, fake_player, keep_items) then
if not autocraft(inv, recipe, fake_player, keep_items, meta) then
crafts_remaining = 0
continue = false
break
Expand All @@ -357,34 +426,6 @@ local function run_autocrafter(pos, elapsed)
return continue and (enabled or crafts_remaining > 0 or queued > 0)
end

local base_formspec = table.concat({
fs_helpers.prepends(10.25, has_digilines and 14.25 or 13.25),
fs_helpers.inv_list(0.25, has_digilines and 5.25 or 4.25, 8, 3, "src", S("Input inventory")),
fs_helpers.inv_list(0.25, 0.25, 3, 3, "recipe", S("Recipe")),
fs_helpers.inv_list(4, 1.5, 1, 1, "output", S("Output preview")),
"image[4,1.5;1,1;[combine:16x16^[noalpha^[colorize:#141318:255]",
fs_helpers.inv_list(5.25, 0.25, 4, 3, "dst", S("Crafted items")),
has_digilines and fs_helpers.field(1.5, 4.25, 7.25, "channel", S("Digiline Channel")) or "",
fs_helpers.player_inv(0.25, has_digilines and 9.25 or 8.25),
})

local tooltip_text = {
[0] = S("Output all items"),
[1] = S("Keep non-consumables"),
[2] = S("Keep all items"),
}

local function update_formspec(meta)
local keep_items = meta:get_int("keep_items")
local fs = table.concat({
base_formspec,
fs_helpers.toggle_button(4, 0.45, meta, "enabled", true),
"image_button[4,2.75;1,1;pipeworks_arrow_"..keep_items..".png;keep_items;;;false;]",
"tooltip[keep_items;"..tooltip_text[keep_items].."]",
})
meta:set_string("formspec", fs)
end

local function receive_fields(pos, _, fields, player)
if (fields.quit and not fields.key_enter_field) or not pipeworks.may_configure(pos, player) then
return
Expand Down Expand Up @@ -627,7 +668,7 @@ local function digilines_action(pos, _, channel, msg)
end
end

core.register_node("pipeworks:autocrafter", {
core.register_node(devicename, {
description = S("Autocrafter"),
drawtype = "normal",
tiles = {"pipeworks_autocrafter.png"},
Expand All @@ -653,6 +694,7 @@ core.register_node("pipeworks:autocrafter", {
on_construct = function(pos)
local meta = core.get_meta(pos)
meta:set_int("keep_items", 1)
meta:set_float(max_fluid_meta_key, 8)
local inv = meta:get_inventory()
inv:set_size("src", 3 * 8)
inv:set_size("recipe", 3 * 3)
Expand Down Expand Up @@ -757,7 +799,7 @@ core.register_node("pipeworks:autocrafter", {
update_formspec(core.get_meta(pos))
end,
})
table.insert(pipeworks.ui_cat_tube_list, "pipeworks:autocrafter")
table.insert(pipeworks.ui_cat_tube_list, devicename)

----------------------
-- Group index code --
Expand Down Expand Up @@ -844,3 +886,28 @@ end

-- Use a metatable to make access cleaner
setmetatable(group_index, {__index = find_group})

-------------------------
-- Fluid functionality --
-------------------------

pipeworks.flowables.register.simple(devicename)
pipeworks.flowables.register.output(devicename, 0, 0, function(pos, node, currentpressure, finitemode, fluid_type)
if fluid_type == nil then return 0, fluid_type end
local meta = core.get_meta(pos)
local fluid_cap = meta:get_float(max_fluid_meta_key)
local fluid_amount = meta:get_float(fluid_amount_meta_key)
local current_fluid_type = meta:get(fluid_type_meta_key)
if current_fluid_type ~= fluid_type then
if fluid_amount == 0 then
meta:set_string(fluid_type_meta_key, fluid_type)
set_craft_by_input(pos, core.get_meta(pos):get_inventory():get_list("recipe"))
else
return 0, fluid_type
end
end
local taken = math.min(fluid_cap - fluid_amount, currentpressure)
meta:set_float(fluid_amount_meta_key, fluid_amount + taken)
update_formspec(meta)
return taken, fluid_type
end, function()end)
4 changes: 2 additions & 2 deletions autodetect-finite-water.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
-- enable finite liquid in the presence of dynamic liquid to preserve water volume.
-- enable finite liquid in the presence of dynamic liquid to preserve fluid volume.
local enable = false

if core.get_modpath("dynamic_liquid") then
pipeworks.logger("detected mod dynamic_liquid, enabling finite liquid flag")
enable = true
end

pipeworks.toggles.finite_water = enable
pipeworks.toggles.finite = enable
Loading