2019-09-05 22:48:30 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
|
|
|
local error, math, minetest, nodecore, type
|
|
|
|
= error, math, minetest, nodecore, type
|
|
|
|
local math_floor, math_sqrt
|
|
|
|
= math.floor, math.sqrt
|
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
2019-12-27 10:09:00 -05:00
|
|
|
local function metaclear(meta, def)
|
|
|
|
local tbl = meta:to_table()
|
|
|
|
if not (tbl.fields[def.qtyfield] or tbl.fields[def.timefield]) then return end
|
|
|
|
tbl.fields[def.qtyfield] = nil
|
|
|
|
tbl.fields[def.timefield] = nil
|
|
|
|
meta:from_table(tbl)
|
|
|
|
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 function soaking_core(def, reg, getmeta)
|
2020-01-11 08:42:23 -05:00
|
|
|
def.qtyfield = def.qtyfield or def.fieldname and (def.fieldname .. "qty")
|
|
|
|
if not def.qtyfield then error("soaking missing qtyfield or fieldname") end
|
|
|
|
def.timefield = def.timefield or def.fieldname and (def.fieldname .. "time")
|
|
|
|
if not def.qtyfield then error("soaking missing qtyfield or fieldname") end
|
2019-09-05 22:48:30 -04:00
|
|
|
|
|
|
|
def.soakinterval = def.soakinterval or ((def.interval or 1) * (def.chance or 1))
|
|
|
|
|
2020-01-11 08:42:23 -05:00
|
|
|
if not def.soakrate then error("soaking missing soakrate callback") end
|
|
|
|
if not def.soakcheck then error("soaking missing soakcheck callback") end
|
2019-09-05 22:48:30 -04:00
|
|
|
|
|
|
|
def.soakvary = def.soakvary or 0.25
|
|
|
|
if not def.soakrand then
|
|
|
|
if def.soakvary then
|
|
|
|
def.soakrand = function(rate, ticks)
|
|
|
|
return rate * (1 + def.soakvary * nodecore.boxmuller()
|
|
|
|
/ math_sqrt(ticks)) * ticks
|
|
|
|
end
|
|
|
|
else
|
|
|
|
def.soakrand = function(rate, ticks) return rate * ticks end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-06 07:01:12 -05:00
|
|
|
local rateadj = nodecore.rate_adjustment("speed", "soaking", def.label)
|
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
|
|
|
def.action = function(...)
|
2019-11-10 08:10:34 -05:00
|
|
|
local now = nodecore.gametime
|
2019-09-05 22:48:30 -04:00
|
|
|
|
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 meta = getmeta(...)
|
2019-09-05 22:48:30 -04:00
|
|
|
local total = meta:get_float(def.qtyfield) or 0
|
|
|
|
local start = meta:get_float(def.timefield)
|
|
|
|
start = start and start ~= 0 and start or now
|
|
|
|
|
|
|
|
local rate = 0
|
|
|
|
local delta = 0
|
|
|
|
if start <= now 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
|
|
|
rate = def.soakrate(...)
|
2019-09-05 22:48:30 -04:00
|
|
|
if rate == false then
|
2019-12-27 10:09:00 -05:00
|
|
|
metaclear(meta, def)
|
2019-12-25 16:05:47 -05:00
|
|
|
return ...
|
2019-09-05 22:48:30 -04:00
|
|
|
end
|
|
|
|
rate = rate or 0
|
|
|
|
local ticks = 1 + math_floor((now - start) / def.soakinterval)
|
|
|
|
delta = def.soakrand(rate, ticks)
|
2019-12-06 07:01:12 -05:00
|
|
|
total = total + delta * rateadj
|
2019-09-05 22:48:30 -04:00
|
|
|
start = start + ticks * def.soakinterval
|
|
|
|
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 function helper(set, ...)
|
|
|
|
if set == false then
|
2019-12-27 10:09:00 -05:00
|
|
|
metaclear(meta, def)
|
2019-12-25 16:05:47 -05:00
|
|
|
return ...
|
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
|
|
|
end
|
|
|
|
meta:set_float(def.qtyfield, set and type(set) == "number" and set or total)
|
|
|
|
meta:set_float(def.timefield, start)
|
|
|
|
return ...
|
2019-09-05 22:48:30 -04:00
|
|
|
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
|
|
|
return helper(def.soakcheck({
|
|
|
|
rate = rate,
|
|
|
|
delta = delta,
|
|
|
|
total = total
|
|
|
|
}, ...))
|
2019-09-05 22:48:30 -04:00
|
|
|
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
|
|
|
return reg(def)
|
|
|
|
end
|
|
|
|
|
|
|
|
function nodecore.register_soaking_abm(def)
|
|
|
|
return soaking_core(def,
|
|
|
|
nodecore.register_limited_abm,
|
|
|
|
function(pos) return minetest.get_meta(pos) end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
function nodecore.register_soaking_aism(def)
|
|
|
|
return soaking_core(def,
|
|
|
|
nodecore.register_aism,
|
|
|
|
function(stack) return stack:get_meta() end
|
|
|
|
)
|
2019-09-05 22:48:30 -04:00
|
|
|
end
|