This commit is contained in:
Brevven 2025-01-01 04:30:31 -08:00
parent 682b86d641
commit e294b3d5c3
2 changed files with 54 additions and 13 deletions

View file

@ -3,6 +3,7 @@ local me = require("me")
local util = {} local util = {}
util.me = me util.me = me
local regenerate_command = "bz-regenerate" local regenerate_command = "bz-regenerate"
local list_command = "bz-list"
function decode(data) function decode(data)
if type(data) == "string" then return data end if type(data) == "string" then return data end
@ -27,8 +28,8 @@ function util.check_fluid_mining()
end end
end end
function util.get_list() function get_list()
local p = game.item_prototypes[me.name.."-list"] local p = prototypes.item[me.name.."-list"]
if p then if p then
data = p.localised_description data = p.localised_description
return decode(data) return decode(data)
@ -41,6 +42,30 @@ function util.force_enable_recipe(event, recipe_name)
end end
end end
function list(event)
if event.command and string.lower(event.command) == "bz-list" then
local player = game.players[event.player_index]
if player and player.connected then
local list = get_list()
if list and #list>0 then
local filename = util.me.name..".txt"
helpers.write_file(filename, list, false, event.player_index)
player.print("Wrote recipes to script-output/"..filename)
else
player.print("Please change your mod startup setting for this mod's modified recipes list.")
end
end
end
end
function util.add_list_command_handler()
script.on_event(defines.events.on_console_command, list)
if not commands.commands[list_command] then
commands.add_command(list_command, "", function() end)
end
end
function util.warptorio2_expansion_helper() function util.warptorio2_expansion_helper()
if script.active_mods["warptorio2_expansion"] then if script.active_mods["warptorio2_expansion"] then
@ -96,7 +121,7 @@ function util.warptorio2_expansion_helper()
end end
end end
local usage = [[ local usage_regenerate = [[
Usage: /bz-regenerate all Usage: /bz-regenerate all
or /bz-regenerate <planet> <resource> [<frequency> <size> <richness>] or /bz-regenerate <planet> <resource> [<frequency> <size> <richness>]
planet must be an internal name like nauvis planet must be an internal name like nauvis
@ -108,15 +133,17 @@ Regenerates ore patches. If frequency/size/richness are provided, the planet wil
- Ores can sometimes overlap on regeneration. - Ores can sometimes overlap on regeneration.
]] ]]
function util.add_regenerate_command_handler() function util.add_regenerate_command_handler()
log("I am here ".. util.me.name)
script.on_event(defines.events.on_console_command, regenerate_ore) script.on_event(defines.events.on_console_command, regenerate_ore)
if not commands.commands[regenerate_command] then if not commands.commands[regenerate_command] then
commands.add_command( regenerate_command, usage, function() end) commands.add_command( regenerate_command, usage_regenerate, function() end)
end end
end end
function regenerate_ore(event) function regenerate_ore(event)
if event.command == regenerate_command then if event.command == regenerate_command then
game.print("I am trying ".. util.me.name)
local params = {} local params = {}
for w in event.parameters:gmatch("%S+") do table.insert(params, w) end for w in event.parameters:gmatch("%S+") do table.insert(params, w) end
if #params == 1 and params[1] == "all" then if #params == 1 and params[1] == "all" then
@ -127,11 +154,12 @@ function regenerate_ore(event)
return return
end end
if not (#params == 2 or #params == 5) then if not (#params == 2 or #params == 5) then
game.print(usage) game.print(usage_regenerate)
return return
end end
local planet = params[1] local planet = params[1]
for _, resource in pairs(me.resources) do for _, resource in pairs(me.resources) do
game.print("I am trying ".. util.me.name .. " " .. resource)
if not game.surfaces[planet] then if not game.surfaces[planet] then
game.print("Could not find surface for "..planet..". May not exist, or may not yet be explored.") game.print("Could not find surface for "..planet..". May not exist, or may not yet be explored.")
return return

View file

@ -165,6 +165,17 @@ function util.use_fluid_mining_final()
end end
end end
-- If Hot metals mod is enabled, mark these metals as hot
function util.add_hot_metals(metals)
if HotMetals and HotMetals.items then
for _, metal in pairs(metals) do
if data.raw.item[metal] or (metal.name and data.raw.item[metal.name]) then
table.insert(HotMetals.items, metal)
end
end
end
end
-- se landfill -- se landfill
-- params: ore, icon_size -- params: ore, icon_size
@ -770,8 +781,8 @@ end
-- set the probability of a product. -- set the probability of a product.
function util.set_product_probability(recipe_name, product, probability, options) function util.set_product_probability(recipe_name, product, probability, options)
if not should_force(options) and bypass(recipe_name) then return end if not should_force(options) and bypass(recipe_name) then return end
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
set_product_probability(data.raw.recipe[recipe_name], product, probability) set_product_probability(data.raw.recipe[recipe_name], product, probability)
end end
end end
@ -791,8 +802,8 @@ end
-- set the amount of a product. -- set the amount of a product.
function util.set_product_amount(recipe_name, product, amount, options) function util.set_product_amount(recipe_name, product, amount, options)
if not should_force(options) and bypass(recipe_name) then return end if not should_force(options) and bypass(recipe_name) then return end
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
set_product_amount(data.raw.recipe[recipe_name], product, amount) set_product_amount(data.raw.recipe[recipe_name], product, amount)
end end
end end
@ -823,8 +834,8 @@ end
-- multiply the cost, energy, and results of a recipe by a multiple -- multiply the cost, energy, and results of a recipe by a multiple
function util.multiply_recipe(recipe_name, multiple, options) function util.multiply_recipe(recipe_name, multiple, options)
if not should_force(options) and bypass(recipe_name) then return end if not should_force(options) and bypass(recipe_name) then return end
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
multiply_recipe(data.raw.recipe[recipe_name], multiple) multiply_recipe(data.raw.recipe[recipe_name], multiple)
end end
end end
@ -889,8 +900,8 @@ end
-- Remove a product from a recipe, WILL NOT remove the only product -- Remove a product from a recipe, WILL NOT remove the only product
function util.remove_product(recipe_name, old, options) function util.remove_product(recipe_name, old, options)
if not should_force(options) and bypass(recipe_name) then return end if not should_force(options) and bypass(recipe_name) then return end
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
remove_product(data.raw.recipe[recipe_name], old) remove_product(data.raw.recipe[recipe_name], old)
end end
end end
@ -967,8 +978,8 @@ end
-- Set energy required -- Set energy required
function util.set_recipe_time(recipe_name, time, options) function util.set_recipe_time(recipe_name, time, options)
if not should_force(options) and bypass(recipe_name) then return end if not should_force(options) and bypass(recipe_name) then return end
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
set_recipe_time(data.raw.recipe[recipe_name], time) set_recipe_time(data.raw.recipe[recipe_name], time)
end end
end end
@ -984,8 +995,8 @@ end
-- Multiply energy required -- Multiply energy required
function util.multiply_time(recipe_name, factor, options) function util.multiply_time(recipe_name, factor, options)
if not should_force(options) and bypass(recipe_name) then return end if not should_force(options) and bypass(recipe_name) then return end
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
multiply_time(data.raw.recipe[recipe_name], factor) multiply_time(data.raw.recipe[recipe_name], factor)
end end
end end
@ -1001,8 +1012,8 @@ end
-- Add to energy required -- Add to energy required
function util.add_time(recipe_name, amount, options) function util.add_time(recipe_name, amount, options)
if not should_force(options) and bypass(recipe_name) then return end if not should_force(options) and bypass(recipe_name) then return end
me.add_modified(recipe_name)
if data.raw.recipe[recipe_name] then if data.raw.recipe[recipe_name] then
me.add_modified(recipe_name)
add_time(data.raw.recipe[recipe_name], amount) add_time(data.raw.recipe[recipe_name], amount)
end end
end end
@ -1243,7 +1254,9 @@ function util.create_list()
icon = "__core__/graphics/empty.png", icon = "__core__/graphics/empty.png",
icon_size = 1, icon_size = 1,
stack_size = 1, stack_size = 1,
flags = {"hidden", "hide-from-bonus-gui"} hidden = true,
hidden_in_factoriopedia = true,
flags = {"hide-from-bonus-gui"}
}}) }})
end end