Separate tech trees in tree mod.

This commit is contained in:
Aaron Suen 2018-11-03 11:26:15 -04:00
parent b7e3048fd7
commit 37c8b0865c
7 changed files with 90 additions and 46 deletions

View File

@ -1,6 +1,8 @@
-- LUALOCALS < ---------------------------------------------------------
local dofile, minetest, nodecore, pairs, rawset, type
= dofile, minetest, nodecore, pairs, rawset, type
local dofile, ipairs, math, minetest, nodecore, pairs, rawset, type
= dofile, ipairs, math, minetest, nodecore, pairs, rawset, type
local math_random
= math.random
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
@ -16,6 +18,31 @@ for k, v in pairs(minetest) do
end
end
function nodecore.mkreg()
local t = {}
local f = function(x) t[#t + 1] = x end
return f, t
end
function nodecore.pickrand(tbl, weight)
weight = weight or function() end
local t = {}
local max = 0
for k, v in pairs(tbl) do
local w = weight(v) or 1
if w > 0 then
max = max + w
t[#t + 1] = {w = w, v = v}
end
end
if max <= 0 then return end
max = math_random() * max
for i, v in ipairs(t) do
max = max - v.w
if max <= 0 then return v.v end
end
end
function nodecore.fixedbox(...) return {type = "fixed", fixed = {...}} end
local path = minetest.get_modpath(modname)

View File

@ -143,6 +143,7 @@ end
local old_get_node_drops = minetest.get_node_drops
minetest.get_node_drops = function(...)
local drops = old_get_node_drops(...)
if not digpos then return drops end
drops = drops or {}
local meta = minetest.get_meta(digpos)
local inv = meta:get_inventory()

View File

@ -3,7 +3,10 @@ local ipairs, minetest, nodecore
= ipairs, minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
nodecore.registered_on_register_node = {}
nodecore.register_on_register_node,
nodecore.registered_on_register_node
= nodecore.mkreg()
local oldreg = minetest.register_node
function minetest.register_node(name, def, ...)
for _, v in ipairs(nodecore.registered_on_register_node) do
@ -12,7 +15,3 @@ function minetest.register_node(name, def, ...)
end
return oldreg(name, def, ...)
end
function nodecore.register_on_register_node(func)
local t = nodecore.registered_on_register_node
t[#t + 1] = func
end

View File

@ -0,0 +1,27 @@
-- LUALOCALS < ---------------------------------------------------------
local minetest, nodecore
= minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
minetest.register_node(modname .. ":eggcorn", {
description = "EggCorn",
drawtype = "plantlike",
paramtype = "light",
visual_scale = 0.5,
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),
inventory_image = modname .. "_eggcorn.png",
tiles = { modname .. "_eggcorn.png" },
groups = {
snappy = 3,
falling_repose = 1
}
})
nodecore.register_leaf_drops(function(pos, node, list)
list[#list + 1] = {
name = modname .. ":eggcorn",
prob = 0.1 * (node.param2 + 1)}
end)

View File

@ -1,11 +1,15 @@
-- LUALOCALS < ---------------------------------------------------------
local dofile, minetest
= dofile, minetest
local dofile, minetest, nodecore
= dofile, minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
nodecore.register_leaf_drops, nodecore.registered_leaf_drops
= nodecore.mkreg()
local modname = minetest.get_current_modname()
local path = minetest.get_modpath(modname)
dofile(path .. "/node.lua")
dofile(path .. "/sticks.lua")
dofile(path .. "/cultivation.lua")
dofile(path .. "/decor.lua")

View File

@ -1,8 +1,6 @@
-- LUALOCALS < ---------------------------------------------------------
local math, minetest, type
= math, minetest, type
local math_random
= math.random
local ipairs, minetest, nodecore, type
= ipairs, minetest, nodecore, type
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
@ -44,36 +42,20 @@ minetest.register_node(modname .. ":leaves", {
},
alternate_solid = {
after_dig_node = function(pos, node)
node = node or minetest.get_node(node)
local l = modname .. ":leaves_loose"
local e = modname .. ":eggcorn"
local b = modname .. ":stick"
local p = {l, l, l, l, l, l, l, l, b, b, e}
for i = 1, node.param2 do
p[#p + 1] = e
p[#p + 1] = e
p[#p + 1] = b
p[#p + 1] = b
node = node or minetest.get_node(pos)
local t = {}
for i, v in ipairs(nodecore.registered_leaf_drops) do
t = v(pos, node, t) or t
end
minetest.place_node(pos,
{name = p[math_random(1, #p)]})
local p = nodecore.pickrand(t, function(x) return x.prob end)
if not p then return end
minetest.place_node(pos, p)
end
}
})
nodecore.register_leaf_drops(function(pos, node, list)
list[#list + 1] = {name = modname .. ":leaves_loose"}
end)
local function fixed(t) return {type = "fixed", fixed = t} end
minetest.register_node(modname .. ":eggcorn", {
description = "EggCorn",
drawtype = "plantlike",
paramtype = "light",
visual_scale = 0.5,
collision_box = fixed({-3/16, -0.5, -3/16, 3/16, 0, 3/16}),
selection_box = fixed({-3/16, -0.5, -3/16, 3/16, 0, 3/16}),
inventory_image = modname .. "_eggcorn.png",
tiles = { modname .. "_eggcorn.png" },
groups = {
snappy = 3,
falling_repose = 1
}
})

View File

@ -1,16 +1,14 @@
-- LUALOCALS < ---------------------------------------------------------
local ItemStack, minetest, type
= ItemStack, minetest, type
local ItemStack, minetest, nodecore
= ItemStack, minetest, nodecore
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local function fixed(t) return {type = "fixed", fixed = t} end
minetest.register_node(modname .. ":stick", {
description = "Stick",
drawtype = "nodebox",
node_box = fixed({-1/16, -0.5, -1/16, 1/16, 0, 1/16}),
node_box = nodecore.fixedbox(-1/16, -0.5, -1/16, 1/16, 0, 1/16),
tiles = {
modname .. "_tree_top.png",
modname .. "_tree_top.png",
@ -30,10 +28,16 @@ minetest.register_node(modname .. ":stick", {
end
})
nodecore.register_leaf_drops(function(pos, node, list)
list[#list + 1] = {
name = modname .. ":stick",
prob = 0.2 * (node.param2 * node.param2)}
end)
minetest.register_node(modname .. ":staff", {
description = "Staff",
drawtype = "nodebox",
node_box = fixed({-1/16, -0.5, -1/16, 1/16, 0.5, 1/16}),
node_box = nodecore.fixedbox(-1/16, -0.5, -1/16, 1/16, 0.5, 1/16),
tiles = {
modname .. "_tree_top.png",
modname .. "_tree_top.png",
@ -65,7 +69,7 @@ minetest.register_tool(modname .. ":adze", {
tool_capabilities = {
full_punch_interval = 1.2,
groupcaps = {
choppy = {times={[3]=1.60}, uses=5, maxlevel=1},
choppy = {times={[3]=1.60}, uses=20, maxlevel=1},
}
},
})