Merge branch 'automatic-energy-values' into dev

This commit is contained in:
ThePython 2023-11-07 18:13:38 -08:00
commit 37d30ebe65
10 changed files with 1339 additions and 1504 deletions

View File

@ -56,6 +56,7 @@ Dependencies: Minetest Game or MineClone.
### 6.0
* New Features:
* Automatically generated energy values! Based on crafting and cooking recipes.
* Infinite food (costs 64 energy to use, equal to steak)
* Alchemical Chest
* Repair Talisman (maybe, would only work in Alchemical Chest)
@ -63,6 +64,9 @@ Dependencies: Minetest Game or MineClone.
* Mind, Life, Body, and Soul Stones (although MTG only has the soul stone).
* Mercurial Eye (maybe)
* Changes:
* ExchangeClone is now a modpack for [annoying reasons](https://forum.minetest.net/viewtopic.php?f=47&p=429775s). *Every single mod* in the modpack is required, regardless of what it says the dependencies are. Disable and then enable it for everything to work correctly.
* The default energy value is no longer 1 but none.
* The 2-billion-ish personal energy limit is has been increased to the actual maximum Lua allows. This may mean some precision is lost when your personal energy reaches a few quadrillion... but that's unlikely to happen, and at that point, it probably doesn't matter, so I'm not testing it.
* Tools that break multiple nodes at once (hammer, hoe, pickaxe, morningstar, and katar) use a better method that may (?) slightly decrease lag.
* Ender pearls can now be crafted with 4 iron and the Philosopher's Stone.
* A couple changes the Philosopher's Stone's transmutation:

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
name = _exchangeclone_energy
title = ExchangeClone Energy
depends = exchangeclone
optional_depends = 3d_armor, mcl_item_id, mcl_core, default, moreswords, mcl_stairs, meat_blocks, sticky_things, fake_liquids, sound_machine, stairs, mcl_dispensers, farming, mobs_mc, screwdriver
depends = exchangeclone, zzzz_exchangeclone_crafthook
optional_depends = 3d_armor, mcl_item_id, mcl_core, default, moreswords, mcl_stairs, meat_blocks, sticky_things, fake_liquids, sound_machine, stairs, mcl_dispensers, farming, mobs_mc, screwdriver, _mcl_autogroup

View File

@ -106,7 +106,7 @@ local function constructor_action(pos)
current_energy = exchangeclone.get_player_energy(player)
end
local energy_value = exchangeclone.get_item_energy(src_stack:get_name())
if energy_value > 0 then
if energy_value and energy_value > 0 then
local max_amount = math.min(src_stack:get_stack_max(), math.floor(current_energy/energy_value))
local added_amount = max_amount - inv:add_item("dst", ItemStack(result.." "..max_amount)):get_count()
local result_energy = math.min(current_energy, current_energy - (energy_value * added_amount)) -- not sure if "math.min()" is necessary

View File

@ -69,7 +69,7 @@ local function deconstructor_action(pos)
end
local stack = inv:get_stack("src", 1)
local individual_energy_value = exchangeclone.get_item_energy(stack:get_name())
if individual_energy_value <= 0 then return end
if individual_energy_value and individual_energy_value <= 0 then return end
local wear = stack:get_wear()
if wear and wear > 1 then
individual_energy_value = math.floor(individual_energy_value * (65536 / wear))

View File

@ -13,25 +13,38 @@ function exchangeclone.get_inventory_drops(pos, inventory, drops) --removes defa
end
end
-- Gets the energy value from an itemstring or itemstack
function exchangeclone.get_item_energy(item)
if not item then return end
if type(item) == "string" and item:sub(1,6) == "group:" and exchangeclone.group_values then
local item_group = item:sub(7,-1)
for _, group in ipairs(exchangeclone.group_values) do
if item_group == group[1] then return group[2] end
end
return
local group_items = exchangeclone.get_group_items(item_group)
local cheapest
for _, group_item in ipairs(group_items[item_group]) do
if group_item then
local energy_value = exchangeclone.get_item_energy(group_item)
if energy_value then
if energy_value > 0 and ((not cheapest) or energy_value < cheapest) then
cheapest = energy_value
end
end
end
end
return cheapest
end
item = ItemStack(item)
local def = minetest.registered_items[item:get_name()]
if not def then return -1 end
if not def then return 0 end
if item:get_name() == "exchangeclone:exchange_orb" then
return (def.energy_value or 0) + exchangeclone.get_orb_itemstack_energy(item)
return def.energy_value or 0 + exchangeclone.get_orb_itemstack_energy(item)
end
if def.energy_value then
return (def.energy_value) * item:get_count()
else
return
end
return -1
end
-- Rounds to the nearest integer
@ -51,8 +64,8 @@ end
-- Gets the energy stored in a specified exchange_orb itemstack.
function exchangeclone.get_orb_itemstack_energy(itemstack)
if not itemstack then return 0 end
if itemstack:get_name() ~= "exchangeclone:exchange_orb" then return 0 end
if not itemstack then return end
if itemstack:get_name() ~= "exchangeclone:exchange_orb" then return end
return itemstack:get_meta():get_float("stored_energy") or 0
end
@ -66,7 +79,7 @@ function exchangeclone.get_orb_energy(inventory, listname, index)
end
-- Decides what mod to use for sounds
if default then exchangeclone.sound_mod = default else exchangeclone.sound_mod = mcl_sounds end
if exchangeclone.mcl then exchangeclone.sound_mod = mcl_sounds else exchangeclone.sound_mod = default end
-- Sets the amount of energy in an orb in a specific inventory slot
function exchangeclone.set_orb_energy(inventory, listname, index, amount)
@ -75,7 +88,7 @@ function exchangeclone.set_orb_energy(inventory, listname, index, amount)
if not index then index = 1 end
local itemstack = inventory:get_stack(listname, index)
if not itemstack then return end
if not (itemstack:get_name() and itemstack:get_name() == "exchangeclone:exchange_orb") then return end
if itemstack:get_name() ~= "exchangeclone:exchange_orb" then return end
local old_energy = exchangeclone.get_orb_itemstack_energy(itemstack)
if amount > old_energy and old_energy > exchangeclone.orb_max then return end -- don't allow more energy to be put into an over-filled orb

View File

@ -73,7 +73,7 @@ local function pickaxe_on_use(itemstack, player, pointed_thing)
elseif itemstack:get_name():find("red") then
local player_energy = exchangeclone.get_player_energy(player)
torch_on_place(ItemStack(torch_itemstring), player, pointed_thing)
exchangeclone.set_player_energy(player, player_energy - math.max(exchangeclone.get_item_energy(torch_itemstring), 8))
exchangeclone.set_player_energy(player, player_energy - math.max(exchangeclone.get_item_energy(torch_itemstring) or 0, 8))
-- If the torch could not be placed, it still costs energy... not sure how to fix that
end
exchangeclone.start_cooldown(player, "pickaxe", 0.3)

View File

@ -189,7 +189,7 @@ local function morningstar_on_use(itemstack, player, pointed_thing)
else
local player_energy = exchangeclone.get_player_energy(player)
torch_on_place(ItemStack(torch_itemstring), player, pointed_thing)
exchangeclone.set_player_energy(player, player_energy - exchangeclone.get_item_energy(torch_itemstring))
exchangeclone.set_player_energy(player, player_energy - math.max(exchangeclone.get_item_energy(torch_itemstring) or 0, 8))
-- If the torch could not be placed, it still costs energy... not sure how to fix that
exchangeclone.start_cooldown(player, "pickaxe", 0.3)
return

View File

@ -55,7 +55,7 @@ function exchangeclone.reload_transmutation_list(player, search)
end
for _, item in ipairs(items_to_show) do
local energy_value = exchangeclone.get_item_energy(item)
if energy_value <= player_energy and energy_value > 0 then
if energy_value and energy_value <= player_energy and energy_value > 0 then
page_num = math.floor(i/16) + 1
if not pages[page_num] then pages[page_num] = {} end
pages[page_num][(i % 16) + 1] = item
@ -70,6 +70,7 @@ local function add_to_output(player, amount, show)
local item = player:get_meta():get_string("exchangeclone_transmutation_selection")
if minetest.registered_items[item] then
local energy_value = exchangeclone.get_item_energy(item)
if not energy_value then return end
local player_energy = exchangeclone.get_player_energy(player)
local stack_max = ItemStack(item):get_stack_max()
if amount == true then amount = stack_max end
@ -89,7 +90,8 @@ local function handle_inventory(player, inventory, to_list)
list = {}
local i = 0
for name, def in pairs(minetest.registered_items) do
if exchangeclone.get_item_energy(name) > 0 and not def.groups.not_in_creative_inventory then
local energy_value = exchangeclone.get_item_energy(name)
if energy_value and energy_value > 0 and not def.groups.not_in_creative_inventory then
i = i + 1
list[i] = name
end
@ -99,7 +101,7 @@ local function handle_inventory(player, inventory, to_list)
inventory:set_stack(to_list, 1, nil)
else
local individual_energy_value = exchangeclone.get_item_energy(stack:get_name())
if individual_energy_value <= 0 then return end
if not individual_energy_value or individual_energy_value <= 0 then return end
local wear = stack:get_wear()
if wear and wear > 1 then
individual_energy_value = math.floor(individual_energy_value * (65536 / wear))
@ -161,6 +163,7 @@ local function allow_inventory_action(player, stack, to_list, count, move, inven
if stack:get_name() == "exchangeclone:alchemical_tome" then return count end
local name = stack:get_name()
local energy_value = exchangeclone.get_item_energy(stack:get_name())
if not energy_value then return 0 end
local def = minetest.registered_items[name]
if energy_value <= 0 or def.groups.not_in_creative_inventory == 1 then
return 0

View File

@ -0,0 +1,10 @@
exchangeclone = {recipes = {}}
local old_func = minetest.register_craft
function minetest.register_craft(arg)
if arg.output then
exchangeclone.recipes[arg.output] = exchangeclone.recipes[arg.output] or {}
table.insert(exchangeclone.recipes[arg.output], table.copy(arg))
end
old_func(arg)
end