diff --git a/README.md b/README.md index cb5f218..3f35c01 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ Dependencies: Minetest Game or MineClone. * Unfortunately, due to an [engine bug](https://github.com/minetest/minetest/issues/14344), this means that players are kind of invincible most of the time. [ ] Remove and add alias for DM/RM shields [ ] Upgrades affect energy value -[ ] Multiple levels of Exchange Orbs (change to Klein Stars) +[ ] Multiple levels of Exchange Orbs (change to Klein Stars, adjust recipes) [ ] Divining rods [ ] Swiftwolf's Rending Gale (maybe rename?) [ ] Mind, Life, Body and Soul Stones (Mind = MCL only) @@ -98,6 +98,7 @@ Dependencies: Minetest Game or MineClone. [ ] Modify tools page [ ] Remove page for PESA [ ] DM/RM blocks can only be broken by correct (or higher) type. +[ ] Change energy collector recipes to match ProjectE ## Changelog
Look at this fancy expanding changelog diff --git a/exchangeclone/constructor.lua b/exchangeclone/constructor.lua index 2ffcf02..a283f66 100644 --- a/exchangeclone/constructor.lua +++ b/exchangeclone/constructor.lua @@ -2,7 +2,7 @@ local S = minetest.get_translator() local formspec = "size["..(exchangeclone.mcl and 9 or 8)..",9]".. - "label[2,1;"..S("Orb").."]".. + "label[2,1;"..S("Star").."]".. "list[context;fuel;2,2;1,1;]".. "label[3,1;"..S("Source").."]".. "list[context;src;3,2;1,1;]".. @@ -25,12 +25,12 @@ end minetest.register_alias("exchangeclone:element_constructor", "exchangeclone:constructor") local function constructor_action(pos) - local using_orb = true + local using_star = true local player local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - if inv:get_stack("fuel", 1):get_name() ~= "exchangeclone:exchange_orb" then - using_orb = false + if minetest.get_item_group(inv:get_stack("fuel", 1):get_name(), "klein_star" < 1 then + using_star = false player = minetest.get_player_by_name(meta:get_string("exchangeclone_placer")) if not (player and player ~= "") then return end end @@ -45,10 +45,10 @@ local function constructor_action(pos) end end local result = exchangeclone.handle_alias(src_stack) - -- make sure orb/player has enough energy + -- make sure star/player has enough energy local current_energy - if using_orb then - current_energy = exchangeclone.get_orb_energy(inv, "fuel", 1) + if using_star then + current_energy = exchangeclone.get_star_energy(inv, "fuel", 1) else current_energy = exchangeclone.get_player_energy(player) end @@ -57,8 +57,8 @@ local function constructor_action(pos) 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 - if using_orb then - exchangeclone.set_orb_energy(inv, "fuel", 1, result_energy) + if using_star then + exchangeclone.set_star_energy(inv, "fuel", 1, result_energy) else exchangeclone.set_player_energy(player, result_energy) end @@ -90,7 +90,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player) return 0 end if listname == "fuel" then - if stack:get_name() == "exchangeclone:exchange_orb" then + if minetest.get_item_group(stack:get_name(), "klein_star") > 0 then return stack:get_count() else return 0 @@ -155,13 +155,13 @@ minetest.register_node("exchangeclone:constructor", { allow_metadata_inventory_take = allow_metadata_inventory_take, on_timer = constructor_action, _mcl_hoppers_on_try_pull = exchangeclone.mcl2_hoppers_on_try_pull(), - _mcl_hoppers_on_try_push = exchangeclone.mcl2_hoppers_on_try_push(nil, function(stack) return stack:get_name() == "exchangeclone:exchange_orb" end), + _mcl_hoppers_on_try_push = exchangeclone.mcl2_hoppers_on_try_push(nil, function(stack) return minetest.get_item_group(stack:get_name(), "klein_star") > 0 end), _mcl_hoppers_on_after_push = function(pos) minetest.get_node_timer(pos):start(1.0) end, _on_hopper_in = exchangeclone.mcla_on_hopper_in( nil, - function(stack) return stack:get_name() == "exchangeclone:exchange_orb" end + function(stack) return minetest.get_item_group(stack:get_name(), "klein_star") > 0 end ), }) @@ -186,7 +186,7 @@ if exchangeclone.pipeworks then local meta = minetest.get_meta(pos) local inv = meta:get_inventory() if get_list(direction) == "fuel" then - if stack:get_name() == "exchangeclone:exchange_orb" then + if minetest.get_item_group(stack:get_name(), "klein_star") > 0 then return inv:room_for_item("fuel", stack) end else @@ -207,8 +207,8 @@ minetest.register_craft({ type = "shaped", output = "exchangeclone:constructor", recipe = { - {"exchangeclone:exchange_orb"}, + {"exchangeclone:klein_star_drei"}, {recipe_ingredient}, - {"exchangeclone:exchange_orb"} + {"exchangeclone:klein_star_drei"} } }) \ No newline at end of file diff --git a/exchangeclone/deconstructor.lua b/exchangeclone/deconstructor.lua index 313f8c1..401a690 100644 --- a/exchangeclone/deconstructor.lua +++ b/exchangeclone/deconstructor.lua @@ -4,7 +4,7 @@ local formspec = "size["..(exchangeclone.mcl and 9 or 8)..",9]".. "label[2,1;"..S("Input").."]".. "list[context;src;2,2;1,1;]".. - "label[5,1;"..S("Orb").."]".. + "label[5,1;"..S("Star").."]".. "list[context;fuel;5,2;1,1;]".. exchangeclone.inventory_formspec(0,5).. "listring[current_player;main]".. @@ -22,17 +22,19 @@ end minetest.register_alias("exchangeclone:element_deconstructor", "exchangeclone:deconstructor") local function deconstructor_action(pos, elapsed) - local limit = exchangeclone.orb_max - local using_orb = true + local limit + local using_star = true local player local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - if inv:get_stack("fuel", 1):get_name() ~= "exchangeclone:exchange_orb" then + if minetest.get_item_group(inv:get_stack("fuel", 1):get_name(), "klein_star") < 1 then limit = exchangeclone.limit - using_orb = false + using_star = false player = minetest.get_player_by_name(meta:get_string("exchangeclone_placer")) if not (player and player ~= "") then return end + else + limit = exchangeclone.get_star_max(inv:get_stack("fuel", 1)) end local stack = inv:get_stack("src", 1) @@ -42,13 +44,13 @@ local function deconstructor_action(pos, elapsed) if wear and wear > 0 then individual_energy_value = math.max(math.floor(individual_energy_value * ((65536 - wear)/65536)), 1) end - if stack:get_name() == "exchangeclone:exchange_orb" then - individual_energy_value = individual_energy_value + exchangeclone.get_orb_itemstack_energy(stack) + if minetest.get_item_group(stack:get_name(), "klein_star") > 0 then + individual_energy_value = individual_energy_value + exchangeclone.get_star_itemstack_energy(stack) end local current_energy - if using_orb then - current_energy = exchangeclone.get_orb_energy(inv, "fuel", 1) + if using_star then + current_energy = exchangeclone.get_star_energy(inv, "fuel", 1) else current_energy = exchangeclone.get_player_energy(player) end @@ -58,8 +60,8 @@ local function deconstructor_action(pos, elapsed) local result = current_energy + energy_value if result < 0 or result > limit then return end - if using_orb then - exchangeclone.set_orb_energy(inv, "fuel", 1, result) + if using_star then + exchangeclone.set_star_energy(inv, "fuel", 1, result) else exchangeclone.set_player_energy(player, result) end @@ -92,7 +94,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player) return 0 end if listname == "fuel" then - if stack:get_name() == "exchangeclone:exchange_orb" then + if minetest.get_item_group(stack:get_name(), "klein_star") > 0 then return stack:get_count() else return 0 @@ -155,13 +157,13 @@ minetest.register_node("exchangeclone:deconstructor", { allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_take = allow_metadata_inventory_take, on_timer = deconstructor_action, - _mcl_hoppers_on_try_push = exchangeclone.mcl2_hoppers_on_try_push(nil, function(stack) return stack:get_name() == "exchangeclone:exchange_orb" end), + _mcl_hoppers_on_try_push = exchangeclone.mcl2_hoppers_on_try_push(nil, function(stack) return minetest.get_item_group(stack:get_name(), "klein_star") > 0 end), _mcl_hoppers_on_after_push = function(pos) minetest.get_node_timer(pos):start(1.0) end, _on_hopper_in = exchangeclone.mcla_on_hopper_in( nil, - function(stack) return stack:get_name() == "exchangeclone:exchange_orb" end + function(stack) return minetest.get_item_group(stack:get_name(), "klein_star") > 0 end ), }) @@ -186,7 +188,7 @@ if exchangeclone.pipeworks then local meta = minetest.get_meta(pos) local inv = meta:get_inventory() if get_list(direction) == "fuel" then - if stack:get_name() == "exchangeclone:exchange_orb" then + if minetest.get_item_group(stack:get_name(), "klein_star") > 0 then return inv:room_for_item("fuel", stack) end else @@ -207,8 +209,8 @@ end minetest.register_craft({ output = "exchangeclone:deconstructor", recipe = { - {"exchangeclone:exchange_orb"}, + {"exchangeclone:klein_star_drei"}, {recipe_ingredient}, - {"exchangeclone:exchange_orb"} + {"exchangeclone:klein_star_drei"} } }) \ No newline at end of file diff --git a/exchangeclone/energy_collector.lua b/exchangeclone/energy_collector.lua index e5b573e..3efc44c 100644 --- a/exchangeclone/energy_collector.lua +++ b/exchangeclone/energy_collector.lua @@ -2,7 +2,7 @@ local S = minetest.get_translator() local formspec = "size["..(exchangeclone.mcl and 9 or 8)..",9]".. - "label[3,2;"..S("Orb").."]".. + "label[3,2;"..S("Star").."]".. "list[context;main;4,2;1,1;]".. exchangeclone.inventory_formspec(0,5).. "listring[current_player;main]".. @@ -46,9 +46,9 @@ local function on_timer(pos, elapsed) -- get node above local above = vector.add({x=0,y=1,z=0}, pos) - local using_orb = true + local using_star = true if inv:is_empty("main") then - using_orb = false + using_star = false end local light = minetest.get_natural_light(above) @@ -59,14 +59,15 @@ local function on_timer(pos, elapsed) return true end local amount = meta:get_int("collector_amount") - if using_orb then - local stored = exchangeclone.get_orb_energy(inv, "main", 1) - if stored + amount <= exchangeclone.orb_max then + if using_star then + local max = exchangeclone.get_star_max(inv:get_stack("main", 1)) + local stored = exchangeclone.get_star_energy(inv, "main", 1) + if stored + amount <= max then stored = stored + amount else - stored = math.max(stored, exchangeclone.orb_max) + stored = math.max(stored, max) end - exchangeclone.set_orb_energy(inv, "main", 1, stored) + exchangeclone.set_star_energy(inv, "main", 1, stored) else local placer = meta:get_string("exchangeclone_placer") if placer and placer ~= "" then @@ -95,7 +96,7 @@ local function allow_metadata_inventory_put(pos, listname, index, stack, player) return 0 end if listname == "main" then - if stack:get_name() == "exchangeclone:exchange_orb" then + if minetest.get_item_group(stack:get_name(), "klein_star") > 0 then return stack:get_count() else return 0 @@ -122,12 +123,12 @@ function exchangeclone.register_energy_collector(itemstring, name, amount, modif minetest.register_node(itemstring, { description = name.."\nGenerates "..exchangeclone.format_number(amount).." energy/second", tiles = { - "exchangeclone_energy_collector_base.png"..modifier, - "exchangeclone_energy_collector_down.png"..modifier, - "exchangeclone_energy_collector_right.png"..modifier, - "exchangeclone_energy_collector_right.png"..modifier, - "exchangeclone_energy_collector_right.png"..modifier, - "exchangeclone_energy_collector_right.png"..modifier + "exchangeclone_energy_collector_base.png^(exchangeclone_energy_collector_overlay.png"..modifier..")", + "exchangeclone_energy_collector_base.png", + "exchangeclone_energy_collector_base.png", + "exchangeclone_energy_collector_base.png", + "exchangeclone_energy_collector_base.png", + "exchangeclone_energy_collector_base.png", }, groups = {cracky = 2, container = 2, pickaxey = 2, energy_collector = amount, tubedevice = 1, tubedevice_receiver = 1}, _mcl_hardness = 3, @@ -183,7 +184,7 @@ function exchangeclone.register_energy_collector(itemstring, name, amount, modif can_insert = function(pos, node, stack, direction) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - if stack:get_name() == "exchangeclone:exchange_orb" then + if minetest.get_item_group(stack:get_name(), "klein_star") > 0 then return inv:room_for_item("main", stack) end end, @@ -205,7 +206,7 @@ end exchangeclone.register_energy_collector("exchangeclone:energy_collector_mk1", S("Energy Collector MK1"), 4, "", { {glass, glass, glass}, - {"exchangeclone:exchange_orb", chest, "exchangeclone:exchange_orb"}, + {"exchangeclone:klein_star_drei", chest, "exchangeclone:klein_star_drei"}, {iron_block, iron_block, iron_block} } ) diff --git a/exchangeclone/furnaces.lua b/exchangeclone/furnaces.lua index 0f58301..cfb6301 100644 --- a/exchangeclone/furnaces.lua +++ b/exchangeclone/furnaces.lua @@ -584,7 +584,7 @@ local active_def = { "exchangeclone_dark_matter_block.png"..pipeworks_connect, "exchangeclone_dark_matter_block.png"..pipeworks_connect, "exchangeclone_dark_matter_block.png"..pipeworks_connect, - "exchangeclone_dark_matter_furnace.png", + "exchangeclone_dark_matter_furnace_active.png", }, paramtype2 = "4dir", parammatter_type = "light", @@ -717,7 +717,7 @@ minetest.override_item("exchangeclone:red_matter_furnace_active", { "exchangeclone_red_matter_block.png", "exchangeclone_red_matter_block.png", "exchangeclone_red_matter_block.png", - "exchangeclone_red_matter_furnace.png", + "exchangeclone_red_matter_furnace_active.png", }, drop = "exchangeclone:red_matter_furnace", groups = {pickaxey=6, not_in_creative_inventory = 1, cracky = 3, container = exchangeclone.mcl2 and 2 or 4, deco_block=1, material_stone=1, level = get_level(5), exchangeclone_furnace = 2, tubedevice = 1, tubedevice_receiver = 1}, diff --git a/exchangeclone/init.lua b/exchangeclone/init.lua index 72966bd..5ef4dd9 100644 --- a/exchangeclone/init.lua +++ b/exchangeclone/init.lua @@ -111,7 +111,7 @@ end dofile(modpath.."/constructor.lua") dofile(modpath.."/deconstructor.lua") dofile(modpath.."/energy_collector.lua") -dofile(modpath.."/orb.lua") +dofile(modpath.."/klein_stars.lua") dofile(modpath.."/craftitems.lua") if exchangeclone.mcl or minetest.get_modpath("3d_armor") then dofile(modpath.."/armor.lua") diff --git a/exchangeclone/klein_stars.lua b/exchangeclone/klein_stars.lua new file mode 100644 index 0000000..c4e7a8f --- /dev/null +++ b/exchangeclone/klein_stars.lua @@ -0,0 +1,74 @@ +local S = minetest.get_translator() + +local function read_star_charge(itemstack, player, pointed_thing) + local click_test = exchangeclone.check_on_rightclick(itemstack, player, pointed_thing) + if click_test ~= false then + return click_test + end + + local stored = exchangeclone.get_star_itemstack_energy(itemstack) + minetest.chat_send_player(player:get_player_name(), S("Current Charge: @1", exchangeclone.format_number(stored))) + return itemstack +end + +local names = { + "Klein Star Ein", + "Klein Star Zwei", + "Klein Star Drei", + "Klein Star Vier", + "Klein Star Sphere", + "Klein Star Omega", + "Magnum Star Ein", + "Magnum Star Zwei", + "Magnum Star Drei", + "Magnum Star Vier", + "Magnum Star Sphere", + "Magnum Star Omega", +} + +minetest.register_alias("exchangeclone:exchange_orb", "exchangeclone:klein_star_omega") + +for i, name in ipairs(names) do + local codified_name = name:lower():gsub(" ", "_") + minetest.register_tool("exchangeclone:"..codified_name, { + description = S(name).."\n"..S("Current Charge: @1", 0) + inventory_image = "exchangeclone_"..codified_name..".png", + wield_image = "exchangeclone_"..codified_name..".png", + on_secondary_use = read_star_charge, + on_place = read_star_charge, + groups = {klein_star = i, disable_repair = 1, fire_immune = 1}, + max_capacity = 50000*math.pow(4,i-1), + _mcl_generate_description = function(itemstack) + return name.."\n"..S("Current Charge: @1", exchangeclone.get_star_itemstack_energy(itemstack)) + end + }) + + if i > 1 then + previous_codified_name = names[i-1]:lower():gsub(" ", "_") + minetest.register_craft({ + output = "exchangeclone:"..codified_name, + type = "shapeless", + recipe = { + "exchangeclone:"..previous_codified_name, + "exchangeclone:"..previous_codified_name, + "exchangeclone:"..previous_codified_name, + "exchangeclone:"..previous_codified_name, + } + }) + end + + minetest.register_craft({ -- Making it fuel so old versions of MCL's hoppers will work with (de)constructors + type = "fuel", + recipe = "exchangeclone:"..codified_name, + burntime = 24000 --Basically 30 coal blocks... + }) +end + +minetest.register_craft({ + output = "exchangeclone:klein_star_ein", + recipe = { + {"exchangeclone:mobius_fuel", "exchangeclone:mobius_fuel", "exchangeclone:mobius_fuel"}, + {"exchangeclone:mobius_fuel", exchangeclone.itemstrings.diamond, "exchangeclone:mobius_fuel"}, + {"exchangeclone:mobius_fuel", "exchangeclone:mobius_fuel", "exchangeclone:mobius_fuel"}, + } +}) \ No newline at end of file diff --git a/exchangeclone/orb.lua b/exchangeclone/orb.lua deleted file mode 100644 index 6de92af..0000000 --- a/exchangeclone/orb.lua +++ /dev/null @@ -1,38 +0,0 @@ -local S = minetest.get_translator() - -local function read_orb_charge(itemstack, player, pointed_thing) - local click_test = exchangeclone.check_on_rightclick(itemstack, player, pointed_thing) - if click_test ~= false then - return click_test - end - - local stored = exchangeclone.get_orb_itemstack_energy(itemstack) - minetest.chat_send_player(player:get_player_name(), S("Current Charge: @1", exchangeclone.format_number(stored))) - return itemstack -end - -minetest.register_tool("exchangeclone:exchange_orb", { - description = S("Exchange Orb").."\n"..S("Current Charge: @1", 0), - inventory_image = "exchangeclone_exchange_orb.png", - color = "#000000", - on_secondary_use = read_orb_charge, - on_place = read_orb_charge, - groups = {exchange_orb = 1, disable_repair = 1, fire_immune = 1} -}) - -minetest.register_craft({ - type = "shaped", - output = "exchangeclone:exchange_orb", - groups = {}, - recipe = { - {exchangeclone.itemstrings.diamond, exchangeclone.itemstrings.iron, exchangeclone.itemstrings.diamond}, - {exchangeclone.itemstrings.iron, "exchangeclone:philosophers_stone", exchangeclone.itemstrings.iron}, - {exchangeclone.itemstrings.diamond, exchangeclone.itemstrings.iron, exchangeclone.itemstrings.diamond} - }, - replacements = {{"exchangeclone:philosophers_stone", "exchangeclone:philosophers_stone"}} -}) -minetest.register_craft({ -- Making it fuel so MineClone hoppers will work with (de)constructors - type = "fuel", - recipe = "exchangeclone:exchange_orb", - burntime = 24000 --Basically 30 coal blocks... -}) \ No newline at end of file diff --git a/exchangeclone/transmutation_table.lua b/exchangeclone/transmutation_table.lua index 3e1ceee..1852fbd 100644 --- a/exchangeclone/transmutation_table.lua +++ b/exchangeclone/transmutation_table.lua @@ -139,8 +139,8 @@ local function handle_inventory(player, inventory, to_list) if wear and wear > 1 then individual_energy_value = math.max(math.floor(individual_energy_value * ((65536 - wear)/65536)), 1) end - if itemstring == "exchangeclone:exchange_orb" then - individual_energy_value = individual_energy_value + exchangeclone.get_orb_itemstack_energy(stack) + if minetest.get_item_group(itemstring, "klein_star") then + individual_energy_value = individual_energy_value + exchangeclone.get_star_itemstack_energy(stack) end local player_energy = exchangeclone.get_player_energy(player) local max_count = math.floor((exchangeclone.limit - player_energy)/individual_energy_value) @@ -164,11 +164,11 @@ local function handle_inventory(player, inventory, to_list) return elseif to_list == "charge" then local player_energy = exchangeclone.get_player_energy(player) - local orb_energy = exchangeclone.get_orb_itemstack_energy(stack) - local charge_amount = math.min(exchangeclone.orb_max - orb_energy, player_energy) + local star_energy = exchangeclone.get_star_itemstack_energy(stack) + local charge_amount = math.min(exchangeclone.get_star_max(stack) - star_energy, player_energy) if charge_amount > 0 then exchangeclone.add_player_energy(player, 0-charge_amount) - exchangeclone.set_orb_energy(inventory, to_list, 1, orb_energy + charge_amount) + exchangeclone.set_star_energy(inventory, to_list, 1, star_energy + charge_amount) exchangeclone.show_transmutation_table_formspec(player) end end @@ -193,7 +193,7 @@ local function allow_inventory_action(player, stack, to_list, count, move, inven if not check_for_table(player, inventory) then return 0 end if to_list == "output" then return 0 - elseif to_list == "charge" and stack:get_name() ~= "exchangeclone:exchange_orb" then + elseif to_list == "charge" and minetest.get_item_group(stack:get_name, "klein_star") then return 0 elseif to_list == "learn" then if stack:get_name() == "exchangeclone:alchemical_tome" then return count end @@ -375,7 +375,7 @@ minetest.register_node("exchangeclone:transmutation_table", { }) minetest.register_tool("exchangeclone:alchemical_tome", { - description = "Alchemical Tome\nOrbs in crafting recipe must be full", + description = "Alchemical Tome\Magnum Star Omegas in crafting recipe must be full", inventory_image = "exchangeclone_alchemical_tome.png", wield_image = "exchangeclone_alchemical_tome.png", groups = {disable_repair = 1, fire_immune = 1} @@ -414,7 +414,7 @@ if minetest.settings:get_bool("exchangeclone.allow_crafting_alchemical_tome", tr output = "exchangeclone:alchemical_tome", recipe = { {"", book, ""}, - {"exchangeclone:exchange_orb", "exchangeclone:philosophers_stone", "exchangeclone:exchange_orb"}, + {"exchangeclone:magnum_star_omega", "exchangeclone:philosophers_stone", "exchangeclone:magnum_star_omega"}, {"", "exchangeclone:red_matter", ""} }, replacements = {{"exchangeclone:philosophers_stone", "exchangeclone:philosophers_stone"}} @@ -423,11 +423,11 @@ end minetest.register_craft_predict(function(itemstack, player, old_craft_grid, craft_inv) if itemstack == ItemStack("exchangeclone:alchemical_tome") then - if exchangeclone.get_orb_itemstack_energy(old_craft_grid[4]) >= exchangeclone.orb_max - and exchangeclone.get_orb_itemstack_energy(old_craft_grid[6]) >= exchangeclone.orb_max then - return - else - return ItemStack("") + for _, i in {4,6} do + local stack = old_craft_grid[i] + if exchangeclone.get_star_itemstack_energy(stack) < exchangeclone.get_star_max(stack) then + return ItemStack("") + end end end end) \ No newline at end of file diff --git a/settingtypes.txt b/settingtypes.txt index 9e68775..d805a01 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -1,7 +1,4 @@ -# Exchange Orb maximum energy (default 51200000) -exchangeclone.orb_max (Exchange Orb maximum energy) int 51200000 - -# Keep unnecessary temporary data (such as the list of recipes) after load time for debugging purposes. + Keep unnecessary temporary data (such as the list of recipes) after load time for debugging purposes. exchangeclone.keep_data (Keep temporary data after loading) bool false # Allow the crafting recipe for the Alchemical Tome diff --git a/zzzz_exchangeclone_init/init.lua b/zzzz_exchangeclone_init/init.lua index 299fb8f..d9c8d58 100644 --- a/zzzz_exchangeclone_init/init.lua +++ b/zzzz_exchangeclone_init/init.lua @@ -14,7 +14,6 @@ if exchangeclone.mcl2 or exchangeclone.mcla then exchangeclone.mcl = true end if not exchangeclone.mcl then exchangeclone.mtg = true end exchangeclone.pipeworks = minetest.get_modpath("pipeworks") -exchangeclone.orb_max = minetest.settings:get("exchangeclone.orb_max") or 51200000 -- Max capacity of Klein Star Omega in ProjectE exchangeclone.keep_data = minetest.settings:get_bool("exchangeclone.keep_data", false) local modpath = minetest.get_modpath("zzzz_exchangeclone_init") diff --git a/zzzz_exchangeclone_init/lib.lua b/zzzz_exchangeclone_init/lib.lua index 7d8a403..02004a3 100644 --- a/zzzz_exchangeclone_init/lib.lua +++ b/zzzz_exchangeclone_init/lib.lua @@ -78,9 +78,9 @@ function exchangeclone.get_item_energy(item) end local def = minetest.registered_items[item:get_name()] if not def then return end - if item:get_name() == "exchangeclone:exchange_orb" then + if minetest.get_item_group(item:get_name(), "klein_star" then if def.energy_value then - return def.energy_value + exchangeclone.get_orb_itemstack_energy(item) + return def.energy_value + exchangeclone.get_star_itemstack_energy(item) end end if def.energy_value then @@ -94,71 +94,53 @@ function exchangeclone.map(input, min1, max1, min2, max2) return (input - min1) / (max1 - min1) * (max2 - min2) + min2 end --- Gets the energy stored in a specified exchange_orb itemstack. -function exchangeclone.get_orb_itemstack_energy(itemstack) +-- Gets the energy stored in a specified star itemstack. +function exchangeclone.get_star_itemstack_energy(itemstack) if not itemstack then return end - if itemstack:get_name() ~= "exchangeclone:exchange_orb" then return end + if minetest.get_item_group(itemstack:get_name(), "klein_star") < 1 then return end return math.max(itemstack:get_meta():get_float("stored_energy"), 0) end --- Gets the amount of energy stored in an orb in a specific inventory slot -function exchangeclone.get_orb_energy(inventory, listname, index) +-- Gets the amount of energy stored in a star in a specific inventory slot +function exchangeclone.get_star_energy(inventory, listname, index) if not inventory then return end if not listname then listname = "main" end if not index then index = 1 end local itemstack = inventory:get_stack(listname, index) - return exchangeclone.get_orb_itemstack_energy(itemstack) + return exchangeclone.get_star_itemstack_energy(itemstack) end -function exchangeclone.set_orb_itemstack_energy(itemstack, amount) +function exchangeclone.set_star_itemstack_energy(itemstack, amount) if not itemstack or not amount 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 + local old_energy = exchangeclone.get_star_itemstack_energy(itemstack) + local max = exchangeclone.get_star_max(itemstack) + if amount > old_energy and old_energy > max then return end -- don't allow more energy to be put into an over-filled star - -- Square roots will hopefully make it less linear - -- And if they don't, I don't really care and I don't want to think about math anymore. - local sqrt_amount = math.sqrt(amount) - local sqrt_max = math.sqrt(exchangeclone.orb_max) - - local r, g, b = 0, 0, 0 - if amount <= 0 then - -- do nothing - elseif sqrt_amount < (sqrt_max/4) then - r = exchangeclone.map(sqrt_amount, 0, sqrt_max/4, 0, 255) - elseif sqrt_amount < (sqrt_max/2) then - g = exchangeclone.map(sqrt_amount, sqrt_max/4, sqrt_max/2, 0, 255) - r = 255 - g - elseif sqrt_amount < (3*sqrt_max/4) then - b = exchangeclone.map(sqrt_amount, sqrt_max/2, 3*sqrt_max/4, 0, 255) - g = 255 - b - else - r = math.min(exchangeclone.map(sqrt_amount, 3*sqrt_max/4, sqrt_max, 0, 255), 255) - b = 255 - end - - local colorstring = minetest.rgba(r,g,b) local meta = itemstack:get_meta() meta:set_float("stored_energy", amount) - meta:set_string("description", S("Exchange Orb").."\n"..S("Current Charge: @1", exchangeclone.format_number(amount))) - meta:set_string("color", colorstring) - local wear = math.min(1, math.max(65535, 65535 - 65535*amount/exchangeclone.orb_max)) - minetest.log(dump(wear)) + meta:set_string("description", itemstack:_mcl_generate_description()) + local wear = math.min(1, math.max(65535, 65535 - 65535*amount/max)) itemstack:set_wear(wear) return itemstack end --- Sets the amount of energy in an orb in a specific inventory slot -function exchangeclone.set_orb_energy(inventory, listname, index, amount) +-- Sets the amount of energy in a star in a specific inventory slot +function exchangeclone.set_star_energy(inventory, listname, index, amount) if not inventory or not amount or amount < 0 then return end if not listname then listname = "main" end if not index then index = 1 end local itemstack = inventory:get_stack(listname, index) - local new_stack = exchangeclone.set_orb_itemstack_energy(itemstack, amount) + local new_stack = exchangeclone.set_star_itemstack_energy(itemstack, amount) if not new_stack then return end inventory:set_stack(listname, index, new_stack) end +function exchangeclone.get_star_max(item) + item = ItemStack(item) + return item:get_definition().max_capacity or 0 +end + -- HUD stuff (show energy value in bottom right) local hud_elements = {}