Compare commits

...

6 Commits

Author SHA1 Message Date
trans_soup 7755583fa4 rename mods and add hacky cleanup thing.
rename mods; add `bg_` prefix.

add hacky cleanup ABM (couldn't get LBM:s to work), that converts old
nodes into new ones according to this rename.

the cleanup doesn't do anything for items, though.
2023-10-15 18:22:13 +02:00
trans_soup 7f3535ca27 make util_stringify more robust. 2023-10-15 17:46:08 +02:00
trans_soup d1a8ad952b fix random tick crash possibility. 2023-10-15 17:38:11 +02:00
trans_soup 24ec93cd50 fix name fields in `mod.conf` files. 2023-10-15 17:23:37 +02:00
trans_soup 8cc8a08f3d create (currently usused) funnel mod. 2023-10-14 15:33:24 +02:00
trans_soup 68202b9c82 minor file rename. 2023-10-14 13:39:53 +02:00
61 changed files with 311 additions and 34 deletions

19
mods/bg_api/cleanup.lua Normal file
View File

@ -0,0 +1,19 @@
-- move from old modnames to new ones. (old ones didn't have the `bg_` prefix.)
minetest.register_on_mods_loaded(function ()
local nodes = minetest.registered_nodes
local names = {}
for name, _ in pairs(nodes) do
table.insert(names, string.sub(name, 4))
end
-- using LBM:s doesn't work for some reason, so this ABM hack thing is used instead.
minetest.register_abm({
nodenames = names,
interval = 10,
chance = 1,
action = function (pos, node)
local name = node.name
minetest.set_node(pos, {name = "bg_" .. name})
end,
})
end)

View File

@ -17,3 +17,5 @@ load_file("util_node")
load_file("wrappers")
load_file("random_tick")
load_file("cleanup")

View File

@ -1,2 +1,2 @@
name = api
name = bg_api
description = api mod for blockgame.

View File

@ -34,6 +34,7 @@ local function random_tick (mapblock_pos)
local pos = vector.new(x, y, z)
local node_def = minetest.registered_nodes[minetest.get_node(pos).name]
if not node_def then return end
if type(node_def.on_random_tick) == "function" then
node_def.on_random_tick(pos, node, i)
end

View File

@ -14,8 +14,8 @@ end
-- probably temporary; will probably use groups for this later.
local air_flowable = {
"air",
"tree:leaves",
"tree:leaves_alive",
"bg_tree:leaves",
"bg_tree:leaves_alive",
}
function blockgame.air_flows_through (pos, node)

View File

@ -5,6 +5,12 @@ function blockgame.stringify (tab)
result = result .. key .. ": " .. blockgame.stringify(value) .. ", "
end
return result .. "}"
elseif type(tab) == "function" then
return "<function>"
elseif type(tab) == "boolean" then
if tab then return "true" else return "false" end
elseif type(tab) == "nil" then
return "nil"
else
return tab
end

View File

@ -1,3 +1,3 @@
name = core
name = bg_core
description = core mod for blockgame.
depends = api
depends = bg_api

View File

Before

Width:  |  Height:  |  Size: 966 B

After

Width:  |  Height:  |  Size: 966 B

View File

Before

Width:  |  Height:  |  Size: 272 B

After

Width:  |  Height:  |  Size: 272 B

View File

Before

Width:  |  Height:  |  Size: 461 B

After

Width:  |  Height:  |  Size: 461 B

View File

Before

Width:  |  Height:  |  Size: 232 B

After

Width:  |  Height:  |  Size: 232 B

View File

Before

Width:  |  Height:  |  Size: 411 B

After

Width:  |  Height:  |  Size: 411 B

View File

Before

Width:  |  Height:  |  Size: 175 B

After

Width:  |  Height:  |  Size: 175 B

View File

Before

Width:  |  Height:  |  Size: 279 B

After

Width:  |  Height:  |  Size: 279 B

View File

Before

Width:  |  Height:  |  Size: 129 B

After

Width:  |  Height:  |  Size: 129 B

View File

@ -1,3 +1,3 @@
name = crafting
name = bg_crafting
description = crafting mod for blockgame.
depends = core, api
depends = bg_core, bg_api

57
mods/bg_funnel/api.lua Normal file
View File

@ -0,0 +1,57 @@
local function get_inventory (pos)
local meta = minetest.get_meta(pos)
return minetest.deserialize(meta:get_string("inventory"))
end
local function set_inventory (pos, inventory)
local meta = minetest.get_meta(pos)
meta:set_string("inventory", minetest.serialize(inventory))
end
local function push (pos, value)
local inventory = get_inventory(pos)
if not inventory then return false end
table.insert(inventory, value)
set_inventory(pos, inventory)
return true
end
local function pop (pos)
local inventory = get_inventory(pos)
if not inventory then return nil end
local value = table.remove(inventory, 1)
set_inventory(pos, inventory)
return value
end
local function place_funnel (itemstack, placed, pointed)
local result = minetest.item_place(itemstack, placer, pointed)
local pos = pointed.above
local meta = minetest.get_meta(pos)
set_inventory(pos, {})
return result
end
local function dig_funnel (pos, ...)
local result = minetest.node_dig(pos, ...)
return result
end
return {
get_inventory = get_inventory,
set_inventory = set_inventory,
place_funnel = place_funnel,
dig_funnel = dig_funnel,
push = push,
pop = pop,
}

82
mods/bg_funnel/funnel.lua Normal file
View File

@ -0,0 +1,82 @@
local modname = minetest.get_current_modname()
local api = load_file("api")
local function get_meta_table (pos)
return minetest.get_meta(pos):to_table()
end
local function set_meta (pos, meta_table)
local meta = minetest.get_meta(pos)
for key, value in pairs(meta_table) do
local fn = nil
if type(value) == "string" then fn = "set_string" end
if type(value) == "int" then fn = "set_int" end
if type(value) == "float" then fn = "set_float" end
if fn then
meta[fn](key, value)
end
end
end
local function attempt_input (pos)
-- TODO: add max limit for amount of nodes inside funnel inventory.
local above = pos + blockgame.vector.dirs.up
if minetest.get_node(above).name == "air" then return false end
local node = minetest.get_node(above)
local meta = get_meta_table(above)
local value = {
node = node,
meta = meta,
}
local success = api.push(pos, value)
if not success then return false end
minetest.remove_node(above)
return true
end
local function attempt_output (pos)
local below = pos + blockgame.vector.dirs.down
if minetest.get_node(below).name ~= "air" then return false end
local value = api.pop(pos)
if not value then return nil end
local node = value.node
local meta = value.meta
minetest.set_node(below, node)
set_meta(below, meta)
return true
end
blockgame.register_abm({
label = "funnel nodes",
nodenames = {modname .. ":funnel"},
interval = 1,
chance = 1,
catch_up = false,
action = function (pos)
-- NOTE: metadata storage might not work, and funnels might not be able to pick up other funnels successfully.
attempt_input(pos)
attempt_output(pos)
end,
})
-- NOTE: the documentation says `register_on_placenode` is "not recommended"; what else could be used for this?
minetest.register_on_placenode(function (pos)
local below = pos + blockgame.vector.dirs.down
if minetest.get_node(below).name ~= modname .. ":funnel" then return end
attempt_input(below)
end)
-- NOTE: the documentation says `register_on_dignode` is "not recommended"; what else could be used for this?
minetest.register_on_dignode(function (pos)
local above = pos + blockgame.vector.dirs.up
if minetest.get_node(above).name ~= modname .. ":funnel" then return end
attempt_output(above)
end)

6
mods/bg_funnel/init.lua Normal file
View File

@ -0,0 +1,6 @@
-- this mod is disabled for now.
--[[
load_file("node")
load_file("recipe")
load_file("funnel")
]]--

3
mods/bg_funnel/mod.conf Normal file
View File

@ -0,0 +1,3 @@
name = bg_funnel
description = adds a funnel node to blockgame.
depends = bg_core, bg_api, bg_tree, bg_woodworking

27
mods/bg_funnel/node.lua Normal file
View File

@ -0,0 +1,27 @@
local modname = minetest.get_current_modname()
local api = load_file("api")
blockgame.register_node(modname .. ":funnel", {
description = "Funnel",
tiles = {
modname .. "_funnel_top.png",
modname .. "_funnel_top.png",
modname .. "_funnel.png",
},
groups = {
woody = 1,
},
on_place = function (...)
return api.place_funnel(...)
end,
on_dig = function (...)
return api.dig_funnel(...)
end,
preserve_metadata = function (pos, node, meta, drops)
-- TODO: store funnel contents inside dropped item.
end,
after_place_node = function (pos, placer, item_stack)
-- TODO: recreate funnel contents from placed item.
end,
})

16
mods/bg_funnel/recipe.lua Normal file
View File

@ -0,0 +1,16 @@
local modname = minetest.get_current_modname()
blockgame.crafting.register_pummel_recipe({
label = "pummel logs into funnel",
used_item = "woodworking:plank",
target_node = "bg_tree:log",
check = function (pos, used_node, target_node)
local below = pos + blockgame.vector.dirs.down
return minetest.get_node(below).name == "bg_tree:log"
end,
on_success = function (pos, used_node, target_node)
local below = pos + blockgame.vector.dirs.down
minetest.remove_node(pos)
minetest.set_node(below, {name = modname .. ":funnel"})
end,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 766 B

View File

@ -1,10 +1,10 @@
blockgame.register_abm({
nodenames = {"core:grass"},
nodenames = {"bg_terrain:grass"},
interval = 15,
chance = 4,
action = function (pos, node)
if blockgame.air_flows_through(pos + blockgame.vector.dirs.up) then return false end
minetest.set_node(pos, {name = "core:dirt"})
minetest.set_node(pos, {name = "bg_terrain:dirt"})
return true
end,
})

View File

@ -22,8 +22,8 @@ local function shuffle (tab)
end
blockgame.register_abm({
nodenames = {"core:grass"},
neighbors = {"core:dirt"},
nodenames = {"bg_terrain:grass"},
neighbors = {"bg_terrain:dirt"},
interval = 15,
chance = 8,
action = function (pos, node)
@ -48,9 +48,9 @@ blockgame.register_abm({
})
function attempt_spread (pos)
if minetest.get_node(pos).name ~= "core:dirt" then return false end
if minetest.get_node(pos).name ~= "bg_terrain:dirt" then return false end
if not blockgame.air_flows_through(pos + blockgame.vector.dirs.up) then return false end
minetest.set_node(pos, {name = "core:grass"})
minetest.set_node(pos, {name = "bg_terrain:grass"})
return true
end

View File

@ -1,3 +1,3 @@
name = grass
name = bg_grass
description = adds grass spreading and related mechanics to blockgame.
depends = core, api
depends = bg_core, bg_api

View File

@ -1,3 +1,3 @@
name = player
name = bg_player
description = blockgame player-related stuff.
depends = core, api
depends = bg_core, bg_api

View File

@ -1,2 +1,2 @@
load_file("node")
load_file("recipes")
load_file("recipe")

View File

@ -1,3 +1,3 @@
name = stoneworking
name = bg_stoneworking
description = blockgame stone related recipes and stuff.
depends = core, crafting, api
depends = bg_core, bg_crafting, bg_api

View File

@ -2,8 +2,8 @@ local modname = minetest.get_current_modname()
blockgame.crafting.register_pummel_recipe({
label = "pummel stone into tile",
used_item = "core:cobblestone",
target_node = "core:cobblestone",
used_item = "bg_terrain:cobblestone",
target_node = "bg_terrain:cobblestone",
check = function (pos, used_node, target_node)
local below_node = minetest.get_node(pos + blockgame.vector.dirs.down)
local stoney_value = minetest.get_item_group(below_node.name, "stoney")
@ -16,7 +16,7 @@ blockgame.crafting.register_pummel_recipe({
blockgame.crafting.register_pummel_recipe({
label = "pummel tile into bricks",
used_item = "core:cobblestone",
used_item = "bg_terrain:cobblestone",
target_node = modname .. ":tile",
check = function (pos, used_node, target_node)
local below_node = minetest.get_node(pos + blockgame.vector.dirs.down)

View File

Before

Width:  |  Height:  |  Size: 860 B

After

Width:  |  Height:  |  Size: 860 B

View File

Before

Width:  |  Height:  |  Size: 816 B

After

Width:  |  Height:  |  Size: 816 B

15
mods/bg_terrain/biome.lua Normal file
View File

@ -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,
})

4
mods/bg_terrain/init.lua Normal file
View File

@ -0,0 +1,4 @@
local modname = minetest.get_current_modname()
load_file("node")
load_file("biome")

3
mods/bg_terrain/mod.conf Normal file
View File

@ -0,0 +1,3 @@
name = bg_terrain
description = adds terrain stuff to blockgame.
depends = bg_api

36
mods/bg_terrain/node.lua Normal file
View File

@ -0,0 +1,36 @@
local modname = minetest.get_current_modname()
blockgame.register_node(modname .. ":stone", {
description = "Stone",
tiles = {
modname .. "_stone.png",
},
groups = {
cracky = 3,
stoney = 1,
},
drop = modname .. ":cobblestone",
})
blockgame.reg_simple_node("cobblestone", "Cobblestone", {
cracky = 3,
stoney = 1,
})
minetest.register_alias("mapgen_stone", modname .. ":stone")
minetest.register_alias("mapgen_water_source", "air")
blockgame.register_node(modname .. ":grass", {
description = "Grass",
tiles = {
modname .. "_grass.png",
},
groups = {
cracky = 3,
dirty = 1,
},
drop = modname .. ":dirt",
})
blockgame.reg_simple_node("dirt", "Dirt", {
cracky = 3,
dirty = 1,
})

Binary file not shown.

After

Width:  |  Height:  |  Size: 966 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 461 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 232 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 175 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 279 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

View File

@ -2,7 +2,7 @@ local modname = minetest.get_current_modname()
minetest.register_decoration({
deco_type = "simple",
place_on = {"core:grass"},
place_on = {"bg_terrain:grass"},
sidelen = 16,
-- fill_ratio = 0.025,
noise_params = {

View File

@ -60,7 +60,7 @@ end
blockgame.register_abm({
label = "sapling grow",
nodenames = {"tree:sapling"},
nodenames = {"bg_tree:sapling"},
neighbors = {"group:dirty", log_alive},
interval = 15,
chance = 4,

View File

@ -1,3 +1,3 @@
name = tree
name = bg_tree
description = blockgame tree mod.
depends = core, crafting, api
depends = bg_core, bg_crafting, bg_api

View File

@ -2,14 +2,14 @@ local modname = minetest.get_current_modname()
-- plant saplings
-- TODO: when recipes add support for groups, use `dirty` group here instead of specific nodes.
blockgame.crafting.register_stack_recipe("core:grass", modname .. ":nut", {name = modname .. ":sapling"})
blockgame.crafting.register_stack_recipe("core:dirt", modname .. ":nut", {name = modname .. ":sapling"})
blockgame.crafting.register_stack_recipe("bg_terrain:grass", modname .. ":nut", {name = modname .. ":sapling"})
blockgame.crafting.register_stack_recipe("bg_terrain:dirt", modname .. ":nut", {name = modname .. ":sapling"})
blockgame.crafting.register_pummel_recipe({
label = "pummel leaves into dirt",
used_item = modname .. ":leaves",
target_node = modname .. ":leaves",
on_success = function (pos, used_node, target_node)
minetest.set_node(pos, {name = "core:dirt"})
minetest.set_node(pos, {name = "bg_terrain:dirt"})
end,
})

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 857 B

After

Width:  |  Height:  |  Size: 857 B

View File

Before

Width:  |  Height:  |  Size: 5.7 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

View File

Before

Width:  |  Height:  |  Size: 887 B

After

Width:  |  Height:  |  Size: 887 B

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

Before

Width:  |  Height:  |  Size: 712 B

After

Width:  |  Height:  |  Size: 712 B

View File

Before

Width:  |  Height:  |  Size: 862 B

After

Width:  |  Height:  |  Size: 862 B

View File

Before

Width:  |  Height:  |  Size: 190 B

After

Width:  |  Height:  |  Size: 190 B

View File

@ -1,3 +1,3 @@
name = woodworking
name = bg_woodworking
description = blockgame wood related recipes and stuff.
depends = core, crafting, api, tree
depends = bg_core, bg_crafting, bg_api, bg_tree

View File

@ -2,8 +2,8 @@ local modname = minetest.get_current_modname()
blockgame.crafting.register_pummel_recipe({
label = "pummel log into plank",
used_item = "core:cobblestone",
target_node = "tree:log",
used_item = "bg_terrain:cobblestone",
target_node = "bg_tree:log",
check = function (pos, used_node, target_node)
for _, side in pairs(blockgame.vector.sides) do
local output_pos = pos + side

View File

Before

Width:  |  Height:  |  Size: 218 B

After

Width:  |  Height:  |  Size: 218 B