Version 0.41.3
[MineClone/MineClone2/MineClone2-Fixes.git] / mods / ITEMS / mcl_potions / init.lua
blobc8b1f73c5c043f54cbb948388cc3e91148f9cfe0
1 local brewhelp = "This item currently has no purpose."
3 minetest.register_craftitem("mcl_potions:fermented_spider_eye", {
4 description = "Fermented Spider Eye",
5 _doc_items_longdesc = brewhelp,
6 wield_image = "mcl_potions_spider_eye_fermented.png",
7 inventory_image = "mcl_potions_spider_eye_fermented.png",
8 groups = { brewitem = 1 },
9 stack_max = 64,
12 minetest.register_craft({
13 type = "shapeless",
14 output = "mcl_potions:fermented_spider_eye",
15 recipe = { "mcl_mushrooms:mushroom_brown", "mcl_core:sugar", "mcl_mobitems:spider_eye" },
18 minetest.register_craftitem("mcl_potions:glass_bottle", {
19 description = "Glass Bottle",
20 _doc_items_longdesc = "A glass bottle is used as a container for liquids and can be used to collect water directly.",
21 _doc_items_usagehelp = "To collect water, it on a cauldron with water (which removes a level of water) or any water source (which removes no water).",
22 inventory_image = "mcl_potions_potion_bottle_empty.png",
23 wield_image = "mcl_potions_potion_bottle_empty.png",
24 groups = {brewitem=1},
25 liquids_pointable = true,
26 on_place = function(itemstack, placer, pointed_thing)
27 if pointed_thing.type == "node" then
28 local node = minetest.get_node(pointed_thing.under)
29 local def = minetest.registered_nodes[node.name]
31 -- Call on_rightclick if the pointed node defines it
32 if placer and not placer :get_player_control().sneak then
33 if def and def.on_rightclick then
34 return def.on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
35 end
36 end
38 -- Try to fill glass bottle with water
39 local get_water = false
40 local river_water = false
41 if not def then
42 -- Unknown node: no-op
43 elseif def.groups and def.groups.water and def.liquidtype == "source" then
44 -- Water source
45 get_water = true
46 river_water = node.name == "mclx_core:river_water_source"
47 -- Or reduce water level of cauldron by 1
48 elseif node.name == "mcl_cauldrons:cauldron_3" then
49 get_water = true
50 minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron_2"})
51 elseif node.name == "mcl_cauldrons:cauldron_2" then
52 get_water = true
53 minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron_1"})
54 elseif node.name == "mcl_cauldrons:cauldron_1" then
55 get_water = true
56 minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"})
57 elseif node.name == "mcl_cauldrons:cauldron_3r" then
58 get_water = true
59 river_water = true
60 minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron_2r"})
61 elseif node.name == "mcl_cauldrons:cauldron_2r" then
62 get_water = true
63 river_water = true
64 minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron_1r"})
65 elseif node.name == "mcl_cauldrons:cauldron_1r" then
66 get_water = true
67 river_water = true
68 minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"})
69 end
70 if get_water then
71 -- Replace with water bottle, if possible, otherwise
72 -- place the water potion at a place where's space
73 local water_bottle
74 if river_water then
75 water_bottle = ItemStack("mcl_potions:potion_river_water")
76 else
77 water_bottle = ItemStack("mcl_potions:potion_water")
78 end
79 minetest.sound_play("mcl_potions_bottle_fill", {pos=pointed_thing.under, gain=0.5, max_hear_range=16})
80 if itemstack:get_count() == 1 then
81 return water_bottle
82 else
83 local inv = placer:get_inventory()
84 if inv:room_for_item("main", water_bottle) then
85 inv:add_item("main", water_bottle)
86 else
87 minetest.add_item(placer:getpos(), water_bottle)
88 end
89 itemstack:take_item()
90 end
91 end
92 end
93 return itemstack
94 end,
97 minetest.register_craft( {
98 output = "mcl_potions:glass_bottle 3",
99 recipe = {
100 { "mcl_core:glass", "", "mcl_core:glass" },
101 { "", "mcl_core:glass", "" }
105 -- Template function for creating images of filled potions
106 -- - colorstring must be a ColorString of form “#RRGGBB”, e.g. “#0000FF” for blue.
107 -- - opacity is optional opacity from 0-255 (default: 127)
108 local potion_image = function(colorstring, opacity)
109 if not opacity then
110 opacity = 127
112 return "mcl_potions_potion_bottle_drinkable.png^(mcl_potions_potion_overlay.png^[colorize:"..colorstring..":"..tostring(opacity)..")"
115 -- Cauldron fill up rules:
116 -- Adding any water increases the water level by 1, preserving the current water type
117 local cauldron_levels = {
118 -- start = { add water, add river water }
119 { "", "_1", "_1r" },
120 { "_1", "_2", "_2" },
121 { "_2", "_3", "_3" },
122 { "_1r", "_2r", "_2r" },
123 { "_2r", "_3r", "_3r" },
125 local fill_cauldron = function(cauldron, water_type)
126 local base = "mcl_cauldrons:cauldron"
127 for i=1, #cauldron_levels do
128 if cauldron == base .. cauldron_levels[i][1] then
129 if water_type == "mclx_core:river_water_source" then
130 return base .. cauldron_levels[i][3]
131 else
132 return base .. cauldron_levels[i][2]
138 -- Itemstring of potions is “mcl_potions:potion_<NBT Potion Tag>”
140 minetest.register_craftitem("mcl_potions:potion_water", {
141 description = "Water Bottle",
142 _doc_items_longdesc = "Water bottles can be used to fill cauldrons. Drinking water has no effect.",
143 _doc_items_usagehelp = "Rightclick to drink. Rightclick a cauldron to pour the water into the cauldron.",
144 stack_max = 1,
145 inventory_image = potion_image("#0000FF"),
146 wield_image = potion_image("#0000FF"),
147 groups = {brewitem=1, food=3, can_eat_when_full=1, water_bottle=1},
148 on_place = function(itemstack, placer, pointed_thing)
149 if pointed_thing.type == "node" then
150 local node = minetest.get_node(pointed_thing.under)
151 local def = minetest.registered_nodes[node.name]
153 -- Call on_rightclick if the pointed node defines it
154 if placer and not placer:get_player_control().sneak then
155 if def and def.on_rightclick then
156 return def.on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
160 local cauldron = fill_cauldron(node.name, "mcl_core:water_source")
161 if cauldron then
162 -- Increase water level of cauldron by 1
163 minetest.set_node(pointed_thing.under, {name=cauldron})
164 minetest.sound_play("mcl_potions_bottle_pour", {pos=pointed_thing.under, gain=0.5, max_hear_range=16})
165 return "mcl_potions:glass_bottle"
169 -- Drink the water by default
170 return minetest.do_item_eat(0, "mcl_potions:glass_bottle", itemstack, placer, pointed_thing)
171 end,
172 on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
175 minetest.register_craftitem("mcl_potions:potion_river_water", {
176 description = "River Water Bottle",
177 _doc_items_longdesc = "River water bottles can be used to fill cauldrons. Drinking it has no effect.",
178 _doc_items_usagehelp = "Rightclick to drink. Rightclick a cauldron to pour the river water into the cauldron.",
179 stack_max = 1,
180 inventory_image = potion_image("#0044FF"),
181 wield_image = potion_image("#0044FF"),
182 groups = {brewitem=1, food=3, can_eat_when_full=1, water_bottle=1},
183 on_place = function(itemstack, placer, pointed_thing)
184 if pointed_thing.type == "node" then
185 local node = minetest.get_node(pointed_thing.under)
186 local def = minetest.registered_nodes[node.name]
188 -- Call on_rightclick if the pointed node defines it
189 if placer and not placer:get_player_control().sneak then
190 if def and def.on_rightclick then
191 return def.on_rightclick(pointed_thing.under, node, placer, itemstack) or itemstack
195 local cauldron = fill_cauldron(node.name, "mclx_core:river_water_source")
196 if cauldron then
197 -- Increase water level of cauldron by 1
198 minetest.set_node(pointed_thing.under, {name=cauldron})
199 minetest.sound_play("mcl_potions_bottle_pour", {pos=pointed_thing.under, gain=0.5, max_hear_range=16})
200 return "mcl_potions:glass_bottle"
204 -- Drink the water by default
205 return minetest.do_item_eat(0, "mcl_potions:glass_bottle", itemstack, placer, pointed_thing)
206 end,
207 on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
212 local how_to_drink = "To drink it, wield it, then rightclick."
214 minetest.register_craftitem("mcl_potions:potion_awkward", {
215 description = "Awkward Potion",
216 _doc_items_longdesc = "This potion has an awkward taste and is used for brewing more potions. Drinking it has no effect.",
217 _doc_items_usagehelp = how_to_drink,
218 stack_max = 1,
219 inventory_image = potion_image("#0000FF"),
220 wield_image = potion_image("#0000FF"),
221 groups = {brewitem=1, food=3, can_eat_when_full=1},
222 on_place = minetest.item_eat(0, "mcl_potions:glass_bottle"),
223 on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
225 minetest.register_craftitem("mcl_potions:potion_mundane", {
226 description = "Mundane Potion",
227 _doc_items_longdesc = "This potion has a clean taste and is used for brewing more potions. Drinking it has no effect.",
228 _doc_items_usagehelp = how_to_drink,
229 stack_max = 1,
230 inventory_image = potion_image("#0000FF"),
231 wield_image = potion_image("#0000FF"),
232 groups = {brewitem=1, food=3, can_eat_when_full=1},
233 on_place = minetest.item_eat(0, "mcl_potions:glass_bottle"),
234 on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
236 minetest.register_craftitem("mcl_potions:potion_thick", {
237 description = "Thick Potion",
238 _doc_items_longdesc = "This potion has a bitter taste and is used for brewing more potions. Drinking it has no effect.",
239 _doc_items_usagehelp = how_to_drink,
240 stack_max = 1,
241 inventory_image = potion_image("#0000FF"),
242 wield_image = potion_image("#0000FF"),
243 groups = {brewitem=1, food=3, can_eat_when_full=1},
244 on_place = minetest.item_eat(0, "mcl_potions:glass_bottle"),
245 on_secondary_use = minetest.item_eat(0, "mcl_potions:glass_bottle"),
248 minetest.register_craftitem("mcl_potions:speckled_melon", {
249 description = "Glistering Melon",
250 _doc_items_longdesc = brewhelp,
251 stack_max = 64,
252 groups = { brewitem = 1 },
253 inventory_image = "mcl_potions_melon_speckled.png",
256 minetest.register_craft({
257 output = "mcl_potions:speckled_melon",
258 recipe = {
259 {'mcl_core:gold_nugget', 'mcl_core:gold_nugget', 'mcl_core:gold_nugget'},
260 {'mcl_core:gold_nugget', 'mcl_farming:melon_item', 'mcl_core:gold_nugget'},
261 {'mcl_core:gold_nugget', 'mcl_core:gold_nugget', 'mcl_core:gold_nugget'},
265 minetest.register_craftitem("mcl_potions:dragon_breath", {
266 description = "Dragon's Breath",
267 _doc_items_longdesc = brewhelp,
268 wield_image = "mcl_potions_dragon_breath.png",
269 inventory_image = "mcl_potions_dragon_breath.png",
270 groups = { brewitem = 1 },
271 stack_max = 64,