Add initial version

This commit is contained in:
Andrew Miner
2026-10-18 19:13:29 -06:00
parent 7fee583710
commit bfd2217cd5
29 changed files with 550 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
.DS_Store
+1
View File
@@ -0,0 +1 @@
unused_args = false
+7
View File
@@ -0,0 +1,7 @@
title = Tungston's Game
author = TungstonMiner
description = Realism-oriented survival simulation
first_mod = tmg_first
last_mode tmg_last
allowed_mapgens = singlenode
default_mapgen = singlenode
View File
+55
View File
@@ -0,0 +1,55 @@
-- Constants ---------------------------------------------------------------------------------------
tmg_constants = { -- luacheck: globals tmg_constants
ALTITUDE = {
SKY = 256,
MOUNTAIN = 128,
MOOR = 64,
HILL = 32,
PLAIN = 16,
SURFACE = 0,
SHALLOW = -16,
DEEP = -32,
ABYSS = -64,
BEDROCK = -128,
},
ANIMATION_TYPE = {
VERTICAL_FRAMES = "vertical_frames",
SHEET_2D = "sheet_2d",
},
DRAW_TYPE = {
ALL_FACES_OPTIONAL = "allfaces_optional",
FLOWING_LIQUID = "flowingliquid",
LIQUID = "liquid",
MESH = "mesh",
NODE_BOX = "nodebox",
NORMAL = "normal",
PLANT_LIKE = "plantlike",
},
LIQUID_TYPE = {
NONE = "none",
SOURCE = "source",
FLOWING = "flowing",
},
TEXTURE_ALPHA = {
OPAQUE = "opaque",
CLIP = "clip",
BLEND = "blend",
},
VISCOSITY = {
XXX_FAST = 0,
XX_FAST = 1,
X_FAST = 2,
FAST = 3,
SLOW = 4,
X_SLOW = 5,
XX_SLOW = 6,
XXX_SLOW = 7,
},
WAVING = {
NO = 0,
PLANT_LIKE = 1,
LEAF_LIKE = 2,
LIQUID_LIKE = 3,
},
}
+6
View File
@@ -0,0 +1,6 @@
-- Imports & Exports -------------------------------------------------------------------------------
local core = _G["core"]
local path = core.get_modpath("tmg_constants")
dofile(path.."/constants.lua")
+4
View File
@@ -0,0 +1,4 @@
name = tmg_constants
title = Tungston's Game / Constants
description = defined shared values across mods
author = tungstonminer
+23
View File
@@ -0,0 +1,23 @@
-- Imports & Exports -------------------------------------------------------------------------------
local core = _G["core"]
tmg_first = {} -- luacheck: globals tmg_first
-- Private Functions -------------------------------------------------------------------------------
local private = {}
function private.register_mapgen_aliases()
core.register_alias("mapgen_stone", "tmg_nodes:stone")
core.register_alias("mapgen_water_source", "tmg_nodes:water_source")
core.register_alias("mapgen_river_water_source", "tmg_nodes:water_source")
end
-- Script ------------------------------------------------------------------------------------------
core.debug("Tungston's Game initializing")
private.register_mapgen_aliases()
+4
View File
@@ -0,0 +1,4 @@
name = tmg_first
title = Tungston's Game / First
description = set up game basics
author = tungstonminer
+136
View File
@@ -0,0 +1,136 @@
-- Imports & Exports -------------------------------------------------------------------------------
local core = _G["core"]
local dump = _G["dump"]
local C = _G["tmg_constants"]
-- Constants ---------------------------------------------------------------------------------------
local SINGLEPLAYER_PRIVS = {
debug = true,
fast = true,
fly = true,
give = true,
interact = true,
noclip = true,
privs = true,
server = true,
settime = true,
teleport = true,
}
-- Private Functions -------------------------------------------------------------------------------
local private = {}
--[[
Find a player with a given name.
Args:
- player_name:string - the name of the desired player
Returns:
- an ObjectRef for the requested player if they're logged on, or nil
]]--
function private.find_player(name)
for _, player in ipairs(core.get_connected_players()) do
if player:get_player_name() == name then
return player
end
end
return nil
end
--[[
Move the indicated player into a safe spawn location.
We're looking for somewhere which is an air block on top of something walkable. We start with
the player's current position, and examine the current x/z column to find the first air block,
and see if that will do. If not, we pick a new location a short distance away, and repeat. The
process continues to expand outwards until a safe location is found, or we've looked half a km
away without finding anything.
If this function gets called before the world has finished generating, it will automatically
delay
Args:
- player:ObjectRef - the player to relocate
]]--
function private.set_starting_pos(player_name, delays)
delays = delays or 0
if delays > 10 then
core.log("warning", "Too many delays in finding a safe spawning location: giving up")
return
end
local player = private.find_player(player_name)
local player_pos = player:get_pos()
local node = core.get_node(player_pos)
if node.name == "unknown" or node.name == "ignore" then
core.log("action", "no map data, delaying player positioning")
core.after(0.1, function() private.set_starting_pos(player_name, delays + 1) end)
return
end
local pos = { x = player_pos.x, y = player_pos.y, z = player_pos.z }
local distances = { 0, 8, 16, 32, 64, 128, 256, 512 }
for _, distance in ipairs(distances) do
for _, dx in ipairs({ 0, 1, -1 }) do
pos.x = player_pos.x + dx * distance
for _, dz in ipairs({ 0, 1, -1 }) do
pos.z = player_pos.z + dz * distance
local floor_node = nil
for y = C.ALTITUDE.BEDROCK, C.ALTITUDE.SKY do
pos.y = y
node = core.get_node(pos)
if floor_node and node.name == "air" then
local floor_def = core.registered_nodes[floor_node.name]
if floor_def.walkable then
core.log("info", "Moved player to "..dump(pos, ""))
player:set_pos(pos)
return
end
break
end
floor_node = node
end
end
end
end
end
--[[
Set up privledges and settings for a new player.
Args:
- 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()
physics.speed_fast = 10
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)
-- Script ------------------------------------------------------------------------------------------
core.log("info", "Tungston's Game initialization complete")
+5
View File
@@ -0,0 +1,5 @@
name = tmg_last
title = Tungston's Game / Last
description = complete game setup
author = tungstonminer
depends = tmg_constants
+8
View File
@@ -0,0 +1,8 @@
-- Imports & Exports -------------------------------------------------------------------------------
local core = _G["core"]
-- Registrations -----------------------------------------------------------------------------------
core.register_mapgen_script(core.get_modpath("tmg_mapgen").."/mapenv.lua")
+176
View File
@@ -0,0 +1,176 @@
-- Imports & Exports -------------------------------------------------------------------------------
local core = _G["core"]
local dump = _G["dump"]
local math = _G["math"]
local VoxelArea = _G["VoxelArea"]
local tmg_constants_path = core.get_modpath("tmg_constants")
dofile(tmg_constants_path.."/constants.lua")
local C = _G["tmg_constants"]
local A = C.ALTITUDE
-- Constants ---------------------------------------------------------------------------------------
local data = {}
local TERRAIN_TYPE_NOISE = core.get_value_noise({
flags = "eased",
lacunarity = 2,
octaves = 1,
offset = 0,
persistence = 0.5,
scale = 1.0,
seed = 8381909047,
spread = { x = 512, y = 512, z = 0 },
})
local TERRAIN_TYPES = {
{ name = "ocean_abyss", lowest = A.ABYSS, highest = A.DEEP, noise = nil },
{ name = "ocean_shelf", lowest = A.DEEP, highest = A.SHALLOW, noise = nil },
{ name = "ocean_surface", lowest = A.SHALLOW, highest = A.SURFACE, noise = nil },
{ name = "land_plains", lowest = A.SURFACE, highest = A.PLAIN, noise = nil },
{ name = "land_hills", lowest = A.PLAIN, highest = A.HILL, noise = nil },
{ name = "land_moors", lowest = A.HILL, highest = A.MOOR, noise = nil },
{ name = "land_mountains", lowest = A.MOOR, highest = A.MOUNTAIN, noise = nil },
}
-- Private Functions -------------------------------------------------------------------------------
local private = {}
function private.compute_altitude_at(pos)
local raw_index = (TERRAIN_TYPE_NOISE:get_2d(pos) + 2) / 2 * #TERRAIN_TYPES
raw_index = math.max(1, math.min(#TERRAIN_TYPES, raw_index))
local result = 0
for index, terrain in ipairs(TERRAIN_TYPES) do
if not terrain.noise then
terrain.noise = private.make_noise_in_range(terrain.lowest, terrain.highest)
end
local factor = math.max(0, math.min(1, 1 - math.abs(raw_index - index)))
result = result + factor * terrain.noise:get_2d(pos)
if pos.x % 64 == 0 and pos.z % 64 == 0 and factor > 0 then
core.debug("raw_index: "..raw_index..", terrain: "..terrain.name..", factor: "..factor)
end
end
return math.floor(result)
end
--[[
Fill the lowest layer of the world with bedrock nodes.
Args:
- area:VoxelArea - an area calibrated to the area to fill
- fill_min:vector - the minimal corner of the area to fill
- fill_max:vector - the maximal corner of the area to fill
]]--
function private.fill_bedrock(area, fill_min, fill_max)
if fill_min.y > A.BEDROCK then return end
local bedrock_id = core.get_content_id("tmg_nodes:bedrock")
for x = fill_min.x, fill_max.x do
for z = fill_min.z, fill_max.z do
data[area:index(x, A.BEDROCK, z)] = bedrock_id
end
end
end
--[[
Fill in the oceans by replacing air blocks below sea level with water.
Args:
- area:VoxelArea - an area calibrated to the area to fill
- fill_min:vector - the minimal corner of the area to fill
- fill_max:vector - the maximal corner of the area to fill
]]--
function private.fill_ocean(area, fill_min, fill_max)
if fill_min.y > A.SURFACE then return end
local water_id = core.get_content_id("mapgen_water_source")
local y_max = math.min(fill_max.y, A.SURFACE)
local y_min = math.max(fill_min.y, A.BEDROCK)
for x = fill_min.x, fill_max.x do
for y = y_min, y_max do
for z = fill_min.z, fill_max.z do
local index = area:index(x, y, z)
if data[index] == core.CONTENT_AIR then
data[index] = water_id
end
end
end
end
end
--[[
Fill in base stone terrain using altitude noise.
Args:
- area:VoxelArea - an area calibrated to the area to fill
- fill_min:vector - the minimal corner of the area to fill
- fill_max:vector - the maximal corner of the area to fill
]]--
function private.fill_terrain(area, fill_min, fill_max)
local pos = { x = 0, y = 0, z = 0 }
local stone_id = core.get_content_id("mapgen_stone")
local y_max = math.min(fill_max.y, A.SKY)
local y_min = math.max(fill_min.y, A.BEDROCK)
for x = fill_min.x, fill_max.x do
for z = fill_min.z, fill_max.z do
pos.x, pos.y = x, z
local y_terrain = private.compute_altitude_at(pos)
for y = y_min, math.min(y_max, y_terrain) do
data[area:index(x, y, z)] = stone_id
end
end
end
end
--[[
Make a ValueNoise source scaled to a certain altitude range.
Args:
- highest:int - the highest altitude desired in the range
- lowest:int - the lowest altitude desired in the range
Return:
- a ValueNoise object
]]--
function private.make_noise_in_range(lowest, highest)
return core.get_value_noise({
flags = "eased",
lacunarity = 2,
octaves = 5,
offset = lowest,
persistence = 0.5,
scale = (highest - lowest) / 2,
seed = 16552167,
spread = { x = 128, y = 128, z = 0 },
})
end
-- Registrations -----------------------------------------------------------------------------------
core.register_on_generated(function(voxels, fill_min, fill_max)
local emerged_min, emerged_max = voxels:get_emerged_area()
local area = VoxelArea(emerged_min, emerged_max)
voxels:get_data(data)
private.fill_terrain(area, fill_min, fill_max)
private.fill_bedrock(area, fill_min, fill_max)
private.fill_ocean(area, fill_min, fill_max)
voxels:set_data(data)
voxels:calc_lighting()
voxels:update_liquids()
end)
+5
View File
@@ -0,0 +1,5 @@
name = tmg_mapgen
title = Tungston's Game / Map Generation
description = do the work of actually generating the map
author = tungstonminer
depends = tmg_nodes
+26
View File
@@ -0,0 +1,26 @@
-- Imports & Exports -------------------------------------------------------------------------------
local core = _G["core"]
-- Constants ---------------------------------------------------------------------------------------
local S = core.get_translator("tmg_nodes")
-- Registrations -----------------------------------------------------------------------------------
core.register_node("tmg_nodes:bedrock", {
description = S("Bedrock"),
drop = "",
is_ground_content = false,
sounds = { footstep = "tmg_nodes_stone" },
tiles = {"tmg_nodes_bedrock.png"},
})
core.register_node("tmg_nodes:stone", {
description = S("Stone"),
drop = "tmg_nodes:stone",
sounds = { footstep = "tmg_nodes_stone" },
tiles = {"tmg_nodes_stone.png"},
})
+10
View File
@@ -0,0 +1,10 @@
-- Imports & Exports -------------------------------------------------------------------------------
local core = _G["core"]
-- Script ------------------------------------------------------------------------------------------
local path = core.get_modpath("tmg_nodes")
dofile(path.."/earthlike.lua")
dofile(path.."/liquid.lua")
+78
View File
@@ -0,0 +1,78 @@
-- Imports & Exports -------------------------------------------------------------------------------
local core = _G["core"]
local tmg_constants = _G["tmg_constants"]
-- Constants ---------------------------------------------------------------------------------------
local S = core.get_translator("tmg_nodes")
-- Registrations -----------------------------------------------------------------------------------
core.register_node("tmg_nodes:water_flowing", {
description = S("Flowing Water"),
drawtype = tmg_constants.DRAW_TYPE.FLOWING_LIQUID,
tiles = {{
name = "tmg_nodes_water_flowing_animated.png",
animation = {
type = tmg_constants.ANIMATION_TYPE.VERTICAL_FRAMES,
aspect_w = 16,
aspect_h = 16,
length = 5.0,
},
}},
sounds = { footstep = { name = "tmg_nodes_water_footstep" } },
is_ground_content = false,
use_texture_alpha = "blend",
paramtype = "light",
paramtype2 = "flowingliquid",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
drowning = 4,
liquidtype = tmg_constants.LIQUID_TYPE.FLOWING,
liquid_alternative_flowing = "tmg_nodes:water_flowing",
liquid_alternative_source = "tmg_nodes:water_source",
liquid_viscosity = tmg_constants.VISCOSITY.XX_FAST,
liquid_range = 7,
waving = tmg_constants.WAVING.LIQUID_LIKE,
post_effect_color = "#033C5CCC",
groups = {},
})
core.register_node("tmg_nodes:water_source", {
description = S("Water"),
drawtype = "liquid",
waving = tmg_constants.WAVING.LIQUID_LIKE,
tiles = {{
name = "tmg_nodes_water_source_animated.png",
animation = {
type = "vertical_frames",
aspect_w = 16,
aspect_h = 16,
length = 5.0,
}
}},
sounds = { footstep = { name = "tmg_nodes_water_footstep" } },
is_ground_content = false,
use_texture_alpha = tmg_constants.TEXTURE_ALPHA.BLEND,
paramtype = "light",
walkable = false,
pointable = false,
diggable = false,
buildable_to = true,
drop = "",
drowning = 4,
liquidtype = "source",
liquid_alternative_flowing = "tmg_nodes:water_flowing",
liquid_alternative_source = "tmg_nodes:water_source",
liquid_viscosity = tmg_constants.VISCOSITY.XX_FAST,
liquid_renewable = true,
liquid_range = 7,
post_effect_color = "#033C5CCC",
groups = { },
})
+5
View File
@@ -0,0 +1,5 @@
name = tmg_nodes
title = Tungston's Game / Nodes
description = define the nodes which make up the world
author = tungstonminer
depends = tmg_constants
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 647 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 438 B

View File