1
0
mirror of https://github.com/mt-mods/pipeworks.git synced 2025-05-11 21:30:22 +02:00

only whitespace changes

This commit is contained in:
Luke aka SwissalpS 2023-06-15 02:46:11 +02:00
parent 2f70be2d90
commit 9be6239ec5

View File

@ -49,7 +49,8 @@ local function calculate_consumption(inv_index, consumption_with_groups)
local groups = {} local groups = {}
-- First consume all non-group requirements -- First consume all non-group requirements
-- This is done to avoid consuming a non-group item which is also in a group -- 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 for key, count in pairs(consumption_with_groups) do
if key:sub(1, 6) == "group:" then if key:sub(1, 6) == "group:" then
groups[#groups + 1] = key:sub(7, #key) groups[#groups + 1] = key:sub(7, #key)
@ -73,7 +74,7 @@ local function calculate_consumption(inv_index, consumption_with_groups)
if count > 0 then if count > 0 then
local def = minetest.registered_items[itemname] local def = minetest.registered_items[itemname]
local item_groups = def and def.groups or {} local item_groups = def and def.groups or {}
for i=1, #groups do for i = 1, #groups do
local group = groups[i] local group = groups[i]
local groupname = "group:" .. group local groupname = "group:" .. group
if item_groups[group] >= 1 and consumption_with_groups[groupname] > 0 then if item_groups[group] >= 1 and consumption_with_groups[groupname] > 0 then
@ -101,6 +102,7 @@ end
local function autocraft(inventory, craft) local function autocraft(inventory, craft)
if not craft then return false end if not craft then return false end
-- check if output and all replacements fit in dst -- check if output and all replacements fit in dst
local output = craft.output.item local output = craft.output.item
local out_items = count_index(craft.decremented_input.items) local out_items = count_index(craft.decremented_input.items)
@ -124,12 +126,14 @@ local function autocraft(inventory, craft)
if empty_count < 0 then if empty_count < 0 then
return false return false
end end
-- check if we have enough material available -- check if we have enough material available
local inv_index = count_index(inventory:get_list("src")) local inv_index = count_index(inventory:get_list("src"))
local consumption = calculate_consumption(inv_index, craft.consumption) local consumption = calculate_consumption(inv_index, craft.consumption)
if not consumption then if not consumption then
return false return false
end end
for itemname, number in pairs(consumption) do for itemname, number in pairs(consumption) do
if (not inv_index[itemname]) or inv_index[itemname] < number then return false end if (not inv_index[itemname]) or inv_index[itemname] < number then return false end
end end
@ -161,7 +165,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
@ -251,7 +255,8 @@ 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
@ -263,46 +268,46 @@ local function update_meta(meta, enabled)
local list_backgrounds = "" local list_backgrounds = ""
if minetest.get_modpath("i3") then if minetest.get_modpath("i3") 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;" .. 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")..";${channel}]".. fs = fs .. "field[0.22,4.1;4.5,0.75;channel;" .. S("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
@ -360,8 +365,8 @@ minetest.register_node("pipeworks:autocrafter", {
description = S("Autocrafter"), description = S("Autocrafter"),
drawtype = "normal", drawtype = "normal",
tiles = {"pipeworks_autocrafter.png"}, tiles = {"pipeworks_autocrafter.png"},
groups = {snappy = 3, tubedevice = 1, tubedevice_receiver = 1, dig_generic = 1, axey=5}, groups = {snappy = 3, tubedevice = 1, tubedevice_receiver = 1, dig_generic = 1, axey = 5},
_mcl_hardness=1.6, _mcl_hardness = 1.6,
tube = {insert_object = function(pos, node, stack, direction) tube = {insert_object = function(pos, node, stack, direction)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
@ -379,9 +384,9 @@ minetest.register_node("pipeworks:autocrafter", {
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,
@ -490,13 +495,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(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
@ -505,11 +510,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("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
@ -536,4 +541,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"