minetest.register_craftitem("farming:cotton_seed", {
	description = "Cotton Seeds",
	inventory_image = "farming_cotton_seed.png",
	on_place = function(itemstack, placer, pointed_thing)
		local above = minetest.env:get_node(pointed_thing.above)
		if above.name == "air" then
			above.name = "farming:cotton_1"
			minetest.env:set_node(pointed_thing.above, above)
			itemstack:take_item(1)
			return itemstack
		end
	end
})

minetest.register_node("farming:cotton_1", {
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	drawtype = "raillike",
	drop = "",
	tiles = {"farming_cotton_seed.png"},
	selection_box = {
    type = "fixed",
    fixed = {
      {-0.5, -0.5, -0.5, 0.5, -0.5, 0.5}
    },
  },
	groups = {snappy=3, flammable=2, not_in_creative_inventory=1, attached_node=1},
	sounds = default.node_sound_leaves_defaults(),
})

minetest.register_node("farming:cotton_2", {
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	drawtype = "plantlike",
	drop = "",
	tiles = {"farming_cotton_2.png"},
	selection_box = {
		type = "fixed",
		fixed = {
			{-0.5, -0.5, -0.5, 0.5, -0.5+12/16, 0.5}
		},
	},
	groups = {snappy=3, flammable=2, not_in_creative_inventory=1, attached_node=1},
	sounds = default.node_sound_leaves_defaults(),
})

minetest.register_node("farming:cotton", {
	paramtype = "light",
	sunlight_propagates = true,
	walkable = false,
	drawtype = "nodebox",
	tiles = {"farming_cotton.png"},
	node_box = { 
    type = "fixed",
    fixed = {
      {-0.5/5, -2.5/5, -0.5/5, 0.5/5, -1.5/5, 0.5/5},
      {0.5/5, -1.5/5, -1.5/5, 1.5/5, 1.5/5, -0.5/5},
      {-1.5/5, -1.5/5, 0.5/5, -0.5/5, 1.5/5, 1.5/5},
      {0.5/5, -1.5/5, 0.5/5, 1.5/5, 1.5/5, 1.5/5},
      {-1.5/5, -1.5/5, -1.5/5, -0.5/5, 1.5/5, -0.5/5},
      {-2.5/5, 0.5/5, -2.5/5, -1.5/5, 2.5/5, -1.5/5},
      {1.5/5, 0.5/5, -2.5/5, 2.5/5, 2.5/5, -1.5/5},
      {1.5/5, 0.5/5, 1.5/5, 2.5/5, 2.5/5, 2.5/5},
      {-2.5/5, 0.5/5, 1.5/5, -1.5/5, 2.5/5, 2.5/5},
    }
  },
	drop = {
		max_items = 6,
		items = {
			{ items = {'farming:cotton_seed'} },
			{ items = {'farming:cotton_seed'}, rarity = 2},
			{ items = {'farming:cotton_seed'}, rarity = 5},
			{ items = {'farming:string'} },
			{ items = {'farming:string'}, rarity = 2 },
			{ items = {'farming:string'}, rarity = 5 }
		}
	},
	groups = {snappy=3, flammable=2, not_in_creative_inventory=1, attached_node=1},
	sounds = default.node_sound_leaves_defaults(),
})

farming:add_plant("farming:cotton", {"farming:cotton_1", "farming:cotton_2"}, 50, 20)

minetest.register_craftitem("farming:string", {
	description = "String",
	inventory_image = "farming_string.png",
})

minetest.register_craft({
	output = "wool:white",
	recipe = {{"farming:string"}}
})

-- ========= FUEL =========
minetest.register_craft({
	type = "fuel",
	recipe = "farming:cotton_seed",
	burntime = 1
})

minetest.register_craft({
	type = "fuel",
	recipe = "farming:string",
	burntime = 1
})
