Tidy code and remove stack_max limit of Glass Bottle

This commit is contained in:
Sys Quatre 2020-07-13 00:44:28 +02:00
parent 36d76ca7fb
commit 0e277c51fb

View File

@ -17,11 +17,6 @@
-- You should have received a copy of the GNU General Public License -- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>. -- along with this program. If not, see <http://www.gnu.org/licenses/>.
--changes so that bottles can't stack
minetest.override_item("vessels:glass_bottle", {
stack_max = 3,
})
local vessels_shelf_formspec = local vessels_shelf_formspec =
"size[8,7;]".. "size[8,7;]"..
default.gui_bg.. default.gui_bg..
@ -543,14 +538,16 @@ minetest.register_node("witchcraft:pot", {
{-0.375, 0.3125, -0.375, -0.3125, 0.375, 0.375}, -- NodeBox20 {-0.375, 0.3125, -0.375, -0.3125, 0.375, 0.375}, -- NodeBox20
} }
}, },
on_rightclick = function(pos, node, clicker, item, _) on_rightclick = function(pos, node, clicker, itemstack, _)
local wield_item = clicker:get_wielded_item():get_name() local wield_item = itemstack:get_name()
if wield_item == "bucket:bucket_water" or if wield_item == "bucket:bucket_water" or
wield_item == "bucket:bucket_river_water" then wield_item == "bucket:bucket_river_water" then
minetest.set_node(pos, {name="witchcraft:pot_blue", param2=node.param2}) minetest.set_node(pos, {name="witchcraft:pot_blue", param2=node.param2})
item:replace("bucket:bucket_empty") return ItemStack("bucket:bucket_empty")
elseif wield_item == "vessels:drinking_glass" then elseif wield_item == "vessels:drinking_glass" then
item:replace("witchcraft:bottle_slime") itemstack:set_count(itemstack:get_count() - 1)
minetest.env:add_item({x=pos.x, y=pos.y+1.5, z=pos.z}, "witchcraft:bottle_slime")
end end
end, end,
groups = {cracky=1, falling_node=1, oddly_breakable_by_hand=1} groups = {cracky=1, falling_node=1, oddly_breakable_by_hand=1}
@ -650,31 +647,35 @@ minetest.register_node("witchcraft:pot_"..color, {
{-0.4375, 0.375, -0.4375, 0.4375, 0.5, 0.4375}, -- NodeBox7 {-0.4375, 0.375, -0.4375, 0.4375, 0.5, 0.4375}, -- NodeBox7
} }
}, },
on_rightclick = function(pos, node, clicker, item, _) on_rightclick = function(pos, node, clicker, itemstack, _)
local wield_item = clicker:get_wielded_item():get_name() local wield_item = itemstack:get_name()
if wield_item == "vessels:glass_bottle" and clicker:get_wielded_item():get_count() == 3 then
item:replace("witchcraft:potion_"..color) if wield_item == "vessels:glass_bottle" then
minetest.env:add_item({x=pos.x, y=pos.y+1.5, z=pos.z}, "witchcraft:potion_"..color) local wield_items_count = itemstack:get_count()
minetest.env:add_item({x=pos.x, y=pos.y+1.5, z=pos.z}, "witchcraft:potion_"..color) local potions_count = (wield_items_count <= 3 and wield_items_count) or 3
local wield_items_left = (wield_items_count - potions_count)
itemstack:set_count((wield_items_left < 0 and 0) or wield_items_left)
for i = 1, potions_count do
minetest.env:add_item({x=pos.x, y=pos.y+1.5, z=pos.z}, "witchcraft:potion_"..color)
end
minetest.set_node(pos, {name="witchcraft:pot", param2=node.param2}) minetest.set_node(pos, {name="witchcraft:pot", param2=node.param2})
elseif wield_item == "vessels:glass_bottle" and clicker:get_wielded_item():get_count() ~= 3 then elseif wield_item == ingredient then
item:replace("witchcraft:potion_"..color)
minetest.set_node(pos, {name="witchcraft:pot", param2=node.param2})
else
if wield_item == ingredient then
minetest.set_node(pos, {name="witchcraft:pot_"..newcolor, param2=node.param2}) minetest.set_node(pos, {name="witchcraft:pot_"..newcolor, param2=node.param2})
item:take_item() itemstack:take_item()
elseif wield_item == ingredient2 then elseif wield_item == ingredient2 then
minetest.set_node(pos, {name="witchcraft:pot_"..newcolor2, param2=node.param2}) minetest.set_node(pos, {name="witchcraft:pot_"..newcolor2, param2=node.param2})
item:take_item() itemstack:take_item()
elseif wield_item == "bucket:bucket_water" then elseif wield_item == "bucket:bucket_water" or
wield_item == "bucket:bucket_river_water" then
minetest.set_node(pos, {name="witchcraft:pot_blue", param2=node.param2}) minetest.set_node(pos, {name="witchcraft:pot_blue", param2=node.param2})
item:replace("bucket:bucket_empty") return ItemStack("bucket:bucket_empty")
elseif wield_item == "witchcraft:potion_"..combine then elseif wield_item == "witchcraft:potion_"..combine then
minetest.set_node(pos, {name="witchcraft:pot_"..cresult, param2=node.param2}) minetest.set_node(pos, {name="witchcraft:pot_"..cresult, param2=node.param2})
item:replace("vessels:glass_bottle") itemstack:replace("vessels:glass_bottle")
end end
end
end, end,
groups = {cracky=1, falling_node=1, oddly_breakable_by_hand=1} groups = {cracky=1, falling_node=1, oddly_breakable_by_hand=1}
}) })