mirror of
				https://github.com/sys4-fr/server-nalc.git
				synced 2025-11-04 05:55:28 +01:00 
			
		
		
		
	Make empty buckets stackable
from mt_game
This commit is contained in:
		@@ -106,44 +106,56 @@ end
 | 
			
		||||
 | 
			
		||||
-- Empty Bucket code by Casimir.
 | 
			
		||||
 | 
			
		||||
minetest.register_craftitem(":bucket:bucket_empty", {
 | 
			
		||||
minetest.register_craftitem("bucket:bucket_empty", {
 | 
			
		||||
	description = "Empty Bucket",
 | 
			
		||||
	inventory_image = "bucket.png",
 | 
			
		||||
	stack_max = 99,
 | 
			
		||||
	liquids_pointable = true,
 | 
			
		||||
	on_use = function(itemstack, user, pointed_thing)
 | 
			
		||||
		-- Must be pointing to a node.
 | 
			
		||||
		-- Must be pointing to node
 | 
			
		||||
		if pointed_thing.type ~= "node" then
 | 
			
		||||
			return
 | 
			
		||||
		end
 | 
			
		||||
		-- Check if pointing to a liquid source.
 | 
			
		||||
		-- Check if pointing to a liquid source
 | 
			
		||||
		local node = minetest.get_node(pointed_thing.under)
 | 
			
		||||
		local liquiddef = bucket.liquids[node.name]
 | 
			
		||||
		if liquiddef ~= nil and liquiddef.itemname ~= nil and
 | 
			
		||||
			node.name == liquiddef.source then
 | 
			
		||||
		local item_count = user:get_wielded_item():get_count()
 | 
			
		||||
 | 
			
		||||
		if liquiddef ~= nil
 | 
			
		||||
		and liquiddef.itemname ~= nil
 | 
			
		||||
		and node.name == liquiddef.source then
 | 
			
		||||
			if check_protection(pointed_thing.under,
 | 
			
		||||
					user:get_player_name(),
 | 
			
		||||
					"take ".. node.name) then
 | 
			
		||||
				user:get_player_name(),
 | 
			
		||||
				"take ".. node.name) then
 | 
			
		||||
				return
 | 
			
		||||
			end
 | 
			
		||||
			-- Only one bucket: replace.
 | 
			
		||||
			local count = itemstack:get_count()
 | 
			
		||||
			if count == 1 then
 | 
			
		||||
				minetest.add_node(pointed_thing.under, {name="air"})
 | 
			
		||||
				return ItemStack({name = liquiddef.itemname,
 | 
			
		||||
					metadata = tostring(node.param2)})
 | 
			
		||||
			end
 | 
			
		||||
			-- Stacked buckets: add a filled bucket, replace stack.
 | 
			
		||||
 | 
			
		||||
-- default set to return filled bucket
 | 
			
		||||
			local giving_back = liquiddef.itemname
 | 
			
		||||
 | 
			
		||||
-- check if holding more than 1 empty bucket
 | 
			
		||||
			if item_count > 1 then
 | 
			
		||||
 | 
			
		||||
			-- if space in inventory add filled bucked, otherwise drop as item
 | 
			
		||||
			local inv = user:get_inventory()
 | 
			
		||||
			if inv:room_for_item("main", liquiddef.itemname) then
 | 
			
		||||
				count = count - 1
 | 
			
		||||
				itemstack:set_count(count)
 | 
			
		||||
			if inv:room_for_item("main", {name=liquiddef.itemname}) then
 | 
			
		||||
				inv:add_item("main", liquiddef.itemname)
 | 
			
		||||
				return ItemStack(itemstack)
 | 
			
		||||
			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
 | 
			
		||||
 | 
			
		||||
			-- set to return empty buckets minus 1
 | 
			
		||||
			giving_back = "bucket:bucket_empty "..tostring(item_count-1)
 | 
			
		||||
 | 
			
		||||
		end
 | 
			
		||||
	end,
 | 
			
		||||
 | 
			
		||||
		minetest.add_node(pointed_thing.under, {name="air"})
 | 
			
		||||
 | 
			
		||||
		return ItemStack(giving_back)
 | 
			
		||||
	end
 | 
			
		||||
end,
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
bucket.register_liquid(
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user