Refactor hopper -> composter ABMs
parent
47eda5b69e
commit
7deec7ae03
|
@ -603,17 +603,53 @@ if minetest.get_modpath("mcl_composters") then
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
local uppos = vector.offset(pos, 0, 1, 0)
|
local uppos = vector.offset(pos, 0, 1, 0)
|
||||||
--local downpos = vector.offset(pos, 0, -1, 0)
|
--local downpos = vector.offset(pos, 0, -1, 0)
|
||||||
local meta = minetest.get_meta(pos)
|
|
||||||
local inv = meta:get_inventory()
|
|
||||||
-- Get bonemeal from composter above
|
-- Get bonemeal from composter above
|
||||||
local upnode = minetest.get_node(uppos)
|
local upnode = minetest.get_node(uppos)
|
||||||
if upnode.name == "mcl_composters:composter_ready" then
|
if upnode.name == "mcl_composters:composter_ready" then
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
|
||||||
minetest.swap_node(uppos, { name = "mcl_composters:composter" })
|
minetest.swap_node(uppos, { name = "mcl_composters:composter" })
|
||||||
|
|
||||||
inv:add_item("main", "mcl_dye:white")
|
inv:add_item("main", "mcl_dye:white")
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
---@param node node
|
||||||
|
---@return integer?
|
||||||
|
---@nodiscard
|
||||||
|
local function composter_level(node)
|
||||||
|
local nn = node.name
|
||||||
|
if nn == "mcl_composters:composter" then
|
||||||
|
return 0
|
||||||
|
elseif nn == "mcl_composters:composter_1" then
|
||||||
|
return 1
|
||||||
|
elseif nn == "mcl_composters:composter_2" then
|
||||||
|
return 2
|
||||||
|
elseif nn == "mcl_composters:composter_3" then
|
||||||
|
return 3
|
||||||
|
elseif nn == "mcl_composters:composter_4" then
|
||||||
|
return 4
|
||||||
|
elseif nn == "mcl_composters:composter_5" then
|
||||||
|
return 5
|
||||||
|
elseif nn == "mcl_composters:composter_6" then
|
||||||
|
return 6
|
||||||
|
elseif nn == "mcl_composters:composter_7" then
|
||||||
|
return 7
|
||||||
|
else
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = 1, 7 do
|
||||||
|
assert(composter_level({ name = "mcl_composters:composter_" .. i }) == i)
|
||||||
|
end
|
||||||
|
|
||||||
|
assert(composter_level({ name = "mcl_composters:composter" }) == 0)
|
||||||
|
assert(composter_level({ name = "mcl_composters:some_other_node" }) == nil)
|
||||||
|
|
||||||
minetest.register_abm({
|
minetest.register_abm({
|
||||||
label = "Add compostable items on composter",
|
label = "Add compostable items on composter",
|
||||||
nodenames = { "mcl_hoppers:hopper" },
|
nodenames = { "mcl_hoppers:hopper" },
|
||||||
|
@ -632,59 +668,26 @@ if minetest.get_modpath("mcl_composters") then
|
||||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||||
--local uppos = vector.offset(pos, 0, 1, 0)
|
--local uppos = vector.offset(pos, 0, 1, 0)
|
||||||
local downpos = vector.offset(pos, 0, -1, 0)
|
local downpos = vector.offset(pos, 0, -1, 0)
|
||||||
|
|
||||||
|
local downnode = minetest.get_node(downpos)
|
||||||
|
|
||||||
|
---@type integer|string|nil
|
||||||
|
local level = composter_level(downnode)
|
||||||
|
|
||||||
|
--Consume compostable items and update composter below
|
||||||
|
if level then
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
--Consume compostable items and update composter below
|
|
||||||
local downnode = minetest.get_node(downpos)
|
for i = 1, 5 do
|
||||||
if downnode.name == "mcl_composters:composter" or downnode.name == "mcl_composters:composter_1"
|
local stack = inv:get_stack("main", i)
|
||||||
or downnode.name == "mcl_composters:composter_2" or downnode.name == "mcl_composters:composter_3"
|
local compchance = minetest.get_item_group(stack:get_name(), "compostability")
|
||||||
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 compchance > 0 then
|
if compchance > 0 then
|
||||||
itemcomp[hslot]:take_item()
|
stack:take_item()
|
||||||
inv:set_list("main", itemcomp)
|
inv:set_stack("main", i, stack)
|
||||||
local rand = math.random(0, 100)
|
|
||||||
if compchance >= rand then
|
if compchance >= math.random(0, 100) 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))
|
mcl_dye.add_bone_meal_particle(vector.offset(downpos, 0, level / 8, 0))
|
||||||
if level < 7 then
|
if level < 7 then
|
||||||
level = level + 1
|
level = level + 1
|
||||||
|
@ -693,6 +696,8 @@ if minetest.get_modpath("mcl_composters") then
|
||||||
end
|
end
|
||||||
minetest.swap_node(downpos, { name = "mcl_composters:composter_" .. level })
|
minetest.swap_node(downpos, { name = "mcl_composters:composter_" .. level })
|
||||||
end
|
end
|
||||||
|
break
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
name = mcl_hoppers
|
name = mcl_hoppers
|
||||||
description = It's just a clone of Minecraft hoppers, functions nearly identical to them minus mesecons making them stop and the way they're placed.
|
description = It's just a clone of Minecraft hoppers, functions nearly identical to them minus mesecons making them stop and the way they're placed.
|
||||||
depends = mcl_core, mcl_formspec, mcl_sounds, mcl_util
|
depends = mcl_core, mcl_formspec, mcl_sounds, mcl_util, mcl_dye
|
||||||
optional_depends = doc, screwdriver
|
optional_depends = doc, screwdriver
|
||||||
|
|
Loading…
Reference in New Issue