chore: change plural item forms to match mc

E.g. "ingots" to "ingot"
This commit is contained in:
Emerson Rosen-Jones 2026-01-17 16:58:10 -05:00
parent bcb70f8780
commit 367744fdd6

View file

@ -107,7 +107,7 @@ function craft_multiple (requester, item_type, conversion_type, count)
end end
function execute_crafts (requester, item_type, crafts) function execute_crafts (requester, item_type, crafts)
local num_crafts = crafts.nuggets local num_crafts = crafts.nugget
if num_crafts > 0 then if num_crafts > 0 then
print(("Crafting %s nuggets"):format(item_type)) print(("Crafting %s nuggets"):format(item_type))
craft_multiple(item_type, 4, num_crafts) craft_multiple(item_type, 4, num_crafts)
@ -115,7 +115,7 @@ function execute_crafts (requester, item_type, crafts)
print(("Crafting %s ingots"):format(item_type)) print(("Crafting %s ingots"):format(item_type))
craft_multiple(item_type, 1, -num_crafts) craft_multiple(item_type, 1, -num_crafts)
end end
num_crafts = crafts.blocks num_crafts = crafts.block
if num_crafts > 0 then if num_crafts > 0 then
print(("Crafting %s blocks"):format(item_type)) print(("Crafting %s blocks"):format(item_type))
craft_multiple(requester, item_type, 2, num_crafts) craft_multiple(requester, item_type, 2, num_crafts)
@ -141,12 +141,12 @@ function sum_items (inv_f)
end end
function dist_to_num (dist) function dist_to_num (dist)
return dist.nuggets + dist.ingots * INGOTS + dist.blocks * BLOCKS return dist.nugget + dist.ingot * INGOTS + dist.block * BLOCKS
end end
function get_dist (item_type, items) function get_dist (item_type, items)
-- TODO change plurals to singulars to match mc -- TODO change plurals to singulars to match mc
local dist = { nuggets = 0, ingots = 0, blocks = 0 } local dist = { nugget = 0, ingot = 0, block = 0 }
for item, count in pairs(items) do for item, count in pairs(items) do
local type, form = item:match":(%l-)_(%l*)" local type, form = item:match":(%l-)_(%l*)"
form = string.format("%ss", form) form = string.format("%ss", form)
@ -158,42 +158,42 @@ function get_dist (item_type, items)
end end
function decide_dist (num) function decide_dist (num)
local dist = { nuggets = 0, ingots = 0, blocks = 0 } local dist = { nugget = 0, ingot = 0, block = 0 }
if num > MAX_NUM then if num > MAX_NUM then
local excess = num - MAX_NUM local excess = num - MAX_NUM
dist.blocks = math.floor(excess / BLOCKS) dist.block = math.floor(excess / BLOCKS)
num = num - (dist.blocks * BLOCKS) num = num - (dist.block * BLOCKS)
end end
local balance = math.floor(num / 10) local balance = math.floor(num / 10)
dist.nuggets, dist.ingots = balance, balance dist.nugget, dist.ingot = balance, balance
num = num - (balance * 10) num = num - (balance * 10)
dist.nuggets = dist.nuggets + num dist.nugget = dist.nugget + num
return dist return dist
end end
function get_diff (dist1, dist2) function get_diff (dist1, dist2)
return { return {
nuggets = dist1.nuggets - dist2.nuggets, nugget = dist1.nugget - dist2.nugget,
ingots = dist1.ingots - dist2.ingots, ingot = dist1.ingot - dist2.ingot,
blocks = dist1.blocks - dist2.blocks block = dist1.block - dist2.block
} }
end end
function filter_clamp (diff, current_dist) function filter_clamp (diff, current_dist)
-- reduce diff numbers to what can be crafted using current resources -- reduce diff numbers to what can be crafted using current resources
if diff.blocks > 0 then if diff.block > 0 then
diff.blocks = math.min( diff.block = math.min(
diff.blocks - (diff.blocks % BLOCK_RATIO), diff.block - (diff.block % BLOCK_RATIO),
math.floor(current_dist.ingots / 9) math.floor(current_dist.ingot / 9)
) )
end end
if diff.nuggets > 0 then if diff.nugget > 0 then
diff.nuggets = math.min( diff.nugget = math.min(
diff.nuggets - (diff.nuggets % NUGGET_RATIO), diff.nugget - (diff.nugget % NUGGET_RATIO),
current_dist.ingots * 9 current_dist.ingot * 9
) )
end end
diff.ingots = (-diff.nuggets / 9) + (-diff.blocks * 9) diff.ingot = (-diff.nugget / 9) + (-diff.block * 9)
return diff return diff
end end
@ -201,8 +201,8 @@ function diff_to_crafts (diff)
-- go from one end e.g. nuggets to the other e.g. blocks, removing -- go from one end e.g. nuggets to the other e.g. blocks, removing
-- from the diff to create crafts until the diff is empty -- from the diff to create crafts until the diff is empty
local crafts = {} local crafts = {}
crafts.nuggets = math.floor(diff.nuggets / NUGGET_RATIO) crafts.nugget = math.floor(diff.nugget / NUGGET_RATIO)
crafts.blocks = math.floor(diff.blocks / BLOCK_RATIO) crafts.block = math.floor(diff.block / BLOCK_RATIO)
return crafts return crafts
end end