2018-11-03 11:26:15 -04:00
|
|
|
-- LUALOCALS < ---------------------------------------------------------
|
2019-10-06 09:26:18 -04:00
|
|
|
local minetest, nodecore, pairs, vector
|
|
|
|
= minetest, nodecore, pairs, vector
|
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
|
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
|
|
|
|
|
|
|
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-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
|
|
|
|
2019-10-05 10:17:47 -04:00
|
|
|
local function growtree(pos)
|
2019-10-27 10:05:57 -04:00
|
|
|
nodecore.witness(vector.add(pos, {x = 0, y = 0.499, z = 0}), "grow tree")
|
2019-10-05 10:17:47 -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
|
|
|
|
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)
|
|
|
|
else
|
|
|
|
local def = minetest.registered_nodes[n.name]
|
|
|
|
if def and def.buildable_to then
|
|
|
|
leaves[p] = n
|
|
|
|
minetest.remove_node(p)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
local place = {x = pos.x - 2, y = pos.y, z = pos.z - 2}
|
2019-10-06 09:26:18 -04:00
|
|
|
minetest.get_meta(pos):from_table({})
|
2019-10-05 10:17:47 -04:00
|
|
|
minetest.place_schematic(place, nodecore.tree_schematic,
|
|
|
|
"random", {}, false)
|
|
|
|
for p, n in pairs(leaves) do
|
|
|
|
if minetest.get_node(p).name == "air" then
|
|
|
|
minetest.set_node(p, n)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_chatcommand("growtrees", {
|
|
|
|
description = "Instantly grow 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()
|
|
|
|
local range = {x = 5, y = 5, z = 5}
|
|
|
|
local min = vector.subtract(pos, range)
|
|
|
|
local max = vector.add(pos, range)
|
|
|
|
for _, p in pairs(minetest.find_nodes_in_area(min, max, {epname})) do
|
2019-10-19 11:00:18 -04:00
|
|
|
local r = nodecore.tree_growth_rate(p)
|
2019-10-05 10:17:47 -04:00
|
|
|
if r and r > 0 then growtree(p) end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
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-10-01 18:23:12 -04:00
|
|
|
limited_max = 100,
|
|
|
|
limited_alert = 1000,
|
2019-09-05 22:48:30 -04:00
|
|
|
qtyfield = "growth",
|
|
|
|
timefield = "start",
|
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)
|
2019-10-05 10:17:47 -04:00
|
|
|
if data.total >= 5000 then return growtree(pos) 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
|
|
|
|
})
|