2018-11-03 11:26:15 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-09-08 12:56:51 -04:00
|
|
|
local math, minetest, nodecore, pairs
|
|
|
|
= math, minetest, nodecore, pairs
|
2019-09-05 22:48:30 -04:00
|
|
|
local math_sqrt
|
|
|
|
= math.sqrt
|
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",
|
2018-11-03 11:26:15 -04:00
|
|
|
tiles = { modname .. "_eggcorn.png" },
|
|
|
|
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
|
|
|
|
if stack:get_name() ~= ldname then return end
|
|
|
|
|
|
|
|
minetest.set_node(pos, {name = epname})
|
|
|
|
nodecore.node_sound(pos, "place")
|
|
|
|
|
|
|
|
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-03-06 21:52:53 -05:00
|
|
|
minetest.register_node(epname, nodecore.underride({
|
2019-08-23 20:38:31 -04:00
|
|
|
drop = ldname
|
2019-03-06 21:52:53 -05:00
|
|
|
},
|
2019-03-13 23:51:59 -04:00
|
|
|
minetest.registered_items[ldname] or {}))
|
2018-11-03 12:55:26 -04:00
|
|
|
|
2019-09-05 22:48:30 -04:00
|
|
|
nodecore.register_soaking_abm({
|
2018-11-03 12:55:26 -04:00
|
|
|
label = "EggCorn Growing",
|
|
|
|
nodenames = {epname},
|
|
|
|
interval = 10,
|
2019-02-01 18:34:03 -05:00
|
|
|
chance = 1,
|
2019-09-05 22:48:30 -04:00
|
|
|
qtyfield = "growth",
|
|
|
|
timefield = "start",
|
|
|
|
soakrate = function(pos)
|
2019-02-01 18:34:03 -05:00
|
|
|
local d = 0
|
|
|
|
local w = 1
|
|
|
|
nodecore.scan_flood(pos, 3, function(p)
|
|
|
|
local nn = minetest.get_node(p).name
|
2019-03-13 23:51:59 -04:00
|
|
|
local def = minetest.registered_items[nn] or {}
|
|
|
|
if not def.groups then
|
2019-02-01 18:34:03 -05:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
if def.groups.soil then
|
|
|
|
d = d + def.groups.soil
|
|
|
|
w = w + 0.2
|
2019-08-23 20:51:19 -04:00
|
|
|
elseif def.groups.moist then
|
|
|
|
w = w + def.groups.moist
|
2019-02-01 18:34:03 -05:00
|
|
|
return false
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end)
|
2019-09-05 22:48:30 -04:00
|
|
|
return math_sqrt(d * w)
|
|
|
|
end,
|
|
|
|
soakcheck = function(data, pos)
|
|
|
|
if data.total >= 5000 then
|
2019-09-05 23:01:06 -04:00
|
|
|
minetest.sound_play("nc_tree_woody", {pos = pos, gain = 5})
|
|
|
|
for _ = 1, 4 do
|
|
|
|
minetest.sound_play("nc_terrain_swishy", {pos = pos, gain = 3})
|
|
|
|
end
|
2019-09-08 12:56:51 -04:00
|
|
|
local leaves = {}
|
|
|
|
for i = 1, 8 do
|
|
|
|
local p = {x = pos.x, y = pos.y + i, z = pos.z}
|
|
|
|
local n = minetest.get_node(p)
|
|
|
|
if n.name == modname .. ":leaves" then
|
|
|
|
leaves[p] = n
|
|
|
|
minetest.remove_node(p)
|
|
|
|
end
|
|
|
|
end
|
2019-09-05 22:48:30 -04:00
|
|
|
local place = {x = pos.x - 2, y = pos.y, z = pos.z - 2}
|
2019-09-08 12:56:51 -04:00
|
|
|
minetest.place_schematic(place, nodecore.tree_schematic,
|
2019-09-05 22:48:30 -04:00
|
|
|
"random", {}, false)
|
2019-09-08 12:56:51 -04:00
|
|
|
for p, n in pairs(leaves) do
|
|
|
|
if minetest.get_node(p).name == "air" then
|
|
|
|
minetest.set_node(p, n)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return
|
2019-09-05 22:48:30 -04:00
|
|
|
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
|
|
|
|
})
|