Skip to content

Commit

Permalink
Fixed #10
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePython10110 committed Dec 25, 2023
1 parent b21c182 commit 1842926
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 18 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ Dependencies: Minetest Game or MineClone.
* Test everything in MTG, MCL2, and MCLA (and 5.7)
* Everything breaks properly in MTG
* Fix Tmcl_banners thing
* Fix Technic Beta
* Check for MCL coral groups

### v6.0 (The Compatibility Update)

Expand Down
43 changes: 29 additions & 14 deletions exchangeclone/register_energy.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- Calculates the cheapest recipe given an itemstring.
-- Would probably benefit from another function, since there's quite a bit
-- of duplicate code.

local function get_cheapest_recipe(itemstring, log)
itemstring = ItemStack(itemstring):get_name()
local recipes = exchangeclone.recipes[itemstring]
Expand Down Expand Up @@ -101,7 +102,7 @@ local function get_cheapest_recipe(itemstring, log)
cheapest = {total_cost, recipe}
end
end
if log then minetest.log(dump({
if log then minetest.log("action", dump({
recipe = recipe,
ingredient_cost = ingredient_cost,
output_count = output_count
Expand Down Expand Up @@ -144,18 +145,6 @@ end

local auto = {}

-- Register group energy values
local groupnames = {}
for index, group in ipairs(exchangeclone.group_values) do
groupnames[#groupnames + 1] = group[1] --Get list of group names
end
local grouped_items = exchangeclone.get_group_items(groupnames, true, true)
for index, group in ipairs(exchangeclone.group_values) do
for i, item in pairs(grouped_items[group[1]]) do
set_item_energy(item, group[2])
end
end

-- Handle stonecutter recipes and decaychains in Mineclonia
if exchangeclone.mcla then
exchangeclone.register_craft_type("stonecutting", "cooking")
Expand Down Expand Up @@ -338,7 +327,33 @@ end
for itemstring, recipes in pairs(exchangeclone.recipes) do
local new_name = ItemStack(itemstring):get_name()
if new_name and new_name ~= "" and new_name ~= itemstring then
exchangeclone.recipes[new_name] = recipes
exchangeclone.recipes[new_name] = exchangeclone.recipes[new_name] or {}
for _, recipe in pairs(recipes) do
table.insert(exchangeclone.recipes[new_name], recipe)
end
end
end





-- Up to this point, no energy values have been registered.
-- Now, they will be.





-- Register group energy values
local groupnames = {}
for index, group in ipairs(exchangeclone.group_values) do
groupnames[#groupnames + 1] = group[1] --Get list of group names
end
local grouped_items = exchangeclone.get_group_items(groupnames, true, true)
for index, group in ipairs(exchangeclone.group_values) do
for i, item in pairs(grouped_items[group[1]]) do
set_item_energy(item, group[2])
end
end

Expand Down
7 changes: 4 additions & 3 deletions zzzz_exchangeclone_init/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,15 @@ function exchangeclone.register_craft(data)
local itemstring = ItemStack(data.output):get_name()
exchangeclone.recipes[itemstring] = exchangeclone.recipes[itemstring] or {}
table.insert(exchangeclone.recipes[itemstring], table.copy(data))
-- Should reversed recipe be registered too?
if data.type then
local type_data = exchangeclone.craft_types[data.type]
if type_data.type == "cooking" and type_data.reverse then
local flipped_data = table.copy(data)
flipped_data.output, flipped_data.recipe = flipped_data.recipe, flipped_data.output
local itemstring = ItemStack(flipped_data.output):get_name()
exchangeclone.recipes[itemstring] = exchangeclone.recipes[itemstring] or {}
table.insert(exchangeclone.recipes[itemstring], table.copy(flipped_data))
local flipped_output = ItemStack(flipped_data.output):get_name()
exchangeclone.recipes[flipped_output] = exchangeclone.recipes[flipped_output] or {}
table.insert(exchangeclone.recipes[flipped_output], table.copy(flipped_data))
end
end
end
Expand Down

0 comments on commit 1842926

Please sign in to comment.