diff --git a/mods/crafting_guide/init.lua b/mods/crafting_guide/init.lua index 425935e..ff3026c 100644 --- a/mods/crafting_guide/init.lua +++ b/mods/crafting_guide/init.lua @@ -50,7 +50,7 @@ function crafting_guide.get_formspec(crafts,back_button) return str end -function crafting_guide.get_furnace_formspec(recipe,back_button) +function crafting_guide.get_furnace_formspec(recipe, back_button) local str = crafting_guide.form if back_button then str = crafting_guide.form_back @@ -64,6 +64,20 @@ function crafting_guide.get_furnace_formspec(recipe,back_button) return str end +function crafting_guide.get_anvil_formspec(recipe, back_button) + local str = crafting_guide.form + if back_button then + str = crafting_guide.form_back + end + + str = str .. "label[0,0;Anvil:]" + + str = str .. "item_image_button[0,1;1,1;" .. recipe.input .. ";" .. recipe.input .. ";]" + str = str .. "item_image_button[2,1;1,1;" .. recipe.output .. ";" .. recipe.output .. ";]" + + return str +end + function crafting_guide.get_item_formspec(page, player) page = page or 0 local str = crafting_guide.form_items @@ -86,7 +100,7 @@ function crafting_guide.get_item_formspec(page, player) table.sort(items) for _,name in ipairs(items) do - if ((minetest.get_all_craft_recipes(name) or furnace.get_recipe(name)) or creative_priv) and + if ((minetest.get_all_craft_recipes(name) or furnace.get_recipe(name) or furnace.anvil.get_recipe(name)) or creative_priv) and i < (8*6)*(page+1) then if i > (8*6)*(page)-1 then str = str .. "item_image_button["..x..","..y..";1,1;"..name..";"..name..";]" @@ -193,6 +207,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_formspec(crafts,true)) elseif furnace.get_recipe(i) then minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_furnace_formspec(furnace.get_recipe(i),true)) + elseif furnace.anvil.get_recipe(i) then + minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_anvil_formspec(furnace.anvil.get_recipe(i),true)) end end end @@ -227,6 +243,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_formspec(crafts,true)) elseif furnace.get_recipe(i) then minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_furnace_formspec(furnace.get_recipe(i),true)) + elseif furnace.anvil.get_recipe(i) then + minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_anvil_formspec(furnace.anvil.get_recipe(i),true)) end end end diff --git a/mods/furnace/anvil.lua b/mods/furnace/anvil.lua index c6cd14d..f386fe4 100644 --- a/mods/furnace/anvil.lua +++ b/mods/furnace/anvil.lua @@ -4,6 +4,28 @@ function furnace.anvil.register_material(name, def) furnace.anvil.materials[name] = def end +function furnace.anvil.get_recipe(item) + -- search recipe for item + for i,recipe in pairs(furnace.anvil.materials) do + if item == recipe.items.rod then + return nil -- return nil + end + + if item == recipe.items.plate then + return {input = recipe.items.rod, output = item} -- return recipe for item + end + + if item == (recipe.items.blade or "none") then + return {input = recipe.items.rod, output = item} -- return recipe for item + end + + if item == (recipe.items.other or "none") then + return {input = recipe.items.rod, output = item} -- return recipe for item + end + end + return nil -- no recipe found +end + -- formspec local anvil_form = "size[8,9]" diff --git a/mods/money/init.lua b/mods/money/init.lua index 768b5ab..46c5119 100644 --- a/mods/money/init.lua +++ b/mods/money/init.lua @@ -17,7 +17,7 @@ money.shop.offers = { {input="money:silver_coin 2", output="default:box"}, {input="money:coin 1", output="default:pick"}, {input="money:silver_coin 4", output="dungeons:custom_treasure_chest"}, - {input="default:stone_item 891", output="money:silver_coin 5"} + {input="default:stone_item 999", output="money:silver_coin 5"} } function money.shop.get_formspec(page) diff --git a/mods/npcs/init.lua b/mods/npcs/init.lua index ab4ca43..a94fe11 100644 --- a/mods/npcs/init.lua +++ b/mods/npcs/init.lua @@ -50,6 +50,15 @@ function npcs.register_npc(name, def) local name = player:get_player_name() quests.show_text(def.npc_text, name) end + elseif def.npc_type == "texts" then + def.on_rightclick = function(pos, node, player, itemstack, pt) + if quests.process_npc_goals(player:get_player_name(), "talk", pt.under) then + return + end + + local name = player:get_player_name() + quests.show_text(def.npc_texts[math.random(#def.npc_texts)], name) + end elseif def.npc_type == "quests" then def.on_rightclick = function(pos, node, player, itemstack, pt) if quests.process_npc_goals(player:get_player_name(), "talk", pt.under) then @@ -115,17 +124,52 @@ minetest.register_abm({ npcs.register_npc("npcs:farmer_1", { tiles = {"npc_1.png"}, - npc_type = "quest", - npc_get_quest = function(pos, player) - local quest = quests.new(nil, "Test", "Test") - quest.id = tostring(minetest.get_day_count()) .. " " .. minetest.pos_to_string(pos) - local goal_1 = quests.add_place_goal(quest, "Place dirt", {"default:dirt"}, 1, "Place some dirt blocks!") - local goal_2 = quests.add_talk_goal(quest, "Talk", pos, "Place some dirt blocks!") - - goal_2.requires = goal_1 - - return quest - end, + npc_type = "shop", + npc_text = "Hi! Do you want to buy an item?", + npc_items = { + { + input = "money:silver_coin", + output = "farming:apple 9", + text = "1 Silver Coin -> 8 Apple", + }, { + input = "money:silver_coin 1", + output = "farming:slice_of_bread 9", + text = "4 Silver Coin -> 4 Slice of Bread", + }, { + input = "money:silver_coin 1", + output = "default:mushroom 2", + text = "1 Silver Coin -> 2 Mushroom", + } + }, +}) + +npcs.register_npc("npcs:miner_1", { + tiles = {"npc_3.png"}, + npc_type = "shop", + npc_text = "Hi! Do you want to buy an item?", + npc_items = { + { + input = "money:silver_coin 10", + output = "furnace:furnace", + text = "10 Silver Coin -> 1 Furnace", + }, { + input = "money:silver_coin 10", + output = "furnace:anvil", + text = "10 Silver Coin -> 1 Anvil", + }, { + input = "money:silver_coin", + output = "torch:torch 4", + text = "1 Silver Coin -> 4 Torch", + }, { + input = "money:coin", + output = "default:pick", + text = "1 Gold Coin -> 1 Iron Pick", + }, { + input = "default:stone_item 999", + output = "money:silver_coin 5", + text = "999 Stone -> 5 Silver Coin", + } + }, }) npcs.register_npc("npcs:hunter_1", { @@ -143,6 +187,20 @@ npcs.register_npc("npcs:hunter_1", { end, }) +npcs.register_npc("npcs:builder_1", { + tiles = {"npc_4.png"}, + npc_type = "texts", + npc_texts = { + "Hello!", + "Hi!", + "Hey!", + + "Hello.\nHow are you?", + "Hi.\nHow are you?", + "Hey.\nHow are you?", + }, +}) + --TEST --npcs.register_npc("npcs:farmer", { -- tiles = {"npc_1.png"}, diff --git a/mods/npcs/textures/npc_3.png b/mods/npcs/textures/npc_3.png new file mode 100644 index 0000000..1fb0312 Binary files /dev/null and b/mods/npcs/textures/npc_3.png differ diff --git a/mods/npcs/textures/npc_4.png b/mods/npcs/textures/npc_4.png new file mode 100644 index 0000000..b71a098 Binary files /dev/null and b/mods/npcs/textures/npc_4.png differ