Change Lava Furnace Recipe API and automate UI/I3 compatibility for its recipes

This commit is contained in:
Zenon Seth 2024-03-16 11:50:24 +00:00
parent 71ae67c91f
commit e292c3be57
4 changed files with 64 additions and 79 deletions

View File

@ -1,30 +1,31 @@
local lava_furance_recipes = {}
local NORMAL_COOK_LAVA_USAGE_PER_SEC = 5 -- in millibuckets
local NORMAL_COOK_LAVA_USAGE_PER_SEC = 2 -- in millibuckets
local NORMAL_COOK_REDUCTION_FACTOR = 2
local MIN_TIME = 0.5
--[[
The Lava Furnace recipes format is indexed for item stack.<br>
`name`: The input item
`def`: A table in the following format:
{
input = "input_name", -- required, a string of the input stack needed in the input slot
input_count = N, -- optional; how many of the input items are needed
output = "item_name N", -- the result of the crystalization
lava = 1000, -- how much lava is consumed. 1000 units = 1 bucket
output = "item_name N", -- required, the result of the crystalization
lava = 1000, -- required, how much lava is consumed. 1000 units = 1 bucket
additive = "item_name N", -- optional; the additive that is required to be present for this recipe
additive_use_chance = 100, -- optional; the chance that the additive will be consumed (0 = never, 100 = always)
time = 10, -- approximate time, in seconds, this recipe takes to complete, min is defined by MIN_TIME (or 1sec in practice)
time = 10, -- required, approximate time, in seconds, this recipe takes to complete, min is defined by MIN_TIME (or 1sec in practice)
}
]]
function logistica.register_lava_furnace_recipe(name, def)
if not name or not def or not def.output or not def.lava or not def.time then
function logistica.register_lava_furnace_recipe(def)
if not def or not def.input or not def.output or not def.lava or not def.time then
return
end
local useChance = (def.additive_use_chance ~= nil and logistica.clamp(def.additive_use_chance, 0, 100)) or 100
lava_furance_recipes[name] = lava_furance_recipes[name] or {}
table.insert(lava_furance_recipes[name], {
lava_furance_recipes[def.input] = lava_furance_recipes[def.input] or {}
table.insert(lava_furance_recipes[def.input], {
input = def.input,
input_count = def.input_count or 1,
output = def.output,
lava = math.max(1, def.lava),

View File

@ -1,40 +1,30 @@
if minetest.global_exists("i3") then
local L = function(str) return "logistica:"..str end
i3.register_craft_type("logisticalavafurnace", {
description = "Lava Furnace [logistica]",
icon = "logistica_lava_furnace_front_off.png",
width = 2,
height = 1,
})
i3.register_craft({
items = {"default:silver_sand", "default:ice"},
result = L("silverin"),
type = "logisticalavafurnace"
})
local function init_i3_compat()
local lavaFurnaceRecipes = logistica.get_lava_furnace_internal_recipes()
i3.register_craft({
items = {L("silverin"), "default:steel_ingot"},
result = L("silverin_plate 4"),
type = "logisticalavafurnace"
})
i3.register_craft({
items = {L("silverin_slice"), "default:mese_crystal_fragment"},
result = L("silverin_circuit"),
type = "logisticalavafurnace"
})
i3.register_craft({
items = {"default:glass", L("silverin_slice 6")},
result = L("silverin_mirror_box"),
type = "logisticalavafurnace"
})
i3.register_craft({
items = {L("silverin"), "default:mese_crystal"},
result = L("wireless_crystal"),
type = "logisticalavafurnace"
})
for _, recipes in pairs(lavaFurnaceRecipes) do
for _, recipe in pairs(recipes) do
local items = {}
table.insert(items, recipe.additive)
table.insert(items, recipe.input.." "..tostring(recipe.input_count))
i3.register_craft({
items = items,
result = recipe.output,
type = "logisticalavafurnace"
})
end
end
end
minetest.register_on_mods_loaded(function()
init_i3_compat()
end)
end

View File

@ -1,42 +1,31 @@
if minetest.global_exists("unified_inventory") then
unified_inventory.register_craft_type("logisticalavafurnace", {
description = "Lava Furnace [logistica]",
icon = "logistica_lava_furnace_front_off.png",
width = 2,
height = 1,
})
local L = function(str) return "logistica:"..str end
unified_inventory.register_craft_type("logisticalavafurnace", {
description = "Lava Furnace [logistica]",
icon = "logistica_lava_furnace_front_off.png",
width = 2,
height = 1,
})
local function init_unified_inv_compat()
local lavaFurnaceRecipes = logistica.get_lava_furnace_internal_recipes()
unified_inventory.register_craft({
items = {"default:silver_sand", "default:ice"},
output = L("silverin"),
type = "logisticalavafurnace"
})
for _, recipes in pairs(lavaFurnaceRecipes) do
for _, recipe in pairs(recipes) do
local items = {}
table.insert(items, recipe.input.." "..tostring(recipe.input_count))
table.insert(items, recipe.additive)
unified_inventory.register_craft({
items = items,
output = recipe.output,
type = "logisticalavafurnace"
})
end
end
end
unified_inventory.register_craft({
items = {L("silverin"), "default:steel_ingot"},
output = L("silverin_plate 4"),
type = "logisticalavafurnace"
})
unified_inventory.register_craft({
items = {L("silverin_slice"), "default:mese_crystal_fragment"},
output = L("silverin_circuit"),
type = "logisticalavafurnace"
})
unified_inventory.register_craft({
items = {"default:glass", L("silverin_slice 6")},
output = L("silverin_mirror_box"),
type = "logisticalavafurnace"
})
unified_inventory.register_craft({
items = {L("silverin"), "default:mese_crystal"},
output = L("wireless_crystal"),
type = "logisticalavafurnace"
})
minetest.register_on_mods_loaded(function()
init_unified_inv_compat()
end)
end

View File

@ -1,7 +1,8 @@
local itemstrings = logistica.itemstrings
local L = function(str) return "logistica:"..str end
logistica.register_lava_furnace_recipe(itemstrings.sand, {
logistica.register_lava_furnace_recipe({
input = itemstrings.sand,
output = L("silverin"),
lava = 25,
additive = itemstrings.ice,
@ -9,7 +10,8 @@ logistica.register_lava_furnace_recipe(itemstrings.sand, {
time = 2.5
})
logistica.register_lava_furnace_recipe(L("silverin"), {
logistica.register_lava_furnace_recipe({
input = L("silverin"),
output = L("silverin_plate 4"),
lava = 50,
additive = itemstrings.steel,
@ -17,7 +19,8 @@ logistica.register_lava_furnace_recipe(L("silverin"), {
time = 5
})
logistica.register_lava_furnace_recipe(L("silverin_slice"), {
logistica.register_lava_furnace_recipe({
input = L("silverin_slice"),
output = L("silverin_circuit"),
lava = 60,
additive = itemstrings.fragment,
@ -25,7 +28,8 @@ logistica.register_lava_furnace_recipe(L("silverin_slice"), {
time = 10
})
logistica.register_lava_furnace_recipe(itemstrings.glass, {
logistica.register_lava_furnace_recipe({
input = itemstrings.glass,
output = L("silverin_mirror_box"),
lava = 50,
additive = L("silverin_slice 6"),
@ -33,7 +37,8 @@ logistica.register_lava_furnace_recipe(itemstrings.glass, {
time = 4
})
logistica.register_lava_furnace_recipe(L("silverin"), {
logistica.register_lava_furnace_recipe({
input = L("silverin"),
output = L("wireless_crystal"),
lava = 60,
additive = itemstrings.crystal,