initial commit.
created a few proof-of-concept mechanics. took some textures from minetest game. implemented basic tree growth and stacking in-world crafting.
After Width: | Height: | Size: 6.8 KiB |
|
@ -0,0 +1,3 @@
|
|||
movement_liquid_sink = 0
|
||||
time_speed = 0
|
||||
default_stack_max = 128
|
|
@ -0,0 +1,11 @@
|
|||
local load_file = function (filename)
|
||||
return dofile(minetest.get_modpath(minetest.get_current_modname()) .. "/" .. filename .. ".lua")
|
||||
end
|
||||
rawset(_G, "load_file", load_file)
|
||||
|
||||
local blockgame = {}
|
||||
rawset(_G, "blockgame", blockgame)
|
||||
|
||||
load_file("utils_node")
|
||||
load_file("utils_stringify")
|
||||
load_file("utils_random")
|
|
@ -0,0 +1,2 @@
|
|||
name = api
|
||||
description = api mod for blockgame.
|
|
@ -0,0 +1,12 @@
|
|||
local reg_simple_node = function (name, desc, groups)
|
||||
local my_modname = minetest.get_current_modname()
|
||||
return minetest.register_node(my_modname .. ":" .. name, {
|
||||
description = desc,
|
||||
tiles = {
|
||||
my_modname .. "_" .. name .. ".png",
|
||||
},
|
||||
groups = groups,
|
||||
})
|
||||
end
|
||||
|
||||
blockgame.reg_simple_node = reg_simple_node
|
|
@ -0,0 +1,5 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
|
||||
blockgame.chance = function (chance)
|
||||
return math.random(chance) == 1
|
||||
end
|
|
@ -0,0 +1,13 @@
|
|||
local stringify = function (tab)
|
||||
if type(tab) == "table" then
|
||||
local result = "{ "
|
||||
for key, value in pairs(tab) do
|
||||
result = result .. key .. ": " .. blockgame.stringify(value) .. ", "
|
||||
end
|
||||
return result .. "}"
|
||||
else
|
||||
return tab
|
||||
end
|
||||
end
|
||||
|
||||
blockgame.stringify = stringify
|
|
@ -0,0 +1,15 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
|
||||
minetest.clear_registered_biomes()
|
||||
minetest.register_biome({
|
||||
name = "unknown",
|
||||
node_top = modname .. ":grass",
|
||||
depth_top = 1,
|
||||
node_filler = modname .. ":dirt",
|
||||
depth_filler = 2,
|
||||
node_stone = modname .. ":stone",
|
||||
heat_point = 0,
|
||||
humidity_point = 0,
|
||||
y_min = -31000,
|
||||
y_max = 31000,
|
||||
})
|
|
@ -0,0 +1,19 @@
|
|||
local create_group_cap = function (max_level)
|
||||
return {maxlevel = max_level, times={[1] = 1, [2] = 2, [3] = 3}}
|
||||
end
|
||||
|
||||
minetest.register_item(":", {
|
||||
["type"] = "none",
|
||||
inventory_image = "[combine:1x1",
|
||||
tool_capabilities = {
|
||||
groupcaps ={
|
||||
uses = 0,
|
||||
cracky = create_group_cap(3),
|
||||
stoney = create_group_cap(3),
|
||||
dirty = create_group_cap(3),
|
||||
woody = create_group_cap(3),
|
||||
planty = create_group_cap(3),
|
||||
},
|
||||
},
|
||||
node_placement_prediction = "",
|
||||
})
|
|
@ -0,0 +1,5 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
|
||||
load_file("node")
|
||||
load_file("biome")
|
||||
load_file("hand")
|
|
@ -0,0 +1,3 @@
|
|||
name = core
|
||||
description = core mod for blockgame.
|
||||
depends = api
|
|
@ -0,0 +1,19 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
|
||||
blockgame.reg_simple_node("stone", "Stone", {
|
||||
cracky = 3,
|
||||
stoney = 1,
|
||||
})
|
||||
|
||||
minetest.register_alias("mapgen_stone", modname .. ":stone")
|
||||
minetest.register_alias("mapgen_water_source", "air")
|
||||
|
||||
blockgame.reg_simple_node("grass", "Grass", {
|
||||
cracky = 3,
|
||||
dirty = 1,
|
||||
})
|
||||
|
||||
blockgame.reg_simple_node("dirt", "Dirt", {
|
||||
cracky = 3,
|
||||
dirty = 1,
|
||||
})
|
After Width: | Height: | Size: 268 B |
After Width: | Height: | Size: 272 B |
After Width: | Height: | Size: 461 B |
After Width: | Height: | Size: 232 B |
After Width: | Height: | Size: 411 B |
After Width: | Height: | Size: 175 B |
After Width: | Height: | Size: 279 B |
After Width: | Height: | Size: 129 B |
|
@ -0,0 +1,45 @@
|
|||
blockgame.crafting = blockgame.crafting or {}
|
||||
local api = blockgame.crafting
|
||||
|
||||
local recipes = {}
|
||||
api.registered_recipes = recipes
|
||||
|
||||
api.register_stack_recipe = function (top_node, bottom_node, result, consumes_top)
|
||||
local consumes_top = consumes_top
|
||||
if consumes_top == nil then consumes_top = true end
|
||||
|
||||
recipes[top_node] = recipes[top_node] or {}
|
||||
|
||||
table.insert(recipes[top_node], {
|
||||
["type"] = "stack_two_nodes",
|
||||
index_key = top_node,
|
||||
top_node = top_node,
|
||||
bottom_node = bottom_node,
|
||||
result = result,
|
||||
consumes_top = consumes_top,
|
||||
})
|
||||
end
|
||||
|
||||
api.handle_placement = function (pos, new_node, placer, old_node, itemstack, pointed_thing)
|
||||
if recipes[new_node.name] == nil then return false end
|
||||
|
||||
for _, recipe in pairs(recipes[new_node.name]) do
|
||||
local result = api.handle_stack_recipe(recipe, pos, new_node)
|
||||
if result then return not recipe.consumes_top end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
api.handle_stack_recipe = function (recipe, pos, top_node)
|
||||
if top_node.name ~= recipe.top_node then return false end
|
||||
|
||||
local down = vector.add(pos, vector.new(0, -1, 0))
|
||||
local below = minetest.get_node(down)
|
||||
if below.name ~= recipe.bottom_node then return false end
|
||||
|
||||
minetest.remove_node(pos)
|
||||
minetest.set_node(down, recipe.result)
|
||||
|
||||
return true
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
|
||||
load_file("api")
|
||||
|
||||
minetest.register_on_placenode(function (...)
|
||||
return blockgame.crafting.handle_placement(...)
|
||||
end)
|
|
@ -0,0 +1,3 @@
|
|||
name = crafting
|
||||
description = crafting mod for blockgame.
|
||||
depends = core, api
|
|
@ -0,0 +1,51 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
|
||||
blockgame.tree = blockgame.tree or {}
|
||||
local api = blockgame.tree
|
||||
|
||||
-- TODO move these to the general api since they're not tree-specific.
|
||||
local sides = {
|
||||
vector.new(0, 0, -1),
|
||||
vector.new(0, 0, 1),
|
||||
vector.new(-1, 0, 0),
|
||||
vector.new(1, 0, 0),
|
||||
}
|
||||
|
||||
local directions = {
|
||||
vector.new(0, 0, -1),
|
||||
vector.new(0, 0, 1),
|
||||
vector.new(0, -1, 0),
|
||||
vector.new(0, 1, 0),
|
||||
vector.new(-1, 0, 0),
|
||||
vector.new(1, 0, 0),
|
||||
}
|
||||
|
||||
blockgame.random_side = function ()
|
||||
return sides[math.random(#sides)]
|
||||
end
|
||||
blockgame.random_dir = function ()
|
||||
return directions[math.random(#directions)]
|
||||
end
|
||||
|
||||
blockgame.get_below = function (pos)
|
||||
return pos + vector.new(0, -1, 0)
|
||||
end
|
||||
-- end of TODO
|
||||
|
||||
|
||||
|
||||
api.find_bottom_log = function (pos, max_height)
|
||||
local pos = vector.copy(pos)
|
||||
local step = 0
|
||||
while step < max_height do
|
||||
local new_pos = blockgame.get_below(pos)
|
||||
if minetest.get_node(new_pos).name ~= modname .. ":log" then
|
||||
return pos
|
||||
end
|
||||
pos = new_pos
|
||||
|
||||
step = step + 1
|
||||
end
|
||||
return nil
|
||||
end
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
|
||||
minetest.register_decoration({
|
||||
deco_type = "simple",
|
||||
place_on = {"core:grass"},
|
||||
sidelen = 16,
|
||||
-- fill_ratio = 0.025,
|
||||
noise_params = {
|
||||
offset = -0.001,
|
||||
scale = 0.015,
|
||||
spread = {x = 64, y = 64, z = 64},
|
||||
octaves = 3,
|
||||
persistence = 0.6,
|
||||
},
|
||||
y_min = -31000,
|
||||
y_max = 31000,
|
||||
decoration = modname .. ":log",
|
||||
})
|
|
@ -0,0 +1,95 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
local api = blockgame.tree
|
||||
|
||||
local attempt_place = function (pos, node)
|
||||
if minetest.get_node(pos).name ~= "air" then return false end
|
||||
return minetest.set_node(pos, node)
|
||||
end
|
||||
|
||||
|
||||
local extend_leaves_from = function (pos)
|
||||
local side = blockgame.random_side()
|
||||
attempt_place(pos + side, {name = modname .. ":leaves"})
|
||||
end
|
||||
|
||||
local random_walk = function (pos, steps, check)
|
||||
local pos = vector.copy(pos)
|
||||
local step = 0
|
||||
while step < steps do
|
||||
local dir = blockgame.random_dir()
|
||||
local new_pos = pos + dir
|
||||
if check(new_pos) then pos = new_pos end
|
||||
step = step + 1
|
||||
end
|
||||
return pos
|
||||
end
|
||||
|
||||
local spread_roots_from = function (source)
|
||||
local root_pos = random_walk(source, 2, function (pos)
|
||||
if minetest.get_node(pos).name == modname .. ":log" then return true end
|
||||
if minetest.get_node(pos).name == modname .. ":root" then return true end
|
||||
return false
|
||||
end)
|
||||
|
||||
local root_node = minetest.get_node(root_pos)
|
||||
|
||||
if minetest.get_node(root_pos + vector.new(0, 1, 0)).name == modname .. ":log" then
|
||||
minetest.set_node(root_pos, {name = modname .. ":root"})
|
||||
return true
|
||||
end
|
||||
|
||||
local side = blockgame.random_side()
|
||||
local target_pos = root_pos + side
|
||||
if blockgame.chance(2) then target_pos = blockgame.get_below(root_pos) end
|
||||
|
||||
if minetest.get_item_group(minetest.get_node(target_pos), "dirty") then
|
||||
return minetest.set_node(target_pos, {name = modname .. ":root"})
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
minetest.register_abm({
|
||||
label = "sapling grow",
|
||||
nodenames = {"tree:sapling"},
|
||||
neighbors = {"group:dirty", modname .. ":log"},
|
||||
interval = 15,
|
||||
chance = 4,
|
||||
catch_up = true,
|
||||
action = function (pos, node, active_object_count, active_object_count_wider)
|
||||
local below = blockgame.get_below(pos)
|
||||
|
||||
if blockgame.chance(4) then
|
||||
local root_source = api.find_bottom_log(pos, 8)
|
||||
if root_source ~= nil then
|
||||
spread_roots_from(root_source)
|
||||
end
|
||||
end
|
||||
|
||||
if blockgame.chance(2) then
|
||||
extend_leaves_from(pos)
|
||||
end
|
||||
if blockgame.chance(2) then
|
||||
extend_leaves_from(pos)
|
||||
end
|
||||
|
||||
if blockgame.chance(2) then
|
||||
local side = blockgame.random_side()
|
||||
local target = pos + side
|
||||
|
||||
attempt_place(target, {name = modname .. ":log"})
|
||||
|
||||
if blockgame.chance(2) then
|
||||
extend_leaves_from(target)
|
||||
end
|
||||
end
|
||||
|
||||
if blockgame.chance(4) then
|
||||
minetest.set_node(pos, {name = modname .. ":log"})
|
||||
|
||||
if minetest.get_node(below).name == modname .. ":log" and blockgame.chance(2) then return end
|
||||
|
||||
attempt_place(pos + vector.new(0, 1, 0), {name = modname .. ":sapling"})
|
||||
end
|
||||
end,
|
||||
})
|
|
@ -0,0 +1,5 @@
|
|||
load_file("api")
|
||||
load_file("decoration")
|
||||
load_file("node")
|
||||
load_file("grow")
|
||||
load_file("recipes")
|
|
@ -0,0 +1,3 @@
|
|||
name = tree
|
||||
description = blockgame tree mod.
|
||||
depends = core, crafting
|
|
@ -0,0 +1,51 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
|
||||
blockgame.reg_simple_node("log", "Log", {
|
||||
woody = 1,
|
||||
})
|
||||
|
||||
blockgame.reg_simple_node("sapling", "Sapling", {
|
||||
planty = 1,
|
||||
})
|
||||
|
||||
blockgame.reg_simple_node("plank", "Plank", {
|
||||
woody = 1,
|
||||
})
|
||||
|
||||
minetest.register_node(modname .. ":leaves", {
|
||||
description = "Leaves",
|
||||
drawtype = "glasslike",
|
||||
tiles = {
|
||||
modname .. "_leaves.png",
|
||||
},
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
groups = {
|
||||
planty = 1,
|
||||
},
|
||||
drop = {
|
||||
max_items = 2,
|
||||
items = {
|
||||
{
|
||||
rarity = 16,
|
||||
items = {modname .. ":nut 3"}
|
||||
},
|
||||
{
|
||||
rarity = 8,
|
||||
items = {modname .. ":nut 2"}
|
||||
},
|
||||
{
|
||||
rarity = 4,
|
||||
items = {modname .. ":nut"}
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
blockgame.reg_simple_node("nut", "Nut", {
|
||||
woody = 1,
|
||||
})
|
||||
|
||||
blockgame.reg_simple_node("root", "Root", {
|
||||
woody = 1,
|
||||
})
|
|
@ -0,0 +1,4 @@
|
|||
local modname = minetest.get_current_modname()
|
||||
|
||||
blockgame.crafting.register_stack_recipe("core:grass", modname .. ":nut", {name = modname .. ":sapling"})
|
||||
blockgame.crafting.register_stack_recipe(modname .. ":log", modname .. ":nut", {name = modname .. ":plank"})
|
After Width: | Height: | Size: 956 B |
After Width: | Height: | Size: 305 B |
After Width: | Height: | Size: 657 B |
After Width: | Height: | Size: 712 B |
After Width: | Height: | Size: 218 B |
After Width: | Height: | Size: 862 B |
After Width: | Height: | Size: 190 B |