PyuTest.make_item("pyutest_buckets:bucket", "Empty Bucket", {}, "pyutest-bucket.png", {
	pointabilities = {
		nodes = {
			["group:liquid_source"] = true
		}
	},

	on_place = function(itemstack, user, pointed_thing)
		if user == nil then
			return
		end

		if pointed_thing.type == "node" then
			local pos = pointed_thing.under
			local node = core.get_node(pos)
			local def = core.registered_nodes[node.name]

			if def.__bucket then
				PyuTest.give_item_or_drop(ItemStack(def.__bucket), user:get_inventory(), "main", user:get_pos())
				core.remove_node(pos)

				itemstack:take_item()
				return itemstack
			end
		end
	end
})

core.register_craft({
	output = "pyutest_buckets:bucket",
	recipe = {
		{ "pyutest_ores:iron_ingot", "",                        "pyutest_ores:iron_ingot" },
		{ "",                        "pyutest_ores:iron_ingot", "" }
	}
})

PyuTest.make_liquid_bucket = function(name, desc, source, color, groups)
	local colorspec = core.colorspec_to_colorstring(color)
	local texture = string.format("pyutest-bucket.png^(pyutest-bucket-overlay.png^[colorize:%s)", colorspec)

	PyuTest.make_node(name, desc, PyuTest.util.tableconcat({
		bucket = 1
	}, groups or {}), {}, {
		drawtype = "airlike",
		walkable = false,
		pointable = false,
		wield_image = texture,
		inventory_image = texture,

		after_place_node = function(pos, placer)
			if placer == nil then return end
			PyuTest.give_item_or_drop(ItemStack("pyutest_buckets:bucket"), placer:get_inventory(), "main", placer:get_pos())
			core.set_node(pos, { name = source })
		end,

		__on_dispense = function (pos, itemstack)
			itemstack:take_item()

			-- TODO: Eject liquid

			return itemstack
		end
	})

	core.override_item(source, {
		__bucket = name,
	})
end

PyuTest.make_liquid_bucket("pyutest_buckets:water_bucket", "Bucket of Water",
"pyutest_blocks:water_source", "blue", {
	brewing_fuel = 1,
})
PyuTest.make_liquid_bucket("pyutest_buckets:lava_bucket", "Bucket of Lava", "pyutest_blocks:lava_source", "orange")
PyuTest.make_liquid_bucket("pyutest_buckets:acid_bucket", "Bucket of Acid", "pyutest_blocks:liquid_acid_source", "#6c7232")
PyuTest.make_liquid_bucket("pyutest_buckets:oil_bucket", "Bucket of Oil", "pyutest_blocks:oil_source", PyuTest.COLORS.black[2])
