1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-16 23:40:31 +01:00

Make empty buckets stackable

from mt_game
This commit is contained in:
Ombridride 2015-03-03 21:14:32 +01:00
parent 731cc4e82e
commit a85c16af47

View File

@ -106,44 +106,56 @@ end
-- Empty Bucket code by Casimir. -- Empty Bucket code by Casimir.
minetest.register_craftitem(":bucket:bucket_empty", { minetest.register_craftitem("bucket:bucket_empty", {
description = "Empty Bucket", description = "Empty Bucket",
inventory_image = "bucket.png", inventory_image = "bucket.png",
stack_max = 99,
liquids_pointable = true, liquids_pointable = true,
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
-- Must be pointing to a node. -- Must be pointing to node
if pointed_thing.type ~= "node" then if pointed_thing.type ~= "node" then
return return
end end
-- Check if pointing to a liquid source. -- Check if pointing to a liquid source
local node = minetest.get_node(pointed_thing.under) local node = minetest.get_node(pointed_thing.under)
local liquiddef = bucket.liquids[node.name] local liquiddef = bucket.liquids[node.name]
if liquiddef ~= nil and liquiddef.itemname ~= nil and local item_count = user:get_wielded_item():get_count()
node.name == liquiddef.source then
if liquiddef ~= nil
and liquiddef.itemname ~= nil
and node.name == liquiddef.source then
if check_protection(pointed_thing.under, if check_protection(pointed_thing.under,
user:get_player_name(), user:get_player_name(),
"take ".. node.name) then "take ".. node.name) then
return return
end end
-- Only one bucket: replace.
local count = itemstack:get_count() -- default set to return filled bucket
if count == 1 then local giving_back = liquiddef.itemname
minetest.add_node(pointed_thing.under, {name="air"})
return ItemStack({name = liquiddef.itemname, -- check if holding more than 1 empty bucket
metadata = tostring(node.param2)}) if item_count > 1 then
end
-- Stacked buckets: add a filled bucket, replace stack. -- if space in inventory add filled bucked, otherwise drop as item
local inv = user:get_inventory() local inv = user:get_inventory()
if inv:room_for_item("main", liquiddef.itemname) then if inv:room_for_item("main", {name=liquiddef.itemname}) then
count = count - 1
itemstack:set_count(count)
inv:add_item("main", liquiddef.itemname) inv:add_item("main", liquiddef.itemname)
return ItemStack(itemstack)
else else
minetest.chat_send_player(user:get_player_name(), "Your inventory is full.") local pos = user:getpos()
pos.y = math.floor(pos.y + 0.5)
core.add_item(pos, liquiddef.itemname)
end end
-- set to return empty buckets minus 1
giving_back = "bucket:bucket_empty "..tostring(item_count-1)
end end
end,
minetest.add_node(pointed_thing.under, {name="air"})
return ItemStack(giving_back)
end
end,
}) })
bucket.register_liquid( bucket.register_liquid(