2018-11-03 11:26:15 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2020-01-16 21:43:07 -05:00
|
|
|
local math, minetest, nodecore, pairs
|
|
|
|
= math, minetest, nodecore, pairs
|
2020-01-15 22:38:02 -05:00
|
|
|
local math_random
|
|
|
|
= math.random
|
2018-11-03 11:26:15 -04:00
|
|
|
-- LUALOCALS > ---------------------------------------------------------
|
|
|
|
|
|
|
|
local modname = minetest.get_current_modname()
|
|
|
|
|
2019-03-23 16:56:02 -04:00
|
|
|
local ldname = "nc_terrain:dirt_loose"
|
|
|
|
local epname = modname .. ":eggcorn_planted"
|
|
|
|
|
2018-11-03 11:26:15 -04:00
|
|
|
minetest.register_node(modname .. ":eggcorn", {
|
2019-03-04 00:52:21 -05:00
|
|
|
description = "Eggcorn",
|
2018-11-03 11:26:15 -04:00
|
|
|
drawtype = "plantlike",
|
|
|
|
paramtype = "light",
|
|
|
|
visual_scale = 0.5,
|
2019-03-23 20:05:56 -04:00
|
|
|
wield_scale = {x = 0.75, y = 0.75, z = 1.5},
|
2018-11-03 11:26:15 -04:00
|
|
|
collision_box = nodecore.fixedbox(-3/16, -0.5, -3/16, 3/16, 0, 3/16),
|
|
|
|
selection_box = nodecore.fixedbox(-3/16, -0.5, -3/16, 3/16, 0, 3/16),
|
2019-02-03 13:20:19 -05:00
|
|
|
inventory_image = "[combine:24x24:4,4=" .. modname .. "_eggcorn.png",
|
2019-12-01 11:08:12 -05:00
|
|
|
tiles = {modname .. "_eggcorn.png"},
|
2018-11-03 11:26:15 -04:00
|
|
|
groups = {
|
2019-01-24 22:08:05 -05:00
|
|
|
snappy = 1,
|
2019-01-06 14:51:09 -05:00
|
|
|
flammable = 3,
|
2019-03-23 13:01:31 -04:00
|
|
|
attached_node = 1,
|
2019-03-13 23:51:59 -04:00
|
|
|
},
|
2019-03-23 13:01:31 -04:00
|
|
|
node_placement_prediction = "",
|
|
|
|
place_as_item = true,
|
2019-03-25 00:15:05 -04:00
|
|
|
sounds = nodecore.sounds("nc_tree_corny"),
|
2019-08-31 09:26:53 -04:00
|
|
|
stack_rightclick = function(pos, _, whom, stack)
|
2019-03-23 16:56:02 -04:00
|
|
|
if nodecore.stack_get(pos):get_count() ~= 1 then return end
|
2019-10-06 00:08:59 -04:00
|
|
|
local def = minetest.registered_items[stack:get_name()]
|
|
|
|
if (not def) or (not def.groups) or (not def.groups.dirt_loose) then return end
|
2019-03-23 16:56:02 -04:00
|
|
|
|
2020-01-16 22:02:59 -05:00
|
|
|
nodecore.set_loud(pos, {name = epname})
|
2019-03-23 16:56:02 -04:00
|
|
|
|
|
|
|
if nodecore.player_stat_add then
|
|
|
|
nodecore.player_stat_add(1, whom, "craft", "eggcorn planting")
|
|
|
|
end
|
|
|
|
minetest.log((whom and whom:get_player_name() or "unknown")
|
|
|
|
.. " planted an eggcorn at " .. minetest.pos_to_string(pos))
|
2019-04-06 21:02:58 -04:00
|
|
|
|
2019-03-23 16:56:02 -04:00
|
|
|
stack:set_count(stack:get_count() - 1)
|
|
|
|
return stack
|
|
|
|
end
|
2018-11-03 11:26:15 -04:00
|
|
|
})
|
|
|
|
|
2019-03-23 13:01:31 -04:00
|
|
|
nodecore.register_limited_abm({
|
|
|
|
interval = 1,
|
|
|
|
chance = 1,
|
|
|
|
nodenames = {modname .. ":eggcorn"},
|
|
|
|
action = function(pos)
|
|
|
|
minetest.remove_node(pos)
|
|
|
|
return nodecore.place_stack(pos, modname .. ":eggcorn")
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2019-08-31 09:26:53 -04:00
|
|
|
nodecore.register_leaf_drops(function(_, node, list)
|
2018-11-03 11:26:15 -04:00
|
|
|
list[#list + 1] = {
|
2019-01-29 20:41:29 -05:00
|
|
|
name = "air",
|
|
|
|
item = modname .. ":eggcorn",
|
|
|
|
prob = 0.05 * (node.param2 + 1)}
|
2018-11-03 11:26:15 -04:00
|
|
|
end)
|
2018-11-03 12:55:26 -04:00
|
|
|
|
2019-10-12 17:09:42 -04:00
|
|
|
local epdef = nodecore.underride({
|
|
|
|
drop = ldname,
|
|
|
|
no_self_repack = true
|
|
|
|
}, minetest.registered_items[ldname] or {})
|
2019-10-06 09:26:18 -04:00
|
|
|
epdef.groups.soil = nil
|
|
|
|
minetest.register_node(epname, epdef)
|
2018-11-03 12:55:26 -04:00
|
|
|
|
2020-01-16 21:43:07 -05:00
|
|
|
local sproutcost = 2000
|
2019-09-05 22:48:30 -04:00
|
|
|
nodecore.register_soaking_abm({
|
2018-11-03 12:55:26 -04:00
|
|
|
label = "EggCorn Growing",
|
2020-01-11 08:42:23 -05:00
|
|
|
fieldname = "eggcorn",
|
2018-11-03 12:55:26 -04:00
|
|
|
nodenames = {epname},
|
|
|
|
interval = 10,
|
2019-02-01 18:34:03 -05:00
|
|
|
chance = 1,
|
2019-10-01 18:23:12 -04:00
|
|
|
limited_max = 100,
|
|
|
|
limited_alert = 1000,
|
2019-10-19 11:00:18 -04:00
|
|
|
soakrate = nodecore.tree_growth_rate,
|
2019-09-05 22:48:30 -04:00
|
|
|
soakcheck = function(data, pos)
|
2020-01-16 21:43:07 -05:00
|
|
|
if data.total >= sproutcost then
|
2020-01-16 22:02:59 -05:00
|
|
|
nodecore.node_sound(pos, "dig")
|
|
|
|
nodecore.set_loud(pos, {name = modname .. ":root"})
|
2020-01-17 23:41:41 -05:00
|
|
|
local apos = {x = pos.x, y = pos.y + 1, z = pos.z}
|
2020-01-17 23:57:16 -05:00
|
|
|
nodecore.witness(apos, "grow tree")
|
2020-01-17 23:41:41 -05:00
|
|
|
nodecore.set_loud(apos,
|
2020-01-15 22:38:02 -05:00
|
|
|
{name = modname .. ":tree_bud", param2 = 1})
|
2020-01-17 23:41:41 -05:00
|
|
|
local sub = minetest.get_meta(apos)
|
2020-01-16 21:43:07 -05:00
|
|
|
sub:set_float("treegrowqty", data.total - sproutcost)
|
|
|
|
sub:set_float("treegrowtime", nodecore.gametime)
|
2020-01-15 22:38:02 -05:00
|
|
|
return
|
|
|
|
end
|
2019-04-06 21:02:58 -04:00
|
|
|
local zero = {x = 0, y = 0, z = 0}
|
|
|
|
nodecore.digparticles(minetest.registered_items[modname .. ":leaves"],
|
|
|
|
{
|
2019-09-05 22:48:30 -04:00
|
|
|
amount = data.rate,
|
2019-04-06 21:02:58 -04:00
|
|
|
time = 10,
|
|
|
|
minpos = {
|
|
|
|
x = pos.x - 0.3,
|
|
|
|
y = pos.y + 33/64,
|
|
|
|
z = pos.z - 0.3
|
|
|
|
},
|
|
|
|
maxpos = {
|
|
|
|
x = pos.x + 0.3,
|
2019-08-27 19:14:51 -04:00
|
|
|
y = pos.y + 33/64,
|
2019-04-06 21:02:58 -04:00
|
|
|
z= pos.z + 0.3
|
|
|
|
},
|
|
|
|
minvel = zero,
|
|
|
|
maxvel = zero,
|
|
|
|
minexptime = 0.1,
|
|
|
|
maxexptime = 0.5,
|
|
|
|
minsize = 1,
|
|
|
|
maxsize = 3,
|
|
|
|
})
|
2018-11-03 12:55:26 -04:00
|
|
|
end
|
|
|
|
})
|
2020-01-15 22:38:02 -05:00
|
|
|
|
|
|
|
local function leafbud(pos, dx, dy, dz, param2)
|
2020-01-15 23:01:11 -05:00
|
|
|
if param2 <= 1 then
|
|
|
|
if 240 < math_random(0, 255) then return end
|
|
|
|
local npos = {x = pos.x + dx, y = pos.y + dy, z = pos.z + dz}
|
|
|
|
if nodecore.buildable_to(npos) then
|
2020-01-16 22:02:59 -05:00
|
|
|
return nodecore.set_loud(npos, nodecore.calc_leaves(npos))
|
2020-01-15 23:01:11 -05:00
|
|
|
end
|
|
|
|
end
|
2020-01-15 22:38:02 -05:00
|
|
|
local npos = {x = pos.x + dx, y = pos.y + dy, z = pos.z + dz}
|
|
|
|
if nodecore.buildable_to(npos) then
|
2020-01-16 22:02:59 -05:00
|
|
|
return nodecore.set_loud(npos, {name = modname .. ":leaves_bud", param2 = param2})
|
2020-01-15 22:38:02 -05:00
|
|
|
end
|
2020-01-17 23:41:41 -05:00
|
|
|
local node = minetest.get_node(npos)
|
|
|
|
if minetest.get_item_group(node.name, "canopy") ~= 0 and param2 >= node.param2 then
|
|
|
|
return nodecore.set_loud(npos, {name = modname .. ":leaves_bud", param2 = param2})
|
|
|
|
end
|
2020-01-15 22:38:02 -05:00
|
|
|
end
|
|
|
|
|
2020-01-15 23:10:18 -05:00
|
|
|
local trunkcost = 500
|
2020-01-15 22:38:02 -05:00
|
|
|
nodecore.register_soaking_abm({
|
|
|
|
label = "Tree Trunk Growth",
|
|
|
|
fieldname = "treegrow",
|
|
|
|
nodenames = {modname .. ":tree_bud"},
|
|
|
|
interval = 10,
|
2020-01-15 23:36:05 -05:00
|
|
|
chance = 1,
|
2020-01-15 22:38:02 -05:00
|
|
|
limited_max = 100,
|
|
|
|
limited_alert = 1000,
|
2020-01-17 13:38:59 -05:00
|
|
|
soakrate = nodecore.tree_trunk_growth_rate,
|
2020-01-15 22:38:02 -05:00
|
|
|
soakcheck = function(data, pos, node)
|
2020-01-15 23:10:18 -05:00
|
|
|
if data.total < trunkcost then return end
|
2020-01-15 22:38:02 -05:00
|
|
|
|
|
|
|
local tp = nodecore.tree_params[node.param2]
|
|
|
|
if not tp then return minetest.remove_node(pos) end
|
|
|
|
|
|
|
|
minetest.set_node(pos, {name = modname .. ":tree"})
|
|
|
|
|
2020-01-17 13:38:59 -05:00
|
|
|
local apos = {x = pos.x, y = pos.y + 1, z = pos.z}
|
2020-01-17 23:41:41 -05:00
|
|
|
if not nodecore.buildable_to(apos)
|
|
|
|
and minetest.get_item_group(minetest.get_node(apos).name, "canopy") == 0
|
|
|
|
then return end
|
2020-01-17 13:38:59 -05:00
|
|
|
|
2020-01-15 22:38:02 -05:00
|
|
|
local param2 = node.param2 + 1
|
|
|
|
tp = nodecore.tree_params[param2]
|
|
|
|
if not tp then return minetest.remove_node(pos) end
|
|
|
|
while tp.prob and (tp.prob < math_random(0, 255)) do
|
|
|
|
param2 = param2 + 1
|
|
|
|
tp = nodecore.tree_params[param2]
|
|
|
|
if not tp then return minetest.remove_node(pos) end
|
|
|
|
end
|
|
|
|
|
2020-01-15 23:10:18 -05:00
|
|
|
if tp.leaves then
|
|
|
|
leafbud(apos, 1, 0, 0, tp.leaves + 1)
|
|
|
|
leafbud(apos, -1, 0, 0, tp.leaves + 1)
|
|
|
|
leafbud(apos, 0, 0, 1, tp.leaves)
|
|
|
|
leafbud(apos, 0, 0, -1, tp.leaves)
|
|
|
|
end
|
|
|
|
|
2020-01-15 22:38:02 -05:00
|
|
|
if tp.notrunk then
|
2020-01-16 22:02:59 -05:00
|
|
|
nodecore.set_loud(apos, {
|
2020-01-15 22:38:02 -05:00
|
|
|
name = modname .. ":leaves_bud",
|
|
|
|
param2 = tp.leaves
|
|
|
|
})
|
|
|
|
else
|
2020-01-17 23:57:16 -05:00
|
|
|
nodecore.witness(apos, "grow tree")
|
2020-01-16 22:02:59 -05:00
|
|
|
nodecore.set_loud(apos, {
|
2020-01-15 22:38:02 -05:00
|
|
|
name = modname .. ":tree_bud",
|
|
|
|
param2 = param2
|
|
|
|
})
|
2020-01-15 23:10:18 -05:00
|
|
|
local sub = minetest.get_meta(apos)
|
|
|
|
sub:set_float("treegrowqty", data.total - trunkcost)
|
2020-01-16 21:43:07 -05:00
|
|
|
sub:set_float("treegrowtime", nodecore.gametime)
|
2020-01-15 23:10:18 -05:00
|
|
|
return false
|
2020-01-15 22:38:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
nodecore.register_limited_abm({
|
|
|
|
label = "Tree Leaves Growth",
|
|
|
|
nodenames = {modname .. ":leaves_bud"},
|
|
|
|
interval = 10,
|
2020-01-15 23:36:05 -05:00
|
|
|
chance = 10,
|
2020-01-15 22:38:02 -05:00
|
|
|
limited_max = 100,
|
|
|
|
limited_alert = 1000,
|
|
|
|
action = function(pos, node)
|
2020-01-16 22:02:59 -05:00
|
|
|
nodecore.set_loud(pos, nodecore.calc_leaves(pos))
|
2020-01-15 22:38:02 -05:00
|
|
|
if node.param2 <= 1 then
|
|
|
|
return
|
|
|
|
elseif node.param2 == 2 then
|
|
|
|
leafbud(pos, 1, 0, 0, 1)
|
|
|
|
leafbud(pos, -1, 0, 0, 1)
|
|
|
|
elseif node.param2 == 3 then
|
|
|
|
leafbud(pos, 0, 0, 1, 1)
|
|
|
|
leafbud(pos, 0, 0, -1, 1)
|
|
|
|
else
|
|
|
|
leafbud(pos, 1, 0, 0, 3)
|
|
|
|
leafbud(pos, -1, 0, 0, 3)
|
|
|
|
leafbud(pos, 0, 0, 1, 2)
|
|
|
|
leafbud(pos, 0, 0, -1, 2)
|
|
|
|
if node.param2 >= 6 then
|
2020-01-15 23:01:11 -05:00
|
|
|
leafbud(pos, 0, 1, 0, node.param2 - 4)
|
2020-01-15 22:38:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
2020-01-16 21:43:07 -05:00
|
|
|
|
2020-01-17 13:38:59 -05:00
|
|
|
local growtreedata = {
|
|
|
|
[epname] = {
|
|
|
|
r = nodecore.tree_growth_rate,
|
|
|
|
f = "eggcornqty"
|
|
|
|
},
|
|
|
|
[modname .. ":tree_bud"] = {
|
|
|
|
r = nodecore.tree_trunk_growth_rate,
|
|
|
|
f = "treegrowqty"
|
|
|
|
}
|
|
|
|
}
|
2020-01-16 21:43:07 -05:00
|
|
|
minetest.register_chatcommand("growtrees", {
|
|
|
|
description = "Accelerate growth of nearby trees",
|
|
|
|
privs = {["debug"] = true},
|
|
|
|
func = function(pname)
|
|
|
|
local player = minetest.get_player_by_name(pname)
|
|
|
|
if not player then return end
|
|
|
|
local pos = player:get_pos()
|
2020-01-17 13:38:59 -05:00
|
|
|
local spec = {}
|
|
|
|
for k in pairs(growtreedata) do spec[#spec + 1] = k end
|
|
|
|
for _, p in pairs(nodecore.find_nodes_around(pos, spec, 5)) do
|
|
|
|
local nn = minetest.get_node(p).name
|
|
|
|
local data = growtreedata[nn]
|
|
|
|
local r = data.r(p)
|
2020-01-16 21:43:07 -05:00
|
|
|
if r and r > 0 then
|
|
|
|
local meta = minetest.get_meta(p)
|
2020-01-17 13:38:59 -05:00
|
|
|
meta:set_float(data.f, 10000)
|
2020-01-16 21:43:07 -05:00
|
|
|
minetest.chat_send_player(pname, "boosted "
|
2020-01-17 13:38:59 -05:00
|
|
|
.. nn .. " at " .. minetest.pos_to_string(p))
|
2020-01-16 21:43:07 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|