Compare commits

...

14 Commits

Author SHA1 Message Date
trans_soup 9585a7a4b3 add random ticks.
every server step, mapblocks near online players will have randomly
selected nodes within them receive a "random tick", the behaviour of
which is determined in node definitions.
2023-10-13 13:22:56 +02:00
trans_soup 6040e73f6c add debug utility to api. 2023-10-13 13:17:47 +02:00
trans_soup a2ab91c992 fix `math.random` usage.
fix usage of `math.random` in various places to provide both a minimum
and a maximum number, instead of just maximum.

also renamed some files very slightly.
2023-10-13 13:17:14 +02:00
trans_soup eef0283c66 fix incorrect naming.
change description of stone tiles from "Brick" to "Tile".
2023-10-13 10:02:35 +02:00
trans_soup 2e32ca82ba add `register_lbm` wrapper. 2023-10-13 09:55:09 +02:00
trans_soup 568e8059f9 refactor: more wrappers
create more wrappers for built-in functions and use them instead.
2023-10-13 09:31:55 +02:00
trans_soup ccd059aa29 generalize creating wrappers for built-ins.
create utility for creating wrapper functions for `minetest` methods.
2023-10-13 09:19:13 +02:00
trans_soup 1dd287a3c3 tweak hand reach range. 2023-10-13 09:00:05 +02:00
trans_soup 3eb6dc0f94 change miscellaneous player properties. 2023-10-13 08:59:51 +02:00
trans_soup 1aecdeb752 refactor: create general player interface.
create utility function for acting on player properties, and refactor
code for running and step height to make use of this.
2023-10-13 08:48:11 +02:00
trans_soup 732a8cb88a tiny refactor. 2023-10-13 08:30:25 +02:00
trans_soup 3c25192944 increase player step height. 2023-10-13 08:30:16 +02:00
trans_soup 48a51a77ce add running.
create mod for player-related stuff and move hand setup from core mod to
this new mod.

add feature where, while moving, players gradually speed up up to a
certain limit. their jump height is also increased while this happens.
2023-10-12 16:19:11 +02:00
trans_soup 8f956b2bfc create readme. 2023-10-12 11:38:09 +02:00
25 changed files with 270 additions and 26 deletions

21
README.md Normal file
View File

@ -0,0 +1,21 @@
# about
this is a game for the [minetest](https://www.minetest.net/) engine. the main inspirations is [nodecore](https://content.minetest.net/packages/Warr1024/nodecore/).
basically all current recipes are placeholders.
# how to install
download this entire directory and place it inside `~/.minetest/games/` (or wherever your minetest games are stored). then select this game (it's the one with a trans flag as icon) in the minetest menu.
# how to do stuff
two decorative stone variants, tiles and bricks, can be created by pummeling cobblestone and tiles respectively. you must be holding cobblestone while doing this, and the targetted node must be on top of a stone-type node.
pummeling is when you punch a node repeatedly. it's a mechanic taken directly from nodecore.
you can turn a log into planks by pummeling it with stone.
you can grow a tree by placing a dirty node (dirt or grass) on top of a nut. this will create a sapling, which will grow into something vaguely resembling a tree (including roots in the ground). note that there's currently no way to get nuts, so you'll have to use cheats for now if you want trees.
you can create dirt by pummeling leaves with leaves.

View File

@ -6,11 +6,14 @@ rawset(_G, "load_file", load_file)
local blockgame = {}
rawset(_G, "blockgame", blockgame)
load_file("utils_table")
load_file("utils_stringify")
load_file("utils_random")
load_file("utils_vector")
load_file("util_table")
load_file("util_stringify")
load_file("util_debug")
load_file("util_random")
load_file("util_vector")
load_file("utils_node")
load_file("util_node")
load_file("wrapper_abm")
load_file("wrappers")
load_file("random_tick")

View File

@ -0,0 +1,86 @@
--[[
outline:
do the following regularly:
1. create an empty list for mapblocks to process.
2. for every online player:
2.1. go through every mapblock near them, and add the mapblock to the list if it's not already added.
3. for every mapblock in the list:
3.1. load the mapblock.
- the "keep track of loaded mapblocks" part could be useful for other things too.
]]--
-- max distance from players, in mapblocks, within which mapblocks will be random-ticked.
local max_load_range = 4
-- max amount of mapblocks to get random-ticked each server step.
local max_ticked_block_count = 200
-- amount of random ticks to apply to each mapblock.
local random_tick_count = 4
local settings = minetest.settings
local view_range = settings:get("viewing_range")
local load_range = math.min(math.floor(view_range / 16), max_load_range)
local function random_tick (mapblock_pos)
for i=1, random_tick_count do
local x = mapblock_pos.x * 16 + math.random(0, 15)
local y = mapblock_pos.y * 16 + math.random(0, 15)
local z = mapblock_pos.z * 16 + math.random(0, 15)
local pos = vector.new(x, y, z)
local node_def = minetest.registered_nodes[minetest.get_node(pos).name]
if type(node_def.on_random_tick) == "function" then
node_def.on_random_tick(pos, node, i)
end
end
end
blockgame.register_globalstep(function ()
-- find loaded mapblocks
local mapblocks = {}
local visited_blocks = {}
for _, player in pairs(minetest.get_connected_players()) do
local node_pos = player:get_pos()
local mapblock_pos = {}
for key, value in pairs(node_pos) do
mapblock_pos[key] = math.floor(value / 16)
end
for x = mapblock_pos.x - load_range, mapblock_pos.x + load_range do
for y = mapblock_pos.y - load_range, mapblock_pos.y + load_range do
for z = mapblock_pos.z - load_range, mapblock_pos.z + load_range do
local hash = x .. "," .. y .. "," .. z
if not visited_blocks[hash] then
visited_blocks[hash] = true
table.insert(mapblocks, vector.new(x, y, z))
end
end
end
end
end
mapblocks = blockgame.shuffle(mapblocks)
-- tick mapblocks
local ticked_mapblock_count = 0
repeat
ticked_mapblock_count = ticked_mapblock_count + 1
local index = math.random(1, #mapblocks)
local mapblock = mapblocks[index]
table.remove(mapblocks, index)
if mapblock then
random_tick(mapblock)
end
until ticked_mapblock_count >= max_ticked_block_count or #mapblocks == 0
end)

View File

@ -0,0 +1,3 @@
function blockgame.debug (val)
minetest.debug(blockgame.stringify(val))
end

View File

@ -1,6 +1,6 @@
function blockgame.reg_simple_node (name, desc, groups)
local my_modname = minetest.get_current_modname()
return minetest.register_node(my_modname .. ":" .. name, {
return blockgame.register_node(my_modname .. ":" .. name, {
description = desc,
tiles = {
my_modname .. "_" .. name .. ".png",

View File

@ -1,10 +1,10 @@
local modname = minetest.get_current_modname()
function blockgame.chance (chance)
return math.random(chance) == 1
return math.random(1, chance) == 1
end
function blockgame.random_element (tab)
local keys = blockgame.get_keys(tab)
return tab[keys[math.random(#keys)]]
return tab[keys[math.random(1, #keys)]]
end

View File

@ -15,3 +15,14 @@ function blockgame.shallow_copy_table (tab)
end
return result
end
function blockgame.shuffle (tab)
local keys = blockgame.get_keys(tab)
local result = {}
while #keys > 0 do
local index = math.random(1, #keys)
local key = table.remove(keys, index)
table.insert(result, tab[key])
end
return result
end

View File

@ -1,3 +0,0 @@
function blockgame.register_abm (...)
return minetest.register_abm(...)
end

30
mods/bg_api/wrappers.lua Normal file
View File

@ -0,0 +1,30 @@
local function create_plain_wrapper (function_name)
local wrapper = function (...)
--[[
local args = {...}
-- labels will be used later, probably.
local label = #args > 1 and args[1] or "unlabeled"
local callback = #args > 1 and args[2] or args[1]
minetest[function_name](callback)
]]--
minetest[function_name](...)
end
blockgame[function_name] = wrapper
end
for name in pairs({
register_abm = true,
register_lbm = true,
register_on_joinplayer = true,
register_node = true,
register_item = true,
register_on_placenode = true,
register_on_dignode = true,
register_on_punchnode = true,
register_globalstep = true,
}) do
create_plain_wrapper(name)
end

View File

@ -2,4 +2,3 @@ local modname = minetest.get_current_modname()
load_file("node")
load_file("biome")
load_file("hand")

View File

@ -1,6 +1,6 @@
local modname = minetest.get_current_modname()
minetest.register_node(modname .. ":stone", {
blockgame.register_node(modname .. ":stone", {
description = "Stone",
tiles = {
modname .. "_stone.png",
@ -19,7 +19,7 @@ blockgame.reg_simple_node("cobblestone", "Cobblestone", {
minetest.register_alias("mapgen_stone", modname .. ":stone")
minetest.register_alias("mapgen_water_source", "air")
minetest.register_node(modname .. ":grass", {
blockgame.register_node(modname .. ":grass", {
description = "Grass",
tiles = {
modname .. "_grass.png",

View File

@ -86,12 +86,12 @@ end
local pummeling = {}
-- NOTE: might wanna change this to somehow store pummels per-node instead of per-player?
minetest.register_on_dignode(function (_, _, digger)
blockgame.register_on_dignode(function (_, _, digger)
if not (digger and digger:is_player()) then return end
pummeling[digger:get_player_name()] = nil
end)
minetest.register_on_punchnode(function (pos, node, puncher, pointed)
blockgame.register_on_punchnode(function (pos, node, puncher, pointed)
if (not puncher:is_player()) or puncher:get_player_control().sneak then return end
local player_name = puncher:get_player_name()
-- if not minetest.interact(player_name) then return end

View File

@ -2,6 +2,6 @@ local modname = minetest.get_current_modname()
load_file("api")
minetest.register_on_placenode(function (...)
blockgame.register_on_placenode(function (...)
return blockgame.crafting.handle_placement(...)
end)

View File

@ -2,7 +2,7 @@ local function create_group_cap (max_level)
return {maxlevel = max_level, times={[1] = 1, [2] = 2, [3] = 3}}
end
minetest.register_item(":", {
blockgame.register_item(":", {
["type"] = "none",
inventory_image = "[combine:1x1",
tool_capabilities = {
@ -16,5 +16,5 @@ minetest.register_item(":", {
},
},
node_placement_prediction = "",
range = 5.0,
range = 5.8,
})

5
mods/bg_player/init.lua Normal file
View File

@ -0,0 +1,5 @@
load_file("hand")
load_file("run")
load_file("step_height")
load_file("misc")

9
mods/bg_player/misc.lua Normal file
View File

@ -0,0 +1,9 @@
local utils = load_file("util_misc")
blockgame.register_on_joinplayer(function(player)
utils.handle_player(player, function (_, data)
data.properties.pointable = false
data.properties.zoom_fov = 15
data.properties.eye_height = 1.7
end)
end)

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

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

48
mods/bg_player/run.lua Normal file
View File

@ -0,0 +1,48 @@
local utils = load_file("util_misc")
local walk_speed = 1
local walk_time = 2
local speedup_time = 6
local run_factor = 3
local slowdown_factor = 8
local jump_height = 1
local jump_factor = 1.5
local speed_data = {}
local function handle_speed (player, delta_time)
utils.handle_player(player, function (player, p_data)
speed_data[player] = speed_data[player] or {}
local data = speed_data[player]
data.duration = (data.duration or 0) + delta_time
local control = p_data.control
local moving = control.up or control.down or control.left or control.right
if not moving then
data.duration = data.duration - delta_time * (slowdown_factor + 1)
end
if data.duration < 0 then data.duration = 0 end
if data.duration > walk_time + speedup_time then data.duration = walk_time + speedup_time end
if data.duration < walk_time then
p_data.physics.speed = walk_speed
p_data.physics.jump = jump_height
else
local run_time = data.duration - walk_time
local t = run_time / speedup_time
local factor = (run_factor - 1) * t + 1
if factor > run_factor then factor = run_factor end
p_data.physics.speed = walk_speed * factor
p_data.physics.jump = jump_height + (jump_height * jump_factor - 1) * t
end
end)
end
blockgame.register_globalstep(function(delta_time)
for _, player in pairs(minetest.get_connected_players()) do
handle_speed(player, delta_time)
end
end)

View File

@ -0,0 +1,9 @@
local utils = load_file("util_misc")
blockgame.register_globalstep(function(delta_time)
for _, player in pairs(minetest.get_connected_players()) do
utils.handle_player(player, function (_, data)
data.properties.stepheight = data.control.sneak and 0.01 or 1.05
end)
end
end)

View File

@ -0,0 +1,20 @@
local function handle_player (player, fn)
local data = {}
data.control = player:get_player_control()
data.properties = player:get_properties()
data.physics = player:get_physics_override()
local result = fn(player, data)
player:set_properties(data.properties)
player:set_physics_override(data.physics)
return result
end
return {
handle_player = handle_player,
}

View File

@ -2,6 +2,6 @@ blockgame.reg_simple_node("bricks", "Bricks", {
stoney = 1,
})
blockgame.reg_simple_node("tile", "Bricks", {
blockgame.reg_simple_node("tile", "Tile", {
stoney = 1,
})

View File

@ -58,7 +58,7 @@ local function spread_roots_from (source)
return false
end
minetest.register_abm({
blockgame.register_abm({
label = "sapling grow",
nodenames = {"tree:sapling"},
neighbors = {"group:dirty", log_alive},

View File

@ -1,6 +1,6 @@
local modname = minetest.get_current_modname()
minetest.register_node(modname .. ":log", {
blockgame.register_node(modname .. ":log", {
description = "Log",
tiles = {
modname .. "_log_top.png",
@ -11,7 +11,7 @@ minetest.register_node(modname .. ":log", {
woody = 1,
},
})
minetest.register_node(modname .. ":log_alive", {
blockgame.register_node(modname .. ":log_alive", {
description = "Growing Log",
tiles = {
modname .. "_log_top_alive.png",
@ -29,7 +29,7 @@ blockgame.reg_simple_node("sapling", "Sapling", {
planty = 1,
})
minetest.register_node(modname .. ":leaves", {
blockgame.register_node(modname .. ":leaves", {
description = "Leaves",
drawtype = "glasslike",
tiles = {
@ -41,7 +41,7 @@ minetest.register_node(modname .. ":leaves", {
planty = 1,
},
})
minetest.register_node(modname .. ":leaves_alive", {
blockgame.register_node(modname .. ":leaves_alive", {
description = "Growing Leaves",
drawtype = "glasslike",
tiles = {