From 802e33fdc0515b0e39137ae3e68d78c1fcf2edc9 Mon Sep 17 00:00:00 2001 From: Beha Date: Mon, 9 Jan 2017 19:09:53 -0500 Subject: [PATCH] Add a mana potion. --- kingdoms/gen.lua | 1 + magic/init.lua | 1 + magic/potions.lua | 81 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 83 insertions(+) create mode 100644 magic/potions.lua diff --git a/kingdoms/gen.lua b/kingdoms/gen.lua index 60b69a3..4da7c8f 100644 --- a/kingdoms/gen.lua +++ b/kingdoms/gen.lua @@ -8,6 +8,7 @@ if kingdoms.config.mapgen then default.register_biomes() default.register_decorations() + flowers.register_decorations() kingdoms.log("action", "Applied mapgen settings.") end magic.register_mapgen() diff --git a/magic/init.lua b/magic/init.lua index b03e391..b8f785f 100644 --- a/magic/init.lua +++ b/magic/init.lua @@ -24,6 +24,7 @@ domodfile("crafts.lua") domodfile("timegens.lua") domodfile("crystals.lua") domodfile("spells.lua") +domodfile("potions.lua") domodfile("turrets.lua") domodfile("spells/action.lua") diff --git a/magic/potions.lua b/magic/potions.lua new file mode 100644 index 0000000..f5367fd --- /dev/null +++ b/magic/potions.lua @@ -0,0 +1,81 @@ +function magic.register_potion(name, def) + local item_def = { + description = def.description, + drawtype = "plantlike", + tiles = {"vessels_glass_bottle.png^[colorize:"..def.color..":200"}, + inventory_image = "vessels_glass_bottle.png^[colorize:"..def.color..":200", + wield_image = "vessels_glass_bottle.png^[colorize:"..def.color..":200", + paramtype = "light", + is_ground_content = false, + walkable = false, + selection_box = { + type = "fixed", + fixed = {-0.25, -0.5, -0.25, 0.25, 0.3, 0.25} + }, + groups = {vessel = 1, dig_immediate = 3, attached_node = 1}, + sounds = default.node_sound_glass_defaults(), + } + local function docost(player) + if def.harmful then + return magic.require_energy(player, def.cost, true) + else + return magic.require_mana(player, def.cost, true) + end + end + if def.on_use then + function item_def.on_use(itemstack, player) + if def.cost then + if not docost(player) then return end + end + if def.on_use(itemstack, player) then + if player:get_inventory():room_for_item("main", "vessels:glass_bottle") then + player:get_inventory():add_item("main", "vessels:glass_bottle") + else + minetest.add_item(pos, "vessels:glass_bottle") + end + itemstack:take_item() + end + return itemstack + end + end + minetest.register_node(name, item_def) +end + +magic.register_potion("magic:water_bottle", { + description = "Bottle of Water", + color = "#02A", +}) + +minetest.register_craft({ + output = "magic:water_bottle", + type = "shapeless", + recipe = {"vessels:glass_bottle", "bucket:bucket_water"}, + replacements = {{"bucket:bucket_water", "bucket:bucket_empty"}}, +}) + +magic.register_potion("magic:purified_water_bottle", { + description = "Purified Bottle of Water", + color = "#23B", +}) + +minetest.register_craft({ + type = "cooking", + output = "magic:purified_water_bottle", + recipe = "magic:water_bottle", + cooktime = 5, +}) + +magic.register_potion("magic:minor_mana_potion", { + description = "Minor Mana Restoration Potion", + color = "#00F", + on_use = function(itemstack, player) + magic.require_mana(player, -2) + return true + end, +}) + +minetest.register_craft({ + output = "magic:minor_mana_potion", + type = "shapeless", + recipe = {"magic:water_bottle", "flowers:geranium"}, +})