PlayerInventory & PlayerInventoryUI: You can now specify groups as materials for primitive crafting in your inventory. #34
This commit is contained in:
@@ -42,10 +42,17 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('.+::craft_item', function(play
|
|||||||
OutputStack:set_count(OutputStack:get_count() * fieldValue)
|
OutputStack:set_count(OutputStack:get_count() * fieldValue)
|
||||||
|
|
||||||
local recipeStacks = {}
|
local recipeStacks = {}
|
||||||
|
local recipeGroups = {}
|
||||||
for _, itemName in ipairs(craft.recipe) do
|
for _, itemName in ipairs(craft.recipe) do
|
||||||
local item = ItemStack(itemName)
|
|
||||||
item:set_count(item:get_count() * fieldValue)
|
local group, count = itemName:match('group:(%S+)'), itemName:match('group:%S+ (%S+)') or 1
|
||||||
table.insert(recipeStacks, item)
|
if group == nil then
|
||||||
|
local item = ItemStack(itemName)
|
||||||
|
item:set_count(item:get_count() * fieldValue)
|
||||||
|
table.insert(recipeStacks, item)
|
||||||
|
else
|
||||||
|
recipeGroups[group] = tonumber(count)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, item in ipairs(recipeStacks) do
|
for _, item in ipairs(recipeStacks) do
|
||||||
@@ -55,6 +62,28 @@ PlayerInventoryUI:registerOnFormFieldActionMatch('.+::craft_item', function(play
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local mainList = inv:get_list('main')
|
||||||
|
for group, count in pairs(recipeGroups) do
|
||||||
|
for _, item in ipairs(mainList) do
|
||||||
|
if core.get_item_group(item:get_name(), group) > 0 then
|
||||||
|
local itemCount = item:get_count()
|
||||||
|
if count > itemCount then
|
||||||
|
count = count - itemCount
|
||||||
|
table.insert(recipeStacks, item)
|
||||||
|
else
|
||||||
|
item:set_count(count)
|
||||||
|
table.insert(recipeStacks, item)
|
||||||
|
count = 0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if count > 0 then
|
||||||
|
core.chat_send_player(playerName, 'Not enough materials for crafting!')
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if inv:room_for_item('main', OutputStack) then
|
if inv:room_for_item('main', OutputStack) then
|
||||||
for _, item in ipairs(recipeStacks) do
|
for _, item in ipairs(recipeStacks) do
|
||||||
inv:remove_item('main', item)
|
inv:remove_item('main', item)
|
||||||
|
|||||||
@@ -97,3 +97,11 @@ storageFactory:registerItems({
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local PrimitiveCraftHandler = Smc.requireCraftSystemPrimitiveCraftHandler()
|
||||||
|
|
||||||
|
PrimitiveCraftHandler:registerCraft('storages:case_closed', {
|
||||||
|
recipe = {
|
||||||
|
'group:log 4'
|
||||||
|
},
|
||||||
|
output = 'storages:case_closed',
|
||||||
|
})
|
||||||
@@ -88,6 +88,7 @@ local function registerWood(name, x, def)
|
|||||||
tiles = getLogTiles(x, 2),
|
tiles = getLogTiles(x, 2),
|
||||||
paramtype2 = 'facedir',
|
paramtype2 = 'facedir',
|
||||||
_rarity = def.rarity,
|
_rarity = def.rarity,
|
||||||
|
groups = {log = 1}
|
||||||
},
|
},
|
||||||
callbacks = {
|
callbacks = {
|
||||||
on_place = core.rotate_node
|
on_place = core.rotate_node
|
||||||
|
|||||||
@@ -105,8 +105,14 @@ local function getCraftPane(self, playerName, paneType)
|
|||||||
|
|
||||||
local recipe = ''
|
local recipe = ''
|
||||||
for _, itemName in ipairs(craft.recipe) do
|
for _, itemName in ipairs(craft.recipe) do
|
||||||
local recipeItem = ItemStack(itemName)
|
local group, count = itemName:match('group:(%S+)'), itemName:match('group:%S+ (%S+)') or 1
|
||||||
recipe = recipe..'- '..core.strip_colors(recipeItem:get_definition()._title)..' x'..recipeItem:get_count()..'\n'
|
|
||||||
|
if group == nil then
|
||||||
|
local recipeItem = ItemStack(itemName)
|
||||||
|
recipe = recipe..'- '..core.strip_colors(recipeItem:get_definition()._title)..' x'..recipeItem:get_count()..'\n'
|
||||||
|
else
|
||||||
|
recipe = recipe..'- any item from the group "'..group..'" x'..count..'\n'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
CraftPane:
|
CraftPane:
|
||||||
|
|||||||
Reference in New Issue
Block a user