2019-10-29 07:12:01 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
Active ItemStack Modifier overhaul.
AISM's now tick against stacks, including in piles, shelves,
and player inventories, (hopefully) efficiently compared to
the old way with separate ABMs. Item entity support is also
possible, but not necessary yet.
This started out as a bugfix for being able to put a torch inside a
shelf, which didn't make much sense gameplay-wise. It ended up
going quite a bit further.
- Aggregate now gets wet in stack form. Swimming with dry
concrete now has consequences.
- Lux reactions, radiation, and infusion should now behave more
consistently.
- Sponges can now wet or dry in stack form, including inside
containers.
- Torch ignition, quenching, and extinguishing is now more
consistent regardless of context, and torches are now more
dangerous, and can ignite things in more contexts.
2019-10-29 20:03:00 -04:00
|
|
|
local math, minetest, nodecore, pairs, string
|
|
|
|
= math, minetest, nodecore, pairs, string
|
|
|
|
local math_random, string_format
|
|
|
|
= math.random, string.format
|
2019-10-29 07:12:01 -04:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
-- Active ItemStack Modifiers
|
|
|
|
|
|
|
|
-- Definition:
|
|
|
|
--- itemnames: {"mod:itemname", "group:name"}
|
|
|
|
--- interval: integer,
|
|
|
|
--- chance: integer,
|
|
|
|
--- func: function(stack, data) end
|
|
|
|
-- Data:
|
|
|
|
--- {pos, node}
|
|
|
|
--- {player, inv, list, slot}
|
|
|
|
|
|
|
|
nodecore.register_aism,
|
|
|
|
nodecore.registered_aisms
|
|
|
|
= nodecore.mkreg()
|
|
|
|
|
|
|
|
local aismidx = {}
|
Active ItemStack Modifier overhaul.
AISM's now tick against stacks, including in piles, shelves,
and player inventories, (hopefully) efficiently compared to
the old way with separate ABMs. Item entity support is also
possible, but not necessary yet.
This started out as a bugfix for being able to put a torch inside a
shelf, which didn't make much sense gameplay-wise. It ended up
going quite a bit further.
- Aggregate now gets wet in stack form. Swimming with dry
concrete now has consequences.
- Lux reactions, radiation, and infusion should now behave more
consistently.
- Sponges can now wet or dry in stack form, including inside
containers.
- Torch ignition, quenching, and extinguishing is now more
consistent regardless of context, and torches are now more
dangerous, and can ignite things in more contexts.
2019-10-29 20:03:00 -04:00
|
|
|
local function defadd(key, def)
|
|
|
|
aismidx[key] = aismidx[key] or {}
|
|
|
|
aismidx[key][def] = true
|
|
|
|
end
|
2019-10-29 07:12:01 -04:00
|
|
|
minetest.after(0, function()
|
|
|
|
for _, def in pairs(nodecore.registered_aisms) do
|
|
|
|
for _, name in pairs(def.itemnames) do
|
|
|
|
if name:sub(1, 6) == "group:" then
|
|
|
|
for k, v in pairs(minetest.registered_items) do
|
|
|
|
if v and v.groups and v.groups[name:sub(7)] then
|
Active ItemStack Modifier overhaul.
AISM's now tick against stacks, including in piles, shelves,
and player inventories, (hopefully) efficiently compared to
the old way with separate ABMs. Item entity support is also
possible, but not necessary yet.
This started out as a bugfix for being able to put a torch inside a
shelf, which didn't make much sense gameplay-wise. It ended up
going quite a bit further.
- Aggregate now gets wet in stack form. Swimming with dry
concrete now has consequences.
- Lux reactions, radiation, and infusion should now behave more
consistently.
- Sponges can now wet or dry in stack form, including inside
containers.
- Torch ignition, quenching, and extinguishing is now more
consistent regardless of context, and torches are now more
dangerous, and can ignite things in more contexts.
2019-10-29 20:03:00 -04:00
|
|
|
defadd(k, def)
|
2019-10-29 07:12:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
else
|
Active ItemStack Modifier overhaul.
AISM's now tick against stacks, including in piles, shelves,
and player inventories, (hopefully) efficiently compared to
the old way with separate ABMs. Item entity support is also
possible, but not necessary yet.
This started out as a bugfix for being able to put a torch inside a
shelf, which didn't make much sense gameplay-wise. It ended up
going quite a bit further.
- Aggregate now gets wet in stack form. Swimming with dry
concrete now has consequences.
- Lux reactions, radiation, and infusion should now behave more
consistently.
- Sponges can now wet or dry in stack form, including inside
containers.
- Torch ignition, quenching, and extinguishing is now more
consistent regardless of context, and torches are now more
dangerous, and can ignite things in more contexts.
2019-10-29 20:03:00 -04:00
|
|
|
defadd(name, def)
|
2019-10-29 07:12:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
Active ItemStack Modifier overhaul.
AISM's now tick against stacks, including in piles, shelves,
and player inventories, (hopefully) efficiently compared to
the old way with separate ABMs. Item entity support is also
possible, but not necessary yet.
This started out as a bugfix for being able to put a torch inside a
shelf, which didn't make much sense gameplay-wise. It ended up
going quite a bit further.
- Aggregate now gets wet in stack form. Swimming with dry
concrete now has consequences.
- Lux reactions, radiation, and infusion should now behave more
consistently.
- Sponges can now wet or dry in stack form, including inside
containers.
- Torch ignition, quenching, and extinguishing is now more
consistent regardless of context, and torches are now more
dangerous, and can ignite things in more contexts.
2019-10-29 20:03:00 -04:00
|
|
|
local keys = 0
|
|
|
|
local defs = 0
|
|
|
|
local peak = 0
|
|
|
|
for _, v in pairs(aismidx) do
|
|
|
|
keys = keys + 1
|
|
|
|
local n = 0
|
|
|
|
for _ in pairs(v) do n = n + 1 end
|
|
|
|
defs = defs + n
|
|
|
|
if n > peak then peak = n end
|
|
|
|
end
|
|
|
|
minetest.log(string_format("register_aism: %d keys, %d defs, %d peak", keys, defs, peak))
|
2019-10-29 07:12:01 -04:00
|
|
|
end)
|
|
|
|
|
|
|
|
local function checkrun(def, stack, data)
|
|
|
|
if def.chance and def.chance > 1 and math_random(1, def.chance) ~= 1 then return end
|
|
|
|
if def.interval and def.interval > 1 and (minetest.get_gametime() % def.interval) ~= 0 then return end
|
Active ItemStack Modifier overhaul.
AISM's now tick against stacks, including in piles, shelves,
and player inventories, (hopefully) efficiently compared to
the old way with separate ABMs. Item entity support is also
possible, but not necessary yet.
This started out as a bugfix for being able to put a torch inside a
shelf, which didn't make much sense gameplay-wise. It ended up
going quite a bit further.
- Aggregate now gets wet in stack form. Swimming with dry
concrete now has consequences.
- Lux reactions, radiation, and infusion should now behave more
consistently.
- Sponges can now wet or dry in stack form, including inside
containers.
- Torch ignition, quenching, and extinguishing is now more
consistent regardless of context, and torches are now more
dangerous, and can ignite things in more contexts.
2019-10-29 20:03:00 -04:00
|
|
|
stack = def.action(stack, data)
|
|
|
|
if stack then
|
|
|
|
if data.node then
|
|
|
|
nodecore.stack_set(data.pos, stack)
|
|
|
|
elseif data.inv and data.list and data.slot then
|
|
|
|
data.inv:set_stack(data.list, data.slot, stack)
|
|
|
|
end
|
|
|
|
end
|
2019-10-29 07:12:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
local function checkstack(stack, data)
|
|
|
|
if (not stack) or stack:is_empty() then return end
|
|
|
|
local name = stack:get_name()
|
|
|
|
local defs = aismidx[name]
|
|
|
|
if not defs then return end
|
Active ItemStack Modifier overhaul.
AISM's now tick against stacks, including in piles, shelves,
and player inventories, (hopefully) efficiently compared to
the old way with separate ABMs. Item entity support is also
possible, but not necessary yet.
This started out as a bugfix for being able to put a torch inside a
shelf, which didn't make much sense gameplay-wise. It ended up
going quite a bit further.
- Aggregate now gets wet in stack form. Swimming with dry
concrete now has consequences.
- Lux reactions, radiation, and infusion should now behave more
consistently.
- Sponges can now wet or dry in stack form, including inside
containers.
- Torch ignition, quenching, and extinguishing is now more
consistent regardless of context, and torches are now more
dangerous, and can ignite things in more contexts.
2019-10-29 20:03:00 -04:00
|
|
|
for def in pairs(defs) do
|
2019-10-29 07:12:01 -04:00
|
|
|
checkrun(def, stack, data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
nodecore.register_limited_abm({
|
|
|
|
label = "AISM Scheduler",
|
|
|
|
nodenames = {"group:visinv"},
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
action = function(pos, node)
|
|
|
|
return checkstack(nodecore.stack_get(pos), {
|
|
|
|
pos = pos,
|
|
|
|
node = node
|
|
|
|
})
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
local function invtick()
|
|
|
|
minetest.after(1, invtick)
|
|
|
|
for _, player in pairs(minetest.get_connected_players()) do
|
Active ItemStack Modifier overhaul.
AISM's now tick against stacks, including in piles, shelves,
and player inventories, (hopefully) efficiently compared to
the old way with separate ABMs. Item entity support is also
possible, but not necessary yet.
This started out as a bugfix for being able to put a torch inside a
shelf, which didn't make much sense gameplay-wise. It ended up
going quite a bit further.
- Aggregate now gets wet in stack form. Swimming with dry
concrete now has consequences.
- Lux reactions, radiation, and infusion should now behave more
consistently.
- Sponges can now wet or dry in stack form, including inside
containers.
- Torch ignition, quenching, and extinguishing is now more
consistent regardless of context, and torches are now more
dangerous, and can ignite things in more contexts.
2019-10-29 20:03:00 -04:00
|
|
|
local pos = player:get_pos()
|
|
|
|
pos.y = pos.y + player:get_properties().eye_height
|
2019-10-29 07:12:01 -04:00
|
|
|
local inv = player:get_inventory()
|
|
|
|
for lname, list in pairs(inv:get_lists()) do
|
|
|
|
for slot, stack in pairs(list) do
|
|
|
|
checkstack(stack, {
|
Active ItemStack Modifier overhaul.
AISM's now tick against stacks, including in piles, shelves,
and player inventories, (hopefully) efficiently compared to
the old way with separate ABMs. Item entity support is also
possible, but not necessary yet.
This started out as a bugfix for being able to put a torch inside a
shelf, which didn't make much sense gameplay-wise. It ended up
going quite a bit further.
- Aggregate now gets wet in stack form. Swimming with dry
concrete now has consequences.
- Lux reactions, radiation, and infusion should now behave more
consistently.
- Sponges can now wet or dry in stack form, including inside
containers.
- Torch ignition, quenching, and extinguishing is now more
consistent regardless of context, and torches are now more
dangerous, and can ignite things in more contexts.
2019-10-29 20:03:00 -04:00
|
|
|
pos = pos,
|
2019-10-29 07:12:01 -04:00
|
|
|
player = player,
|
|
|
|
inv = inv,
|
|
|
|
list = lname,
|
|
|
|
slot = slot
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
invtick()
|