mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-09-12 08:42:10 +02:00
132 lines
3.5 KiB
Lua
132 lines
3.5 KiB
Lua
---
|
|
--- Generated by EmmyLua(https://github.com/EmmyLua)
|
|
--- Created by michieal.
|
|
--- DateTime: 12/29/22 12:34 PM -- Restructure Date
|
|
---
|
|
|
|
local modname = minetest.get_current_modname()
|
|
local S = minetest.get_translator(modname)
|
|
local bamboo = "mcl_bamboo:bamboo"
|
|
local DEBUG = false
|
|
|
|
local strlen = string.len
|
|
local substr = string.sub
|
|
local rand = math.random
|
|
|
|
--Bamboo can be planted on moss blocks, grass blocks, dirt, coarse dirt, rooted dirt, gravel, mycelium, podzol, sand, red sand, or mud
|
|
mcl_bamboo.bamboo_dirt_nodes = {
|
|
"mcl_core:redsand",
|
|
"mcl_core:sand",
|
|
"mcl_core:dirt",
|
|
"mcl_core:coarse_dirt",
|
|
"mcl_core:dirt_with_grass",
|
|
"mcl_core:podzol",
|
|
"mcl_core:mycelium",
|
|
"mcl_lush_caves:rooted_dirt",
|
|
"mcl_lush_caves:moss",
|
|
"mcl_mud:mud",
|
|
}
|
|
|
|
--- pos: node position; placer: ObjectRef that is placing the item
|
|
--- returns: true if protected, otherwise false.
|
|
function mcl_bamboo.is_protected(pos, placer)
|
|
local name = placer:get_player_name()
|
|
if minetest.is_protected(pos, name) then
|
|
minetest.record_protection_violation(pos, name)
|
|
return true
|
|
end
|
|
return false
|
|
end
|
|
|
|
function mcl_bamboo.grow_bamboo(pos, _)
|
|
local BAMBOO_SOIL_DIST = -16
|
|
local BAM_MAX_HEIGHT_STPCHK = 11
|
|
local BAM_MAX_HEIGHT_TOP = 15
|
|
|
|
local chk_pos
|
|
local soil_pos
|
|
if minetest.get_node_light(pos) < 8 then
|
|
return
|
|
end
|
|
local found = false -- used for the soil check
|
|
local mboo = ""
|
|
for py = -1, BAMBOO_SOIL_DIST, -1 do
|
|
chk_pos = vector.offset(pos, 0, py, 0)
|
|
local name = minetest.get_node(chk_pos).name
|
|
for i = 1, #mcl_bamboo.bamboo_dirt_nodes do
|
|
if name == mcl_bamboo.bamboo_dirt_nodes[i] then
|
|
found = true
|
|
soil_pos = chk_pos
|
|
break
|
|
end
|
|
end
|
|
if found then
|
|
break
|
|
else
|
|
mboo = substr(name, strlen(name) - 3, strlen(name))
|
|
if mboo ~= "mboo" and mboo ~= "oo_1" and mboo ~= "oo_2" and mboo ~= "oo_3" then
|
|
break
|
|
end
|
|
end
|
|
end
|
|
-- requires knowing where the soil node is.
|
|
if not found then
|
|
return
|
|
end
|
|
local grow_amount = rand(1, 32)
|
|
grow_amount = rand(1, 32)
|
|
grow_amount = rand(1, 32)
|
|
grow_amount = rand(1, 32) -- because yeah, not truly random, or even a good prng.
|
|
-- Bonemeal: Grows the bamboo by 1-2 stems. (per the minecraft wiki.)
|
|
|
|
for py = 1, BAM_MAX_HEIGHT_TOP do
|
|
chk_pos = vector.offset(pos, 0, py, 0)
|
|
local node_below = minetest.get_node(pos).name
|
|
local name = minetest.get_node(chk_pos).name
|
|
local dist = vector.distance(soil_pos, chk_pos)
|
|
if dist >= BAM_MAX_HEIGHT_STPCHK then
|
|
-- stop growing check.
|
|
if name == "air" then
|
|
local height = rand(BAM_MAX_HEIGHT_STPCHK, BAM_MAX_HEIGHT_TOP)
|
|
if height == dist then
|
|
minetest.set_node(chk_pos, {name = "mcl_bamboo:bamboo_endcap"})
|
|
end
|
|
end
|
|
break
|
|
end
|
|
mboo = substr(name, strlen(name) - 3, strlen(name))
|
|
if name == "air" then
|
|
minetest.set_node(chk_pos, {name = node_below})
|
|
-- handle growing a second node.
|
|
if grow_amount == 2 then
|
|
chk_pos = vector.offset(chk_pos, 0, 1, 0)
|
|
if minetest.get_node(chk_pos).name == "air" then
|
|
minetest.set_node(chk_pos, {name = node_below})
|
|
end
|
|
end
|
|
break
|
|
elseif mboo ~= "mboo" and mboo ~= "oo_1" and mboo ~= "oo_2" and mboo ~= "oo_3" then
|
|
break
|
|
end
|
|
end
|
|
|
|
end
|
|
|
|
-- Add Groups function, courtesy of Warr1024.
|
|
function mcl_bamboo.addgroups(name, ...)
|
|
local def = minetest.registered_items[name] or error(name .. " not found")
|
|
local groups = {}
|
|
for k, v in pairs(def.groups) do
|
|
groups[k] = v
|
|
end
|
|
local function addall(x, ...)
|
|
if not x then
|
|
return
|
|
end
|
|
groups[x] = 1
|
|
return addall(...)
|
|
end
|
|
addall(...)
|
|
return minetest.override_item(name, {groups = groups})
|
|
end
|