diff --git a/README.md b/README.md index 9770c42..4192405 100644 --- a/README.md +++ b/README.md @@ -105,6 +105,7 @@ You can find the old textures and sounds by going back to previous commits in Gi * The Constructor and Deconstructor are now deprecated. Element Exchange is no more. * Upgrades and Stars can no longer be used as fuel. * Dark and Red Matter Armor now uses ProjectE's textures + * Removed the ability to right click with stars to see the charge (made it more convenient to add the EMC Link) * Bugfixes: * Dark and Red Matter Armor display properly (and identically) in both games. diff --git a/exchangeclone/emc_link.lua b/exchangeclone/emc_link.lua index ca8369c..6dfbf98 100644 --- a/exchangeclone/emc_link.lua +++ b/exchangeclone/emc_link.lua @@ -3,7 +3,8 @@ local function on_rightclick(pos, node, player, itemstack, pointed_thing) local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - if player:get_player_control().sneak then + -- Would be sneak but that would require me to override the player's hand... + if player:get_player_control().aux1 then local contained = inv:get_stack("star", 1) if minetest.get_item_group(itemstack:get_name(), "klein_star") > 0 then inv:set_stack("star", 1, itemstack) @@ -22,9 +23,61 @@ local function on_rightclick(pos, node, player, itemstack, pointed_thing) end end +local function link_action(pos) + local using_star = true + local player + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + if minetest.get_item_group(inv:get_stack("star", 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 + local target_item = meta:get_string("target_item") + if target_item and target_item ~= "" and minetest.registered_items[target_item] then + local input_stack = inv:get_stack("input", 1) + local output_stack = inv:get_stack("output", 1) + -- make sure the target matches the output (including enchantments) + if not inv:is_empty("output") then + if exchangeclone.handle_alias(target_item) ~= output_stack:get_name() then + return + end + end + local result = exchangeclone.handle_alias(target_item) + -- make sure star/player has enough EMC + local current_emc + if using_star then + current_emc = exchangeclone.get_star_emc(inv, "star", 1) + else + current_emc = exchangeclone.get_player_emc(player) + end + local emc_value = exchangeclone.get_item_emc(input_stack:get_name()) + if emc_value and emc_value > 0 then + local max_amount = math.min(input_stack:get_stack_max(), math.floor(current_emc/emc_value)) + local added_amount = max_amount - inv:add_item("output", ItemStack(result.." "..max_amount)):get_count() + local result_emc = math.min(current_emc, current_emc - (emc_value * added_amount)) -- not sure if "math.min()" is necessary + if using_star then + exchangeclone.set_star_emc(inv, "star", 1, result_emc) + else + exchangeclone.set_player_emc(player, result_emc) + end + end + end + + local timer = minetest.get_node_timer(pos) + if not (target_item and target_item ~= "" and minetest.registered_items[target_item]) then + timer:stop() + else + if not timer:is_started() then + timer:start(1) + end + end +end + minetest.register_node("exchangeclone:emc_link", { description = "EMC Link\nAllows automation with personal EMC", tiles = {"exchangeclone_emc_link.png"}, + groups = {pickaxey=4, material_stone=1, cracky = 2, building_block = 1, level = exchangeclone.mtg and 2 or 0}, on_rightclick = on_rightclick, on_construct = function(pos) local meta = minetest.get_meta(pos) @@ -38,9 +91,12 @@ minetest.register_node("exchangeclone:emc_link", { local player_name = player:get_player_name() local meta = minetest.get_meta(pos) meta:set_string("exchangeclone_placer", player_name) - meta:set_string("infotext", "EMC Link".."\n"..S("Owned by ")..player_name) + meta:set_string("infotext", "EMC Link".."\n".."Owned by "..player_name) if exchangeclone.pipeworks then pipeworks.after_place(pos, player, itemstack, pointed_thing) end end, + sounds = exchangeclone.sound_mod.node_sound_stone_defaults(), + _mcl_blast_resistance = 10, + _mcl_hardness = 8, }) \ No newline at end of file diff --git a/exchangeclone/hopper_compat.lua b/exchangeclone/hopper_compat.lua index 1a46c2d..0ba0318 100644 --- a/exchangeclone/hopper_compat.lua +++ b/exchangeclone/hopper_compat.lua @@ -8,26 +8,25 @@ hopper:add_container({ }) hopper:add_container({ - {"top", "group:container=3", "main"}, - {"bottom", "group:container=3", "main"}, - {"side", "group:container=3", "main"}, + {"top", "exchangeclone:upgrader", "dst"}, + {"side", "exchangeclone:upgrader", "fuel"}, + {"bottom", "exchangeclone:upgrader", "src"}, }) --- I assumed "top" meant when it's on top of a node, not when there's a node on top of it. Whoops. hopper:add_container({ - {"top", "group:container=4", "dst"}, - {"side", "group:container=4", "fuel"}, - {"bottom", "group:container=4", "src"}, + {"top", "group:exchangeclone_furnace", "dst"}, + {"side", "group:exchangeclone_furnace", "fuel"}, + {"bottom", "group:exchangeclone_furnace", "src"}, }) --- Hoppers will only be able to insert into one side of a double chest, I think (unless you have 1 hopper per side) hopper:add_container({ - {"top", "group:container=5", "main"}, - {"bottom", "group:container=5", "main"}, - {"side", "group:container=5", "main"}, + {"top", "group:energy_collector", "main"}, + {"bottom", "group:energy_collector", "main"}, + {"side", "group:energy_collector", "main"}, }) + hopper:add_container({ - {"top", "group:container=6", "main"}, - {"bottom", "group:container=6", "main"}, - {"side", "group:container=6", "main"}, + {"top", "exchangeclone:emc_link", "output"}, + {"bottom", "exchangeclone:emc_link", "input"}, + {"side", "exchangeclone:emc_link", "input"}, }) \ No newline at end of file diff --git a/exchangeclone/klein_stars.lua b/exchangeclone/klein_stars.lua index 5d44e18..bdb88ee 100644 --- a/exchangeclone/klein_stars.lua +++ b/exchangeclone/klein_stars.lua @@ -1,16 +1,5 @@ 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_emc(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", @@ -35,8 +24,6 @@ for i, name in ipairs(names) do description = S(name).."\n"..S("Current Charge: @1/@2", 0, exchangeclone.format_number(capacity)), 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 = capacity, _mcl_generate_description = function(itemstack)