This commit is contained in:
Andrew Miner
2026-10-30 21:16:18 -06:00
parent cac0557036
commit a1ee82308c
18 changed files with 381 additions and 155 deletions
-21
View File
@@ -1,21 +0,0 @@
-- Private -----------------------------------------------------------------------------------------
local private = {}
function private.is_key(name, value, table_name, table_value)
if table_value[value] ~= nil then return end
error(name.." should be a key in "..table_name..", but "..value.." isn't present")
end
function private.is_type(name, value, type_name)
if type(value) == type_name then return end
error(name.." should be a "..type_name..", but was a "..type(value))
end
-- Export ------------------------------------------------------------------------------------------
return {
is_key = private.is_key,
is_type = private.is_type
}
+1 -1
View File
@@ -3,7 +3,7 @@
local core = _G.core local core = _G.core
-- Registrations ----------------------------------------------------------------------------------- -- Script ------------------------------------------------------------------------------------------
core.register_biome({ core.register_biome({
name = "ocean_floor", name = "ocean_floor",
+9 -2
View File
@@ -1,9 +1,16 @@
-- Imports ----------------------------------------------------------------------------------------- -- Imports -----------------------------------------------------------------------------------------
local jvmi = _G.jvmi
local core = _G.core local core = _G.core
local mod = jvmi.register_mod("jvmi_biomes")
-- Registrations -----------------------------------------------------------------------------------
-- Script ------------------------------------------------------------------------------------------
if jvmi.env == "main" then
core.clear_registered_biomes() core.clear_registered_biomes()
dofile(core.get_modpath("jvmi_biomes").."/definitions.lua") mod.domodfile("definitions.lua")
elseif jvmi.env == "mapgen" then
mod.domodfile("mapgen.lua")
end
@@ -1,31 +1,35 @@
-- Imports ----------------------------------------------------------------------------------------- -- Imports -----------------------------------------------------------------------------------------
local jvmi = _G.jvmi
local core = _G.core local core = _G.core
local path = core.get_game_info().path local mod = jvmi.register_mod("jvmi_biomes")
local C = dofile(path.."/common/constants.lua")
local Region = dofile(path.."/common/region.lua")
-- Private -----------------------------------------------------------------------------------------
local private = {} local private = {}
local C = jvmi.C
local Region = jvmi.Region
-- Public ------------------------------------------------------------------------------------------
--[[ --[[
Apply biomes to the given region. Apply biomes to the given region.
This function will both update the `Region.META..BIOME` table so that each x,z column has an This function will both update the `Region.META.BIOME` table so that each x,z column has an
assigned biome, but it will also update the data within the region to have that biome fully assigned biome, but it will also update the data within the region to have that biome fully
applied from decorations to fill material. applied from decorations to fill material.
Args: Args:
region:Region - the region currently being generated region:Region - the region currently being generated
]]-- ]]--
function private.apply_to(region) function mod.apply_to(region)
private.assign_biomes(region) private.assign_biomes(region)
private.fill_surface(region) private.fill_surface(region)
end end
-- Private -----------------------------------------------------------------------------------------
--[[ --[[
Assigns a specific biome to each position in the region. Assigns a specific biome to each position in the region.
@@ -77,10 +81,3 @@ function private.fill_surface(region)
end end
end) end)
end end
-- Export ------------------------------------------------------------------------------------------
return {
apply_to = private.apply_to
}
+70
View File
@@ -0,0 +1,70 @@
-- Private -----------------------------------------------------------------------------------------
local private = {
enabled = false
}
--[[
Disable all checks.
By default, checks start out disabled already. This function should be used to turn off checks
when they are no longer needed following a call to `enable`.
]]--
function private.disable()
private.enabled = false
end
--[[
Enable all checks.
By default, all checks are *disabled* for better performance. By calling this function, one can
turn on checks for a given patch of code.
]]--
function private.enable()
private.enabled = true
end
--[[
Assert that a given value is a key in a certain table.
Args:
name:string - the name used for the value in error messages
value:any - the value being tested
table_name:string - the name used for the table in error messages
table_value:table - the table which must contain the indicated value
Errors:
if the given `value` does not refer to a non-`nil` value in `table_value`
]]--
function private.is_key(name, value, table_name, table_value)
if not private.enabled then return end
if table_value[value] ~= nil then return end
error(name.." should be a key in "..table_name..", but "..value.." isn't present")
end
--[[
Assert that a given value is a certain type.
Args:
name:string - the name used for the value in error messages
value:any - the value being tested
type_name:string - the string which *should* be produced by `type(value)`
Errors:
if the `type(value)` does not produce `type_name`
]]--
function private.is_type(name, value, type_name)
if not private.enabled then return end
if type(value) == type_name then return end
error(name.." should be a "..type_name..", but was a "..type(value))
end
-- Export ------------------------------------------------------------------------------------------
_G.jvmi.check = {
disable = private.disable,
enable = private.enable,
is_key = private.is_key,
is_type = private.is_type
}
@@ -3,7 +3,7 @@
local C = {} local C = {}
-- Node Definition Constants ----------------------------------------------------------------------- -- Node Definition Constants ---------------------------------------------------
C.ANIMATION_TYPE = { C.ANIMATION_TYPE = {
VERTICAL_FRAMES = "vertical_frames", VERTICAL_FRAMES = "vertical_frames",
@@ -51,7 +51,7 @@ C.WAVING = {
} }
-- Mapgen Constants -------------------------------------------------------------------------------- -- Mapgen Constants ------------------------------------------------------------
--[[ Key altitudes which define the vertical regions of the generated map. ]]-- --[[ Key altitudes which define the vertical regions of the generated map. ]]--
C.ALTITUDE = { C.ALTITUDE = {
@@ -66,7 +66,6 @@ C.ALTITUDE = {
ABYSS = -64, ABYSS = -64,
BEDROCK = -128, BEDROCK = -128,
} }
local A = C.ALTITUDE local A = C.ALTITUDE
--[[ The amount of overlap (as a perentage of total weight) between adjacent terrain types. ]]-- --[[ The amount of overlap (as a perentage of total weight) between adjacent terrain types. ]]--
@@ -87,6 +86,7 @@ C.TERRAIN_TYPE_NOISE_PARAMS = {
spread = { x = 512, y = 512, z = 0 }, spread = { x = 512, y = 512, z = 0 },
} }
--[[ --[[
A table defining the terrain types used in generating the base terrain. A table defining the terrain types used in generating the base terrain.
@@ -113,4 +113,4 @@ C.TERRAIN_TYPES = {
-- Export ------------------------------------------------------------------------------------------ -- Export ------------------------------------------------------------------------------------------
return C _G.jvmi.C = C
+1 -1
View File
@@ -65,4 +65,4 @@ end
-- Export ----------------------------------------------------------------------------------------- -- Export -----------------------------------------------------------------------------------------
return private.dump _G.jvmi.dump = private.dump
+34 -1
View File
@@ -1 +1,34 @@
-- Do nothing. _G.jvmi = _G.jvmi or { mods = {} }
local jvmi = _G.jvmi
local core = _G.core
local base_dir
if not core then
jvmi.env = "test"
jvmi.base_dir = "../.."
jvmi.in_game = false
base_dir = "."
else
base_dir = core.get_modpath("jvmi_first")
jvmi.base_dir = core.get_game_info().path
jvmi.in_game = true
if core.register_mapgen_script then
jvmi.env = "main"
core.register_mapgen_script(base_dir.."/init.lua")
else
jvmi.env = "mapgen"
end
end
dofile(base_dir.."/check.lua")
dofile(base_dir.."/constants.lua")
dofile(base_dir.."/dump.lua")
dofile(base_dir.."/require.lua")
dofile(base_dir.."/table.lua")
-- requires 'check'
dofile(base_dir.."/region.lua")
jvmi.register_mod("jvmi_first")
@@ -1,13 +1,13 @@
-- Import ------------------------------------------------------------------------------------------ -- Import ------------------------------------------------------------------------------------------
local core = _G.core local jvmi = _G.jvmi
local math = _G.math local math = _G.math
local VoxelArea = _G.VoxelArea local VoxelArea = _G.VoxelArea
local check = dofile(core.get_game_info().path.."/common/check.lua") local check = jvmi.check
-- Region Class ------------------------------------------------------------------------------------ -- Private -----------------------------------------------------------------------------------------
local Region = { local Region = {
--[[ Defines the names of the known metadata tables. ]]-- --[[ Defines the names of the known metadata tables. ]]--
@@ -310,6 +310,6 @@ function Region:save_voxels()
end end
-- Export ------------------------------------------------------------------------------------------ -- Public ------------------------------------------------------------------------------------------
return Region jvmi.Region = Region
+119
View File
@@ -0,0 +1,119 @@
-- Imports -----------------------------------------------------------------------------------------
local core = _G.core
local jvmi = _G.jvmi
local string = _G.string
-- Private -----------------------------------------------------------------------------------------
local private = {}
--[[
Extract the short name from a given mod name.
Args:
name:string - the full name of the mod
Returns:
the short name of the mod (i.e., without the "jvmi_" prefix)
Errors:
if the name doesn't have the "jvmi_" prefix
]]--
function private.extract_short_name(name)
local prefix_index = string.find(name, "jvmi_", 1, true)
if prefix_index ~= 1 then
error(name.."does not have a 'jvmi_' prefix")
end
return string.sub(name, 6)
end
--[[
Load a script which is local to a specific mod.
Args:
mod:table - the mod's global table (which must still include the `base_dir` key)
]]--
function private.domodfile(mod, path)
dofile(mod.base_dir.."/"..path)
end
-- Global ------------------------------------------------------------------------------------------
--[[
Register a JVMI mod with the global table.
This will create a new table for the mod's use and populate it with a few useful items. The
table will be returned, and the mod can then use it to store its own global state. The following
keys will be pre-populated for each mod:
base_dir:string - the location on disk where the mod lives
domodfile:function(path:string) - run `dofile` on a script in the mod's base dir
name:string - the full name of the mod, as given
short_name:string - the name of the mod without the "jvmi_" prefix
The mod's table is also added to `jvmi.mods[mod.short_name]`, so that it may be accessed as
needed by other mods.
Args:
name:string - a string giving the full name of the mod "jvmi_..."
Returns:
a table the mod can use to store its own data
]]--
function jvmi.register_mod(name)
local short_name = private.extract_short_name(name)
local mod = jvmi.mods[short_name]
if mod then return mod end
mod = {
base_dir = jvmi.base_dir.."/mods/"..name,
name = name,
short_name = short_name,
}
mod.domodfile = function(path) private.domodfile(mod, path) end
if jvmi.in_game then
mod.S = core.get_translator(name)
else
mod.S = function(text) return text end
end
jvmi.mods[short_name] = mod
return mod
end
--[[
Obtain the global table associated with the named mod.
This function will return the existing table if the mod is already registered, or attempt to
load the mod and return the newly-registered table if not. If this function is called in the
"main" env, it will raise an error if the mod isn't already registered, since mods should use
the `depends` entry in their `mod.conf` file to ensure their dependencies are loaded instead of
using this function.
Args:
name:string - the full name of the mod to load
]]--
function jvmi.require_mod(name)
local short_name = private.extract_short_name(name)
local mod = jvmi.mods[short_name]
if mod then return mod end
if jvmi.env == "main" then
error("Update mod.conf:depends to include "..name)
end
local init_path = jvmi.base_dir.."/mods/"..name.."/init.lua"
dofile(init_path)
mod = jvmi.mods[short_name]
if not mod then
error("Loading "..init_path.." didn't register "..name)
end
return mod
end
@@ -1,8 +1,3 @@
-- Import ------------------------------------------------------------------------------------------
local table = _G.table
-- Private ----------------------------------------------------------------------------------------- -- Private -----------------------------------------------------------------------------------------
local private = {} local private = {}
@@ -26,7 +21,8 @@ end
Performs a deep clone of a given table. Performs a deep clone of a given table.
This function only clones regular keys, and makes no effort to preserve the metatables of the This function only clones regular keys, and makes no effort to preserve the metatables of the
resulting tables. It also does not attempt to handle cycles among the given tables. resulting tables. It also does not attempt to handle cycles among the given tables. If provided
with a non-table value, then it simply returns the same object given without cloning it.
Args: Args:
source:table - the table to be cloned source:table - the table to be cloned
@@ -93,4 +89,4 @@ end
-- Export ------------------------------------------------------------------------------------------ -- Export ------------------------------------------------------------------------------------------
return private.merge({}, table, private) _G.jvmi.table = private.merge({}, _G.table, private)
+6 -7
View File
@@ -1,14 +1,13 @@
-- Imports & Exports ------------------------------------------------------------------------------- -- Imports -----------------------------------------------------------------------------------------
local core = _G.core local core = _G.core
local jvmi = _G.jvmi
local mod = jvmi.register_mod("jvmi_mapgen")
-- Registrations -----------------------------------------------------------------------------------
local path = core.get_modpath("jvmi_mapgen")
core.register_mapgen_script(path.."/mapenv.lua")
-- Script ------------------------------------------------------------------------------------------ -- Script ------------------------------------------------------------------------------------------
core.log("info", "jvmi_mapgen loaded") if jvmi.env == "main" then
core.register_mapgen_script(mod.base_dir.."/mapgen.lua")
end
@@ -1,16 +1,14 @@
-- Imports & Exports ------------------------------------------------------------------------------- -- Imports & Exports -------------------------------------------------------------------------------
local core = _G.core local core = _G.core
local jvmi = _G.jvmi
local vector = _G.vector local vector = _G.vector
local path = core.get_game_info().path local biomes = jvmi.require_mod("jvmi_biomes")
local C = dofile(path.."/common/constants.lua") local C = jvmi.C
local Region = dofile(path.."/common/region.lua") local check = jvmi.check
local table = dofile(path.."/common/table.lua") local Region = jvmi.Region
local table = jvmi.table
local biomes = dofile(core.get_modpath("jvmi_biomes").."/mapenv.lua")
local check = dofile(core.get_game_info().path.."/common/check.lua")
local dump = dofile(core.get_game_info().path.."/common/dump.lua")
-- Constants --------------------------------------------------------------------------------------- -- Constants ---------------------------------------------------------------------------------------
@@ -19,7 +17,8 @@ local A = C.ALTITUDE
local TERRAIN_TYPES = nil local TERRAIN_TYPES = nil
local TERRAIN_TYPE_NOISE = nil local TERRAIN_TYPE_NOISE = nil
-- Common Node Content Ids -----------------------------------------------------
-- Content Ids -----------------------------------------------------
local AIR_ID = core.CONTENT_AIR local AIR_ID = core.CONTENT_AIR
local BEDROCK_ID = core.get_content_id("jvmi_nodes:bedrock") local BEDROCK_ID = core.get_content_id("jvmi_nodes:bedrock")
@@ -193,6 +192,31 @@ function private.on_load()
TERRAIN_TYPE_NOISE = core.get_value_noise(C.TERRAIN_TYPE_NOISE_PARAMS) TERRAIN_TYPE_NOISE = core.get_value_noise(C.TERRAIN_TYPE_NOISE_PARAMS)
end end
--[[
Starting from scratch, populate all the blocks in the indicated region.
Args:
voxels:VoxelManip - a voxel manipulator containing the current state of the region
fill_min:vector - the lowest corner of the region to fill
fill_max:vector - the highest corner of the region to fill
]]--
function private.populate_region(voxels, fill_min, fill_max)
local region = private.region
region:read_voxels(voxels, fill_min, fill_max)
private.assign_terrain_meta(region)
private.assign_altitudes(region)
private.fill_terrain(region)
private.fill_bedrock(region)
private.fill_ocean(region)
biomes.apply_to(region)
region:save_voxels()
end
--[[ --[[
Clone the `C.TERRAIN_TYPES` table and add pre-computed values to it. Clone the `C.TERRAIN_TYPES` table and add pre-computed values to it.
@@ -227,26 +251,7 @@ function private.prepare_terrain_table()
end end
-- Registrations -----------------------------------------------------------------------------------
core.register_on_generated(function(voxels, fill_min, fill_max)
local region = private.region
region:read_voxels(voxels, fill_min, fill_max)
private.assign_terrain_meta(region)
private.assign_altitudes(region)
private.fill_terrain(region)
private.fill_bedrock(region)
private.fill_ocean(region)
biomes.apply_to(region)
region:save_voxels()
end)
-- Script ------------------------------------------------------------------------------------------ -- Script ------------------------------------------------------------------------------------------
private.on_load() private.on_load()
core.register_on_generated(private.populate_region)
+2 -4
View File
@@ -1,11 +1,9 @@
-- Imports & Exports ------------------------------------------------------------------------------- -- Imports & Exports -------------------------------------------------------------------------------
local core = _G.core local core = _G.core
local jvmi = _G.jvmi
local S = jvmi.mods.nodes.S
-- Constants ---------------------------------------------------------------------------------------
local S = core.get_translator("jvmi_nodes")
-- Registrations ----------------------------------------------------------------------------------- -- Registrations -----------------------------------------------------------------------------------
+6 -5
View File
@@ -1,11 +1,12 @@
-- Imports & Exports ------------------------------------------------------------------------------- -- Imports & Exports -------------------------------------------------------------------------------
local core = _G.core local jvmi = _G.jvmi
local mod = jvmi.register_mod("jvmi_nodes")
-- Script ------------------------------------------------------------------------------------------ -- Script ------------------------------------------------------------------------------------------
local path = core.get_modpath("jvmi_nodes") mod.domodfile("earthy.lua")
dofile(path.."/earthy.lua") mod.domodfile("liquid.lua")
dofile(path.."/liquid.lua") mod.domodfile("stony.lua")
dofile(path.."/stony.lua")
+6 -8
View File
@@ -1,15 +1,13 @@
-- Imports & Exports ------------------------------------------------------------------------------- -- Imports & Exports -------------------------------------------------------------------------------
local core = _G["core"] local core = _G.core
local jvmi = _G.jvmi
local C = jvmi.C
local S = jvmi.mods.nodes.S
-- Constants --------------------------------------------------------------------------------------- -- Script ------------------------------------------------------------------------------------------
local C = dofile(core.get_game_info().path.."/common/constants.lua")
local S = core.get_translator("jvmi_nodes")
-- Registrations -----------------------------------------------------------------------------------
core.register_node("jvmi_nodes:water_flowing", { core.register_node("jvmi_nodes:water_flowing", {
description = S("Flowing Water"), description = S("Flowing Water"),
+5 -7
View File
@@ -1,14 +1,12 @@
-- Imports & Exports ------------------------------------------------------------------------------- -- Imports & Exports -------------------------------------------------------------------------------
local core = _G["core"] local core = _G.core
local jvmi = _G.jvmi
local S = jvmi.mods.nodes.S
-- Constants --------------------------------------------------------------------------------------- -- Script ------------------------------------------------------------------------------------------
local S = core.get_translator("jvmi_nodes")
-- Registrations -----------------------------------------------------------------------------------
core.register_node("jvmi_nodes:bedrock", { core.register_node("jvmi_nodes:bedrock", {
description = S("Bedrock"), description = S("Bedrock"),
+62 -36
View File
@@ -1,38 +1,67 @@
-- Imports & Exports ------------------------------------------------------------------------------- -- Imports & Exports -------------------------------------------------------------------------------
local core = _G.core local core = _G.core
local jvmi = _G.jvmi
jvmi.register_mod("jvmi_player")
local private = {}
-- Constants --------------------------------------------------------------------------------------- -- Constants ---------------------------------------------------------------------------------------
local C = dofile(core.get_game_info().path.."/common/constants.lua") local C = jvmi.C
--[[ The multiplier on the player's speed when in "fast" mode. ]]--
local FAST_SPEED_MULTIPLIER = 10
--[[ The maximum number of times to put off setting the player's start position. ]]--
local MAX_PLAYER_SPAWN_DELAYS = 10
--[[ The default privs to be granted to a new player in a singleplayer game. ]]--
local SINGLEPLAYER_PRIVS = { local SINGLEPLAYER_PRIVS = {
debug = true, debug = true, fast = true, fly = true, give = true, interact = true, noclip = true,
fast = true, privs = true, server = true, settime = true, teleport = true,
fly = true,
give = true,
interact = true,
noclip = true,
privs = true,
server = true,
settime = true,
teleport = true,
} }
-- Private ----------------------------------------------------------------------------------------- -- Private -----------------------------------------------------------------------------------------
local private = {} --[[ Configure the player's hand with default settings for this game. ]]--
function private.configure_hand()
local hand_def = core.registered_items[""]
core.debug("hand: "..jvmi.dump(hand_def))
end
--[[
Set up privs for a new player.
Args:
player:ObjectRef - the player to be affected
]]--
function private.configure_privs(player)
core.set_player_privs(player:get_player_name(), SINGLEPLAYER_PRIVS)
end
--[[
Update the player physics for this particular game.
Args:
player:ObjectRef - the player to be affected
]]--
function private.configure_physics(player)
local physics = player:get_physics_override()
physics.speed_fast = FAST_SPEED_MULTIPLIER
player:set_physics_override(physics)
end
--[[ --[[
Find a player with a given name. Find a player with a given name.
Args: Args:
- player_name:string - the name of the desired player player_name:string - the name of the desired player
Returns: Returns:
- an ObjectRef for the requested player if they're logged on, or nil an ObjectRef for the requested player, or `nil` if no such player is logged on
]]-- ]]--
function private.find_player(name) function private.find_player(name)
for _, player in ipairs(core.get_connected_players()) do for _, player in ipairs(core.get_connected_players()) do
@@ -44,6 +73,21 @@ function private.find_player(name)
return nil return nil
end end
--[[
Configure the player's object when they join the server.
Args:
player:ObjectRef - the player who just joined
last_login:timestamp - when the player last logged in (or `nil` if they're brand new)
]]--
function private.on_player_joined(player, last_login)
if last_login then return end
private.configure_privs(player)
private.configure_physics(player)
private.set_starting_pos(player:get_player_name())
end
--[[ --[[
Move the indicated player into a safe spawn location. Move the indicated player into a safe spawn location.
@@ -63,7 +107,7 @@ end
]]-- ]]--
function private.set_starting_pos(player_name, delays) function private.set_starting_pos(player_name, delays)
delays = delays or 0 delays = delays or 0
if delays > 10 then if delays > MAX_PLAYER_SPAWN_DELAYS then
core.log("warning", "Too many delays in finding a safe spawning location: giving up") core.log("warning", "Too many delays in finding a safe spawning location: giving up")
return return
end end
@@ -107,26 +151,8 @@ function private.set_starting_pos(player_name, delays)
end end
end end
--[[
Set up privledges and settings for a new player.
Args: -- Script ------------------------------------------------------------------------------------------
- player:ObjectRef - the current player
]]--
function private.setup_player(player)
core.set_player_privs(player:get_player_name(), SINGLEPLAYER_PRIVS)
local physics = player:get_physics_override() private.configure_hand()
physics.speed_fast = 10 core.register_on_joinplayer(private.on_player_joined)
player:set_physics_override(physics)
end
-- Registrations -----------------------------------------------------------------------------------
core.register_on_joinplayer(function(player, last_login)
if last_login then return end
private.setup_player(player)
private.set_starting_pos(player:get_player_name())
end)