Recipe for renewable lux.
This commit is contained in:
parent
9c1fee366d
commit
65d8a97d83
69
mods/nc_lux/api.lua
Normal file
69
mods/nc_lux/api.lua
Normal file
@ -0,0 +1,69 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local math, minetest, nodecore, pairs, vector
|
||||
= math, minetest, nodecore, pairs, vector
|
||||
local math_ceil, math_pow
|
||||
= math.ceil, math.pow
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
|
||||
local function isfluid(pos)
|
||||
local def = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
return def and def.groups and def.groups.lux_fluid
|
||||
end
|
||||
|
||||
local indirs = {}
|
||||
for _, v in pairs(nodecore.dirs()) do
|
||||
if v.y == 0 then
|
||||
indirs[#indirs + 1] = v
|
||||
end
|
||||
end
|
||||
|
||||
function nodecore.lux_soak_rate(pos)
|
||||
local above = vector.add(pos, {x = 0, y = 1, z = 0})
|
||||
if not isfluid(above) then return false end
|
||||
local qty = 1
|
||||
for _, v in pairs(indirs) do
|
||||
if isfluid(vector.add(pos, v)) then qty = qty + 1 end
|
||||
end
|
||||
|
||||
local dist = nodecore.scan_flood(above, 14, function(p, d)
|
||||
if p.dir and p.dir.y < 0 then return false end
|
||||
local nn = minetest.get_node(p).name
|
||||
if nn == modname .. ":flux_source" then return d end
|
||||
if nn ~= modname .. ":flux_flowing" then return false end
|
||||
end)
|
||||
if not dist then return false end
|
||||
|
||||
return qty * 20 / math_pow(2, dist / 2)
|
||||
end
|
||||
|
||||
local function is_lux_cobble(stack)
|
||||
return (not stack:is_empty()) and minetest.get_item_group(stack:get_name(), "lux_cobble") > 0
|
||||
end
|
||||
|
||||
function nodecore.lux_react_qty(pos, adjust)
|
||||
local minp = vector.subtract(pos, {x = 1, y = 1, z = 1})
|
||||
local maxp = vector.add(pos, {x = 1, y = 1, z = 1})
|
||||
local qty = #minetest.find_nodes_in_area(minp, maxp, {"group:lux_cobble"})
|
||||
if adjust then qty = qty + adjust end
|
||||
for _, p in pairs(minetest.find_nodes_with_meta(minp, maxp)) do
|
||||
if is_lux_cobble(nodecore.stack_get(p)) then
|
||||
qty = qty + 1
|
||||
end
|
||||
end
|
||||
for _, p in pairs(minetest.get_connected_players()) do
|
||||
if vector.distance(pos, vector.add(p:get_pos(), {x = 0, y = 1, z = 0})) < 2 then
|
||||
local inv = p:get_inventory()
|
||||
for i = 1, inv:get_size("main") do
|
||||
if is_lux_cobble(inv:get_stack("main", i)) then
|
||||
qty = qty + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
qty = math_ceil(qty / 2)
|
||||
if qty > 8 then qty = 8 end
|
||||
if qty < 1 then qty = 1 end
|
||||
return qty
|
||||
end
|
@ -5,9 +5,11 @@ local include, nodecore
|
||||
|
||||
nodecore.amcoremod()
|
||||
|
||||
include("api")
|
||||
include("ore")
|
||||
include("fluid")
|
||||
include("react")
|
||||
include("tools")
|
||||
include("cherenkov")
|
||||
include("radiation")
|
||||
include("renew")
|
||||
|
@ -1,43 +1,8 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local ItemStack, math, minetest, nodecore, pairs, vector
|
||||
= ItemStack, math, minetest, nodecore, pairs, vector
|
||||
local math_ceil
|
||||
= math.ceil
|
||||
local minetest, nodecore, pairs, vector
|
||||
= minetest, nodecore, pairs, vector
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local function stackgroup(stack, grp)
|
||||
stack = ItemStack(stack)
|
||||
if stack:is_empty() then return end
|
||||
local name = stack:get_name()
|
||||
local def = minetest.registered_items[name]
|
||||
return def and def.groups and def.groups[grp] and name
|
||||
end
|
||||
|
||||
local function luxqty(pos)
|
||||
local minp = vector.subtract(pos, {x = 1, y = 1, z = 1})
|
||||
local maxp = vector.add(pos, {x = 1, y = 1, z = 1})
|
||||
local qty = #minetest.find_nodes_in_area(minp, maxp, {"group:lux_cobble"})
|
||||
for _, p in pairs(minetest.find_nodes_with_meta(minp, maxp)) do
|
||||
if stackgroup(nodecore.stack_get(p), "lux_cobble") then
|
||||
qty = qty + 1
|
||||
end
|
||||
end
|
||||
for _, p in pairs(minetest.get_connected_players()) do
|
||||
if vector.distance(pos, vector.add(p:get_pos(), {x = 0, y = 1, z = 0})) < 2 then
|
||||
local inv = p:get_inventory()
|
||||
for i = 1, inv:get_size("main") do
|
||||
if stackgroup(inv:get_stack("main", i), "lux_cobble") then
|
||||
qty = qty + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
qty = math_ceil(qty / 2)
|
||||
if qty > 8 then qty = 8 end
|
||||
if qty < 1 then qty = 1 end
|
||||
return qty
|
||||
end
|
||||
|
||||
nodecore.register_limited_abm({
|
||||
label = "Lux Reaction",
|
||||
interval = 1,
|
||||
@ -45,7 +10,7 @@ nodecore.register_limited_abm({
|
||||
limited_max = 100,
|
||||
nodenames = {"group:lux_cobble"},
|
||||
action = function(pos, node)
|
||||
local qty = luxqty(pos)
|
||||
local qty = nodecore.lux_react_qty(pos)
|
||||
local name = node.name:gsub("cobble%d", "cobble" .. qty)
|
||||
if name == node.name then return end
|
||||
minetest.set_node(pos, {name = name})
|
||||
@ -58,9 +23,9 @@ nodecore.register_aism({
|
||||
chance = 2,
|
||||
itemnames = {"group:lux_cobble"},
|
||||
action = function(stack, data)
|
||||
local name = stackgroup(stack, "lux_cobble")
|
||||
if not name then return end
|
||||
local qty = luxqty(data.pos)
|
||||
local name = stack:get_name()
|
||||
if minetest.get_item_group(name, "lux_cobble") <= 0 then return end
|
||||
local qty = nodecore.lux_react_qty(data.pos)
|
||||
name = name:gsub("cobble%d", "cobble" .. qty)
|
||||
if name == stack:get_name() then return end
|
||||
stack:set_name(name)
|
||||
@ -74,13 +39,13 @@ local function playercheck(player)
|
||||
local inv = player:get_inventory()
|
||||
for i = 1, inv:get_size("main") do
|
||||
local stack = inv:get_stack("main", i)
|
||||
if stackgroup(stack, "lux_cobble") then
|
||||
if minetest.get_item_group(stack:get_name(), "lux_cobble") > 0 then
|
||||
stacks[i] = stack
|
||||
found = true
|
||||
end
|
||||
end
|
||||
if not found then return end
|
||||
local qty = luxqty(vector.add(player:get_pos(), {x = 0, y = 1, z = 0}))
|
||||
local qty = nodecore.lux_react_qty(vector.add(player:get_pos(), {x = 0, y = 1, z = 0}))
|
||||
for k, v in pairs(stacks) do
|
||||
local name = v:get_name()
|
||||
local nn = name:gsub("cobble%d", "cobble" .. qty)
|
||||
|
22
mods/nc_lux/renew.lua
Normal file
22
mods/nc_lux/renew.lua
Normal file
@ -0,0 +1,22 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local minetest, nodecore
|
||||
= minetest, nodecore
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
|
||||
nodecore.register_soaking_abm({
|
||||
label = "lux renewal",
|
||||
fieldname = "lavalux",
|
||||
interval = 10,
|
||||
chance = 1,
|
||||
nodenames = {"group:amalgam"},
|
||||
neighbors = {"group:lux_fluid"},
|
||||
soakrate = nodecore.lux_soak_rate,
|
||||
soakcheck = function(data, pos)
|
||||
if data.total < 12500 then return end
|
||||
nodecore.set_loud(pos, {name = modname .. ":cobble"
|
||||
.. nodecore.lux_react_qty(pos, 1)})
|
||||
nodecore.witness(pos, "lux renewal")
|
||||
end
|
||||
})
|
@ -1,8 +1,8 @@
|
||||
-- LUALOCALS < ---------------------------------------------------------
|
||||
local ItemStack, math, minetest, nodecore, pairs, vector
|
||||
= ItemStack, math, minetest, nodecore, pairs, vector
|
||||
local math_ceil, math_exp, math_log, math_pow
|
||||
= math.ceil, math.exp, math.log, math.pow
|
||||
local ItemStack, math, minetest, nodecore, pairs
|
||||
= ItemStack, math, minetest, nodecore, pairs
|
||||
local math_ceil, math_exp, math_log
|
||||
= math.ceil, math.exp, math.log
|
||||
-- LUALOCALS > ---------------------------------------------------------
|
||||
|
||||
local modname = minetest.get_current_modname()
|
||||
@ -39,17 +39,6 @@ for _, shape in pairs({'mallet', 'spade', 'hatchet', 'pick', 'mattock'}) do
|
||||
end
|
||||
end
|
||||
|
||||
local function isfluid(pos)
|
||||
local def = minetest.registered_nodes[minetest.get_node(pos).name]
|
||||
return def and def.groups and def.groups.lux_fluid
|
||||
end
|
||||
local indirs = {}
|
||||
for _, v in pairs(nodecore.dirs()) do
|
||||
if v.y == 0 then
|
||||
indirs[#indirs + 1] = v
|
||||
end
|
||||
end
|
||||
|
||||
local alltools = {}
|
||||
for k in pairs(convert) do alltools[#alltools + 1] = k end
|
||||
for k in pairs(charge) do
|
||||
@ -70,23 +59,7 @@ nodecore.register_soaking_aism({
|
||||
if (not charge[name]) and (not convert[name]) then return false end
|
||||
|
||||
local pos = aismdata.pos or aismdata.player and aismdata.player:get_pos()
|
||||
|
||||
local above = vector.add(pos, {x = 0, y = 1, z = 0})
|
||||
if not isfluid(above) then return false end
|
||||
local qty = 1
|
||||
for _, v in pairs(indirs) do
|
||||
if isfluid(vector.add(pos, v)) then qty = qty + 1 end
|
||||
end
|
||||
|
||||
local dist = nodecore.scan_flood(above, 14, function(p, d)
|
||||
if p.dir and p.dir.y < 0 then return false end
|
||||
local nn = minetest.get_node(p).name
|
||||
if nn == modname .. ":flux_source" then return d end
|
||||
if nn ~= modname .. ":flux_flowing" then return false end
|
||||
end)
|
||||
if not dist then return false end
|
||||
|
||||
return qty * 20 / math_pow(2, dist / 2)
|
||||
return nodecore.lux_soak_rate(pos)
|
||||
end,
|
||||
soakcheck = function(data, stack)
|
||||
local name = stack:get_name()
|
||||
|
Loading…
x
Reference in New Issue
Block a user