123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- -- modified by dcc to work with hoppers
- --
- -- NOTE: input hopper goes on SIDE not top... to allow punching of barrel - placing hopper to point correctly
- -- may require screwdriver
- --
- -- output hopper goes below barrel
- --
- -- If testing - please note the abm's only fire every 30 seconds so it can take some time
- --
- compost = {}
- compost.items = {}
- compost.groups = {}
- function compost.register_item(name)
- compost.items[name] = true
- end
- function compost.register_group(name)
- compost.groups[name] = true
- end
- function compost.can_compost(name)
- if compost.items[name] then
- return true
- else
- for k, i in pairs(minetest.registered_items[name].groups) do
- if i > 0 then
- if compost.groups[tostring(k)] then
- return true
- end
- end
- end
- return false
- end
- end
- -- grass
- compost.register_item("default:grass_1")
- compost.register_item("default:junglegrass")
- -- leaves
- compost.register_group("leaves")
- -- dirt
- compost.register_item("default:dirt")
- compost.register_item("default:dirt_with_grass")
- -- stick
- compost.register_item("default:stick")
- -- flowers
- compost.register_item("flowers:geranium")
- compost.register_item("flowers:tulip")
- compost.register_item("flowers:rose")
- compost.register_item("flowers:dandelion_yellow")
- compost.register_item("flowers:dandelion_white")
- -- food
- compost.register_item("farming:bread")
- compost.register_item("farming:wheat")
- -- groups
- compost.register_group("plant")
- compost.register_group("flower")
- -- dcc
- local wood_barrel_src_on_construct = function(pos)
- local inv = minetest.get_meta(pos):get_inventory()
- inv:set_size("src", 1)
- end
- local wood_barrel_dst_on_construct = function(pos)
- local inv = minetest.get_meta(pos):get_inventory()
- inv:set_size("dst", 1)
- -- this is for wood barrel #3 which has 1 compost ready for taking
- --
- inv:set_stack('dst', 1, 'compost:compost')
- local meta = minetest.get_meta(pos)
- meta:set_string("formspec",
- "size[8,5.3]" ..
- default.gui_bg ..
- default.gui_bg_img ..
- default.gui_slots ..
- "list[current_name;dst;3.5,0;1,1;]" ..
- "list[current_player;main;0,1.15;8,1;]" ..
- "list[current_player;main;0,2.38;8,3;8]" ..
- "listring[current_name;main]" ..
- "listring[current_player;main]" ..
- default.get_hotbar_bg(0,1.15)
- )
- end
- -- Only allow compostable items to be placed in input
- -- allow_metadata_inventory_put is a pre-check prior to actual
- -- putting...
- --
- local wood_barrel_allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- --print ("[compost] wood_barrel_allow_metadata_inventory_put ", listname)
- if listname == "src" then
- local stackname = stack:get_name()
- --print ("[compost] wood_barrel_allow_metadata_inventory_put ", stackname )
- if compost.can_compost(stackname) then
- --print ("[compost] succeed wood_barrel_allow_metadata_inventory_put ", stackname)
- return 1 -- take only 1 item
- end
- end
- return 0
- end
- -- actual put
- --
- local wood_barrel_on_metadata_inventory_put = function(pos, listname, index, stack, player)
- --print ("[compost] wood_barrel_on_metadata_inventory_put ")
- if listname == "src" then
- -- check again just in case
- --
- local stackname = stack:get_name()
- if compost.can_compost(stackname) then
- -- we received a compostable item - change to new node type
- --
- minetest.set_node(pos, {name = "compost:wood_barrel_1"})
- return
- end
- end
- end
- -- Versions of callbacks for the inaccessible versions of the barrel
- --
- -- nope
- local wood_barrelNope_allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- --print ("[compost] wood_barrelNope_allow_metadata_inventory_put ")
- return 0
- end
- -- nope
- local wood_barrelNope_on_metadata_inventory_put = function(pos, listname, index, stack, player)
- --print ("[compost] wood_barrelNope_on_metadata_inventory_put ")
- return
- end
- -- nope
- local wood_barrelNope_allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- -- nope you can't take out here
- return 0
- end
- -- nope
- local wood_barrelNope_on_metadata_inventory_take = function(pos, listname, index, stack, player)
- return
- end
- -- Versions of callbacks for when compost is ready....
- -- nope
- local wood_barrel_allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- -- YES you can take out here - we know it is 1 because we put it there with the constructor
- return 1
- end
- -- nope
- local wood_barrel_on_metadata_inventory_take = function(pos, listname, index, stack, player)
- -- when emptied we revert to a plain wood barrel
- local node = minetest.get_node (pos)
- if node.name == "compost:wood_barrel_3" then
- minetest.set_node(pos, {name = "compost:wood_barrel"})
- return ItemStack("compost:compost")
- end
- return
- end
- minetest.register_node("compost:wood_barrel", {
- description = "Wood Barrel",
- tiles = {"default_wood.png"},
- drawtype = "nodebox",
- node_box = {
- type = "fixed",
- fixed = {{-1/2, -1/2, -1/2, 1/2, -3/8, 1/2},
- {-1/2, -1/2, -1/2, -3/8, 1/2, 1/2},
- {3/8, -1/2, -1/2, 1/2, 1/2, 1/2},
- {-1/2, -1/2, -1/2, 1/2, 1/2, -3/8},
- {-1/2, -1/2, 3/8, 1/2, 1/2, 1/2}},
- },
- paramtype = "light",
- is_ground_content = false,
- groups = {choppy = 3},
- sounds = default.node_sound_wood_defaults(),
- on_construct = wood_barrel_src_on_construct, -- dcc
- allow_metadata_inventory_put = wood_barrel_allow_metadata_inventory_put, -- dcc
- on_metadata_inventory_put = wood_barrel_on_metadata_inventory_put, -- dcc
- allow_metadata_inventory_take = wood_barrelNope_allow_metadata_inventory_take, -- dcc
- on_metadata_inventory_take = wood_barrelNope_on_metadata_inventory_take, -- dcc
- on_punch = function(pos, node, puncher, pointed_thing)
- local wielded_item = puncher:get_wielded_item():get_name()
- if compost.can_compost(wielded_item) then
- minetest.set_node(pos, {name = "compost:wood_barrel_1"})
- local w = puncher:get_wielded_item()
- if not(minetest.settings:get_bool('creative_mode')) then
- w:take_item(1)
- puncher:set_wielded_item(w)
- end
- end
- end
- })
- minetest.register_node("compost:wood_barrel_1", {
- description = "Wood Barrel with compost",
- tiles = {"default_wood.png^compost_compost_1.png", "default_wood.png"},
- drawtype = "nodebox",
- node_box = {
- type = "fixed",
- fixed = {{-1/2, -1/2, -1/2, 1/2, -3/8, 1/2},
- {-1/2, -1/2, -1/2, -3/8, 1/2, 1/2},
- {3/8, -1/2, -1/2, 1/2, 1/2, 1/2},
- {-1/2, -1/2, -1/2, 1/2, 1/2, -3/8},
- {-1/2, -1/2, 3/8, 1/2, 1/2, 1/2},
- {-3/8, -1/2, -3/8, 3/8, 3/8, 3/8}},
- },
- paramtype = "light",
- is_ground_content = false,
- allow_metadata_inventory_put = wood_barrelNope_allow_metadata_inventory_put, -- dcc
- on_metadata_inventory_put = wood_barrelNope_on_metadata_inventory_put, -- dcc
- allow_metadata_inventory_take = wood_barrelNope_allow_metadata_inventory_take, -- dcc
- on_metadata_inventory_take = wood_barrelNope_on_metadata_inventory_take, -- dcc
- groups = {choppy = 3},
- sounds = default.node_sound_wood_defaults(),
- })
- minetest.register_node("compost:wood_barrel_2", {
- description = "Wood Barrel with compost",
- tiles = {"default_wood.png^compost_compost_2.png", "default_wood.png"},
- drawtype = "nodebox",
- node_box = {
- type = "fixed",
- fixed = {{-1/2, -1/2, -1/2, 1/2, -3/8, 1/2},
- {-1/2, -1/2, -1/2, -3/8, 1/2, 1/2},
- {3/8, -1/2, -1/2, 1/2, 1/2, 1/2},
- {-1/2, -1/2, -1/2, 1/2, 1/2, -3/8},
- {-1/2, -1/2, 3/8, 1/2, 1/2, 1/2},
- {-3/8, -1/2, -3/8, 3/8, 3/8, 3/8}},
- },
- paramtype = "light",
- is_ground_content = false,
- allow_metadata_inventory_put = wood_barrelNope_allow_metadata_inventory_put, -- dcc
- on_metadata_inventory_put = wood_barrelNope_on_metadata_inventory_put, -- dcc
- allow_metadata_inventory_take = wood_barrelNope_allow_metadata_inventory_take, -- dcc
- on_metadata_inventory_take = wood_barrelNope_on_metadata_inventory_take, -- dcc
- groups = {choppy = 3},
- sounds = default.node_sound_wood_defaults(),
- })
- minetest.register_node("compost:wood_barrel_3", {
- description = "Wood Barrel",
- tiles = {"default_wood.png^compost_compost_3.png", "default_wood.png"},
- drawtype = "nodebox",
- node_box = {
- type = "fixed",
- fixed = {{-1/2, -1/2, -1/2, 1/2, -3/8, 1/2},
- {-1/2, -1/2, -1/2, -3/8, 1/2, 1/2},
- {3/8, -1/2, -1/2, 1/2, 1/2, 1/2},
- {-1/2, -1/2, -1/2, 1/2, 1/2, -3/8},
- {-1/2, -1/2, 3/8, 1/2, 1/2, 1/2},
- {-3/8, -1/2, -3/8, 3/8, 3/8, 3/8}},
- },
- paramtype = "light",
- is_ground_content = false,
- groups = {choppy = 3},
- on_construct = wood_barrel_dst_on_construct, -- dcc
- allow_metadata_inventory_put = wood_barrelNope_allow_metadata_inventory_put, -- dcc
- on_metadata_inventory_put = wood_barrelNope_on_metadata_inventory_put, -- dcc
- allow_metadata_inventory_take = wood_barrel_allow_metadata_inventory_take, -- dcc
- on_metadata_inventory_take = wood_barrel_on_metadata_inventory_take, -- dcc
- sounds = default.node_sound_wood_defaults(),
- on_punch = function(pos, node, player, pointed_thing)
- local p = {x = pos.x + math.random(0, 5)/5 - 0.5, y = pos.y+1, z = pos.z + math.random(0, 5)/5 - 0.5}
- minetest.add_item(p, {name = "compost:compost"})
- minetest.set_node(pos, {name = "compost:wood_barrel"})
- end
- })
- minetest.register_abm({
- nodenames = {"compost:wood_barrel_1"},
- interval = 30,
- chance = 5,
- action = function(pos, node, active_object_count, active_object_count_wider)
- minetest.set_node(pos, {name = "compost:wood_barrel_2"})
- end,
- })
- minetest.register_abm({
- nodenames = {"compost:wood_barrel_2"},
- interval = 30,
- chance = 3,
- action = function(pos, node, active_object_count, active_object_count_wider)
- minetest.set_node(pos, {name = "compost:wood_barrel_3"})
- end,
- })
- minetest.register_craft({
- output = "compost:wood_barrel",
- recipe = {
- {"default:wood", "", "default:wood"},
- {"default:wood", "", "default:wood"},
- {"default:wood", "stairs:slab_wood", "default:wood"}
- }
- })
- minetest.register_node("compost:compost", {
- description = "Compost",
- tiles = {"compost_compost.png"},
- groups = {crumbly = 3},
- sounds = default.node_sound_dirt_defaults(),
- })
- minetest.register_node("compost:garden_soil", {
- description = "Garden Soil",
- tiles = {"compost_garden_soil.png"},
- groups = {crumbly = 3, soil=3, grassland = 1, wet = 1},
- sounds = default.node_sound_dirt_defaults(),
- })
- minetest.register_craft({
- output = "compost:garden_soil",
- recipe = {
- {"compost:compost", "compost:compost"},
- }
- })
- if minetest.get_modpath ("tubelib") and tubelib then
- --print ("[compost] found tubelib")
- -- Thanks to @joe7575
- tubelib.register_node ("compost:wood_barrel", {
- "compost:wood_barrel_1",
- "compost:wood_barrel_2",
- "compost:wood_barrel_3"
- }, {
- on_push_item = function (pos, side, item, player_name)
- local node = minetest.get_node (pos)
- if node.name == "compost:wood_barrel" and compost.can_compost(item:get_name()) then
- minetest.set_node(pos, {name = "compost:wood_barrel_1"})
- return true
- else
- return false
- end
- end,
- on_unpull_item = function (pos, side, item, player_name)
- minetest.set_node(pos, {name = "compost:wood_barrel_3"})
- return true
- end,
- on_pull_item = function (pos, side, player_name)
- local node = minetest.get_node (pos)
- if node.name == "compost:wood_barrel_3" then
- minetest.set_node(pos, {name = "compost:wood_barrel"})
- return ItemStack("compost:compost")
- end
- return nil
- end,
- })
- end
- -- dcc
- if minetest.get_modpath ("hopper") and hopper then
- --print ("[compost] found hopper")
- hopper:add_container({
- {"top", "compost:wood_barrel_3", "dst"}, -- take compost from above into hopper below
- {"side", "compost:wood_barrel", "src"}, -- insert compostable items below to be composted from hopper at side
- })
- end
|