From 91ef21c55b9dd44d2c86dd0a0d5d74ed5798a378 Mon Sep 17 00:00:00 2001 From: anarquimico Date: Sun, 6 Nov 2022 17:49:32 -0300 Subject: [PATCH 1/5] Integrate hoppers with composter --- mods/ITEMS/mcl_hoppers/init.lua | 65 +++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index 87831490f..d17a3c16a 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -415,6 +415,71 @@ minetest.register_abm({ end, }) +minetest.register_abm({ + label = "Hopper/composter integration", + nodenames = {"mcl_hoppers:hopper", "mcl_hoppers:hopper_side"}, + neighbors = {"mcl_composters:composter", "mcl_composters:composter_1", "mcl_composters:composter_2", + "mcl_composters:composter_3", "mcl_composters:composter_4", "mcl_composters:composter_5", + "mcl_composters:composter_6", "mcl_composters:composter_7", "mcl_composters:composter_ready"}, + interval = 1.0, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local uppos = {x=pos.x,y=pos.y+1,z=pos.z} + local downpos = {x=pos.x,y=pos.y-1,z=pos.z} + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + -- Get bonemeal from composter above + local upnode = minetest.get_node(uppos) + if upnode.name == "mcl_composters:composter_ready" then + minetest.swap_node(uppos, {name="mcl_composters:composter"}) + inv:add_item("main", "mcl_dye:white") + end + + --Add compostable itens into composter below + local downnode = minetest.get_node(downpos) + if downnode.name == "mcl_composters:composter" or downnode.name == "mcl_composters:composter_1" + or downnode.name == "mcl_composters:composter_2" or downnode.name == "mcl_composters:composter_3" + or downnode.name == "mcl_composters:composter_4" or downnode.name == "mcl_composters:composter_5" + or downnode.name == "mcl_composters:composter_6" or downnode.name == "mcl_composters:composter_7" then + local itemcomp = inv:get_list("main") + for i, k in ipairs(itemcomp) do + local compchance = minetest.get_item_group(itemcomp[i]:get_name(), "compostability") + if compchance > 0 then + -- TODO: fix bug where take multiple compostable items + itemcomp[i]:take_item() + inv:set_list("main", itemcomp) + local rand = math.random(0,100) + if compchance >= rand then + local level = 0 + if downnode.name == "mcl_composters:composter_1" then + level = 1 + elseif downnode.name == "mcl_composters:composter_2" then + level = 2 + elseif downnode.name == "mcl_composters:composter_3" then + level = 3 + elseif downnode.name == "mcl_composters:composter_4" then + level = 4 + elseif downnode.name == "mcl_composters:composter_5" then + level = 5 + elseif downnode.name == "mcl_composters:composter_6" then + level = 6 + elseif downnode.name == "mcl_composters:composter_7" then + level = 7 + end + mcl_dye.add_bone_meal_particle(vector.offset(downpos, 0, level/8, 0)) + if level < 7 then + level = level + 1 + else + level = "ready" + end + minetest.swap_node(downpos, {name="mcl_composters:composter_" .. level}) + end + end + end + end + end, +}) + minetest.register_abm({ label = "Side-hopper/container item exchange", nodenames = {"mcl_hoppers:hopper_side"}, From f61b072d39408b2c639ecfffc9d5c045470f173f Mon Sep 17 00:00:00 2001 From: anarquimico Date: Mon, 7 Nov 2022 22:10:35 -0300 Subject: [PATCH 2/5] Fixed compostable item comsumption. --- mods/ITEMS/mcl_hoppers/init.lua | 143 +++++++++++++++++--------------- 1 file changed, 78 insertions(+), 65 deletions(-) diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index d17a3c16a..b9af5a056 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -415,71 +415,6 @@ minetest.register_abm({ end, }) -minetest.register_abm({ - label = "Hopper/composter integration", - nodenames = {"mcl_hoppers:hopper", "mcl_hoppers:hopper_side"}, - neighbors = {"mcl_composters:composter", "mcl_composters:composter_1", "mcl_composters:composter_2", - "mcl_composters:composter_3", "mcl_composters:composter_4", "mcl_composters:composter_5", - "mcl_composters:composter_6", "mcl_composters:composter_7", "mcl_composters:composter_ready"}, - interval = 1.0, - chance = 1, - action = function(pos, node, active_object_count, active_object_count_wider) - local uppos = {x=pos.x,y=pos.y+1,z=pos.z} - local downpos = {x=pos.x,y=pos.y-1,z=pos.z} - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - -- Get bonemeal from composter above - local upnode = minetest.get_node(uppos) - if upnode.name == "mcl_composters:composter_ready" then - minetest.swap_node(uppos, {name="mcl_composters:composter"}) - inv:add_item("main", "mcl_dye:white") - end - - --Add compostable itens into composter below - local downnode = minetest.get_node(downpos) - if downnode.name == "mcl_composters:composter" or downnode.name == "mcl_composters:composter_1" - or downnode.name == "mcl_composters:composter_2" or downnode.name == "mcl_composters:composter_3" - or downnode.name == "mcl_composters:composter_4" or downnode.name == "mcl_composters:composter_5" - or downnode.name == "mcl_composters:composter_6" or downnode.name == "mcl_composters:composter_7" then - local itemcomp = inv:get_list("main") - for i, k in ipairs(itemcomp) do - local compchance = minetest.get_item_group(itemcomp[i]:get_name(), "compostability") - if compchance > 0 then - -- TODO: fix bug where take multiple compostable items - itemcomp[i]:take_item() - inv:set_list("main", itemcomp) - local rand = math.random(0,100) - if compchance >= rand then - local level = 0 - if downnode.name == "mcl_composters:composter_1" then - level = 1 - elseif downnode.name == "mcl_composters:composter_2" then - level = 2 - elseif downnode.name == "mcl_composters:composter_3" then - level = 3 - elseif downnode.name == "mcl_composters:composter_4" then - level = 4 - elseif downnode.name == "mcl_composters:composter_5" then - level = 5 - elseif downnode.name == "mcl_composters:composter_6" then - level = 6 - elseif downnode.name == "mcl_composters:composter_7" then - level = 7 - end - mcl_dye.add_bone_meal_particle(vector.offset(downpos, 0, level/8, 0)) - if level < 7 then - level = level + 1 - else - level = "ready" - end - minetest.swap_node(downpos, {name="mcl_composters:composter_" .. level}) - end - end - end - end - end, -}) - minetest.register_abm({ label = "Side-hopper/container item exchange", nodenames = {"mcl_hoppers:hopper_side"}, @@ -534,6 +469,84 @@ minetest.register_abm({ end }) +minetest.register_abm({ + label = "Bonemeal extraction from composter", + nodenames = {"mcl_hoppers:hopper", "mcl_hoppers:hopper_side"}, + neighbors = {"mcl_composters:composter_ready"}, + interval = 1.0, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local uppos = {x=pos.x,y=pos.y+1,z=pos.z} + local downpos = {x=pos.x,y=pos.y-1,z=pos.z} + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + -- Get bonemeal from composter above + local upnode = minetest.get_node(uppos) + if upnode.name == "mcl_composters:composter_ready" then + minetest.swap_node(uppos, {name="mcl_composters:composter"}) + inv:add_item("main", "mcl_dye:white") + end + end, +}) + +minetest.register_abm({ + label = "Add compostable items on composter", + nodenames = {"mcl_hoppers:hopper"}, + neighbors = {"mcl_composters:composter", "mcl_composters:composter_1", "mcl_composters:composter_2", + "mcl_composters:composter_3", "mcl_composters:composter_4", "mcl_composters:composter_5", + "mcl_composters:composter_6", "mcl_composters:composter_7",}, + interval = 1.0, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + local uppos = {x=pos.x,y=pos.y+1,z=pos.z} + local downpos = {x=pos.x,y=pos.y-1,z=pos.z} + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + --Consume compostable items and update composter below + local downnode = minetest.get_node(downpos) + if downnode.name == "mcl_composters:composter" or downnode.name == "mcl_composters:composter_1" + or downnode.name == "mcl_composters:composter_2" or downnode.name == "mcl_composters:composter_3" + or downnode.name == "mcl_composters:composter_4" or downnode.name == "mcl_composters:composter_5" + or downnode.name == "mcl_composters:composter_6" or downnode.name == "mcl_composters:composter_7" then + local itemcomp = inv:get_list("main") + local hslot = mcl_util.get_first_occupied_inventory_slot(minetest.get_inventory({type="node", pos = pos}), "main") + if hslot == nil then return end + local compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") + -- TODO: make it go to next hslot if item isn't compostable + if compchance > 0 then + itemcomp[hslot]:take_item() + inv:set_list("main", itemcomp) + local rand = math.random(0,100) + if compchance >= rand then + local level = 0 + if downnode.name == "mcl_composters:composter_1" then + level = 1 + elseif downnode.name == "mcl_composters:composter_2" then + level = 2 + elseif downnode.name == "mcl_composters:composter_3" then + level = 3 + elseif downnode.name == "mcl_composters:composter_4" then + level = 4 + elseif downnode.name == "mcl_composters:composter_5" then + level = 5 + elseif downnode.name == "mcl_composters:composter_6" then + level = 6 + elseif downnode.name == "mcl_composters:composter_7" then + level = 7 + end + mcl_dye.add_bone_meal_particle(vector.offset(downpos, 0, level/8, 0)) + if level < 7 then + level = level + 1 + else + level = "ready" + end + minetest.swap_node(downpos, {name="mcl_composters:composter_" .. level}) + end + end + end + end, +}) + minetest.register_craft({ output = "mcl_hoppers:hopper", recipe = { From 3072d44b6692ec310e7cfa9552d0f91385a159af Mon Sep 17 00:00:00 2001 From: anarquimico Date: Tue, 8 Nov 2022 19:18:35 -0300 Subject: [PATCH 3/5] Bugs fixed. --- mods/ITEMS/mcl_hoppers/init.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index b9af5a056..e3708629e 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -512,6 +512,22 @@ minetest.register_abm({ local hslot = mcl_util.get_first_occupied_inventory_slot(minetest.get_inventory({type="node", pos = pos}), "main") if hslot == nil then return end local compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") + if compchance == 0 then + hslot = hslot+1 + compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") + if compchance == 0 then + hslot = hslot+1 + compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") + if compchance == 0 then + hslot = hslot+1 + compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") + if compchance == 0 then + hslot = hslot+1 + compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") + end + end + end + end -- TODO: make it go to next hslot if item isn't compostable if compchance > 0 then itemcomp[hslot]:take_item() From cb721f37ce815a679525411b34ece05ab94916e9 Mon Sep 17 00:00:00 2001 From: anarquimico Date: Thu, 10 Nov 2022 21:11:32 -0300 Subject: [PATCH 4/5] Fixed minor bug and removed TODO commentary --- mods/ITEMS/mcl_hoppers/init.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index e3708629e..f1ef3e78e 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -514,21 +514,24 @@ minetest.register_abm({ local compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") if compchance == 0 then hslot = hslot+1 + if hslot == 6 then return end compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") if compchance == 0 then hslot = hslot+1 + if hslot == 6 then return end compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") if compchance == 0 then hslot = hslot+1 + if hslot == 6 then return end compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") if compchance == 0 then hslot = hslot+1 + if hslot == 6 then return end compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") end end end end - -- TODO: make it go to next hslot if item isn't compostable if compchance > 0 then itemcomp[hslot]:take_item() inv:set_list("main", itemcomp) From 3ef8838a114046cc932ad7474c666e2d7185864d Mon Sep 17 00:00:00 2001 From: anarquimico Date: Sat, 12 Nov 2022 06:28:36 -0300 Subject: [PATCH 5/5] Fixed indentation. --- mods/ITEMS/mcl_hoppers/init.lua | 116 ++++++++++++++++---------------- 1 file changed, 58 insertions(+), 58 deletions(-) diff --git a/mods/ITEMS/mcl_hoppers/init.lua b/mods/ITEMS/mcl_hoppers/init.lua index f1ef3e78e..1e53aa1bf 100644 --- a/mods/ITEMS/mcl_hoppers/init.lua +++ b/mods/ITEMS/mcl_hoppers/init.lua @@ -498,68 +498,68 @@ minetest.register_abm({ interval = 1.0, chance = 1, action = function(pos, node, active_object_count, active_object_count_wider) - local uppos = {x=pos.x,y=pos.y+1,z=pos.z} - local downpos = {x=pos.x,y=pos.y-1,z=pos.z} - local meta = minetest.get_meta(pos) + local uppos = {x=pos.x,y=pos.y+1,z=pos.z} + local downpos = {x=pos.x,y=pos.y-1,z=pos.z} + local meta = minetest.get_meta(pos) local inv = meta:get_inventory() - --Consume compostable items and update composter below - local downnode = minetest.get_node(downpos) - if downnode.name == "mcl_composters:composter" or downnode.name == "mcl_composters:composter_1" - or downnode.name == "mcl_composters:composter_2" or downnode.name == "mcl_composters:composter_3" - or downnode.name == "mcl_composters:composter_4" or downnode.name == "mcl_composters:composter_5" - or downnode.name == "mcl_composters:composter_6" or downnode.name == "mcl_composters:composter_7" then - local itemcomp = inv:get_list("main") - local hslot = mcl_util.get_first_occupied_inventory_slot(minetest.get_inventory({type="node", pos = pos}), "main") - if hslot == nil then return end - local compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") - if compchance == 0 then - hslot = hslot+1 - if hslot == 6 then return end - compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") - if compchance == 0 then - hslot = hslot+1 - if hslot == 6 then return end - compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") - if compchance == 0 then - hslot = hslot+1 - if hslot == 6 then return end - compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") + --Consume compostable items and update composter below + local downnode = minetest.get_node(downpos) + if downnode.name == "mcl_composters:composter" or downnode.name == "mcl_composters:composter_1" + or downnode.name == "mcl_composters:composter_2" or downnode.name == "mcl_composters:composter_3" + or downnode.name == "mcl_composters:composter_4" or downnode.name == "mcl_composters:composter_5" + or downnode.name == "mcl_composters:composter_6" or downnode.name == "mcl_composters:composter_7" then + local itemcomp = inv:get_list("main") + local hslot = mcl_util.get_first_occupied_inventory_slot(minetest.get_inventory({type="node", pos = pos}), "main") + if hslot == nil then return end + local compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") + if compchance == 0 then + hslot = hslot+1 + if hslot == 6 then return end + compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") + if compchance == 0 then + hslot = hslot+1 + if hslot == 6 then return end + compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") + if compchance == 0 then + hslot = hslot+1 + if hslot == 6 then return end + compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") if compchance == 0 then hslot = hslot+1 - if hslot == 6 then return end - compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") - end - end - end - end + if hslot == 6 then return end + compchance = minetest.get_item_group(itemcomp[hslot]:get_name(), "compostability") + end + end + end + end if compchance > 0 then - itemcomp[hslot]:take_item() - inv:set_list("main", itemcomp) - local rand = math.random(0,100) - if compchance >= rand then - local level = 0 - if downnode.name == "mcl_composters:composter_1" then - level = 1 - elseif downnode.name == "mcl_composters:composter_2" then - level = 2 - elseif downnode.name == "mcl_composters:composter_3" then - level = 3 - elseif downnode.name == "mcl_composters:composter_4" then - level = 4 - elseif downnode.name == "mcl_composters:composter_5" then - level = 5 - elseif downnode.name == "mcl_composters:composter_6" then - level = 6 - elseif downnode.name == "mcl_composters:composter_7" then - level = 7 - end - mcl_dye.add_bone_meal_particle(vector.offset(downpos, 0, level/8, 0)) - if level < 7 then - level = level + 1 - else - level = "ready" - end - minetest.swap_node(downpos, {name="mcl_composters:composter_" .. level}) + itemcomp[hslot]:take_item() + inv:set_list("main", itemcomp) + local rand = math.random(0,100) + if compchance >= rand then + local level = 0 + if downnode.name == "mcl_composters:composter_1" then + level = 1 + elseif downnode.name == "mcl_composters:composter_2" then + level = 2 + elseif downnode.name == "mcl_composters:composter_3" then + level = 3 + elseif downnode.name == "mcl_composters:composter_4" then + level = 4 + elseif downnode.name == "mcl_composters:composter_5" then + level = 5 + elseif downnode.name == "mcl_composters:composter_6" then + level = 6 + elseif downnode.name == "mcl_composters:composter_7" then + level = 7 + end + mcl_dye.add_bone_meal_particle(vector.offset(downpos, 0, level/8, 0)) + if level < 7 then + level = level + 1 + else + level = "ready" + end + minetest.swap_node(downpos, {name="mcl_composters:composter_" .. level}) end end end