wip
This commit is contained in:
@@ -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
|
||||
}
|
||||
@@ -3,7 +3,7 @@
|
||||
local core = _G.core
|
||||
|
||||
|
||||
-- Registrations -----------------------------------------------------------------------------------
|
||||
-- Script ------------------------------------------------------------------------------------------
|
||||
|
||||
core.register_biome({
|
||||
name = "ocean_floor",
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
-- Imports -----------------------------------------------------------------------------------------
|
||||
|
||||
local jvmi = _G.jvmi
|
||||
local core = _G.core
|
||||
|
||||
local mod = jvmi.register_mod("jvmi_biomes")
|
||||
|
||||
-- Registrations -----------------------------------------------------------------------------------
|
||||
|
||||
core.clear_registered_biomes()
|
||||
dofile(core.get_modpath("jvmi_biomes").."/definitions.lua")
|
||||
-- Script ------------------------------------------------------------------------------------------
|
||||
|
||||
if jvmi.env == "main" then
|
||||
core.clear_registered_biomes()
|
||||
mod.domodfile("definitions.lua")
|
||||
elseif jvmi.env == "mapgen" then
|
||||
mod.domodfile("mapgen.lua")
|
||||
end
|
||||
|
||||
@@ -1,31 +1,35 @@
|
||||
-- Imports -----------------------------------------------------------------------------------------
|
||||
|
||||
local jvmi = _G.jvmi
|
||||
local core = _G.core
|
||||
|
||||
local path = core.get_game_info().path
|
||||
local C = dofile(path.."/common/constants.lua")
|
||||
local Region = dofile(path.."/common/region.lua")
|
||||
|
||||
|
||||
-- Private -----------------------------------------------------------------------------------------
|
||||
|
||||
local mod = jvmi.register_mod("jvmi_biomes")
|
||||
local private = {}
|
||||
|
||||
local C = jvmi.C
|
||||
local Region = jvmi.Region
|
||||
|
||||
|
||||
-- Public ------------------------------------------------------------------------------------------
|
||||
|
||||
--[[
|
||||
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
|
||||
applied from decorations to fill material.
|
||||
|
||||
Args:
|
||||
region:Region - the region currently being generated
|
||||
]]--
|
||||
function private.apply_to(region)
|
||||
function mod.apply_to(region)
|
||||
private.assign_biomes(region)
|
||||
private.fill_surface(region)
|
||||
end
|
||||
|
||||
|
||||
-- Private -----------------------------------------------------------------------------------------
|
||||
|
||||
--[[
|
||||
Assigns a specific biome to each position in the region.
|
||||
|
||||
@@ -77,10 +81,3 @@ function private.fill_surface(region)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
-- Export ------------------------------------------------------------------------------------------
|
||||
|
||||
return {
|
||||
apply_to = private.apply_to
|
||||
}
|
||||
@@ -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 = {}
|
||||
|
||||
|
||||
-- Node Definition Constants -----------------------------------------------------------------------
|
||||
-- Node Definition Constants ---------------------------------------------------
|
||||
|
||||
C.ANIMATION_TYPE = {
|
||||
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. ]]--
|
||||
C.ALTITUDE = {
|
||||
@@ -66,7 +66,6 @@ C.ALTITUDE = {
|
||||
ABYSS = -64,
|
||||
BEDROCK = -128,
|
||||
}
|
||||
|
||||
local A = C.ALTITUDE
|
||||
|
||||
--[[ 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 },
|
||||
}
|
||||
|
||||
|
||||
--[[
|
||||
A table defining the terrain types used in generating the base terrain.
|
||||
|
||||
@@ -113,4 +113,4 @@ C.TERRAIN_TYPES = {
|
||||
|
||||
-- Export ------------------------------------------------------------------------------------------
|
||||
|
||||
return C
|
||||
_G.jvmi.C = C
|
||||
@@ -65,4 +65,4 @@ end
|
||||
|
||||
-- Export -----------------------------------------------------------------------------------------
|
||||
|
||||
return private.dump
|
||||
_G.jvmi.dump = private.dump
|
||||
@@ -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 ------------------------------------------------------------------------------------------
|
||||
|
||||
local core = _G.core
|
||||
local jvmi = _G.jvmi
|
||||
local math = _G.math
|
||||
local VoxelArea = _G.VoxelArea
|
||||
|
||||
local check = dofile(core.get_game_info().path.."/common/check.lua")
|
||||
local check = jvmi.check
|
||||
|
||||
|
||||
-- Region Class ------------------------------------------------------------------------------------
|
||||
-- Private -----------------------------------------------------------------------------------------
|
||||
|
||||
local Region = {
|
||||
--[[ Defines the names of the known metadata tables. ]]--
|
||||
@@ -310,6 +310,6 @@ function Region:save_voxels()
|
||||
end
|
||||
|
||||
|
||||
-- Export ------------------------------------------------------------------------------------------
|
||||
-- Public ------------------------------------------------------------------------------------------
|
||||
|
||||
return Region
|
||||
jvmi.Region = Region
|
||||
@@ -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 -----------------------------------------------------------------------------------------
|
||||
|
||||
local private = {}
|
||||
@@ -26,7 +21,8 @@ end
|
||||
Performs a deep clone of a given table.
|
||||
|
||||
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:
|
||||
source:table - the table to be cloned
|
||||
@@ -93,4 +89,4 @@ end
|
||||
|
||||
-- Export ------------------------------------------------------------------------------------------
|
||||
|
||||
return private.merge({}, table, private)
|
||||
_G.jvmi.table = private.merge({}, _G.table, private)
|
||||
@@ -1,14 +1,13 @@
|
||||
-- Imports & Exports -------------------------------------------------------------------------------
|
||||
-- Imports -----------------------------------------------------------------------------------------
|
||||
|
||||
local core = _G.core
|
||||
local jvmi = _G.jvmi
|
||||
|
||||
|
||||
-- Registrations -----------------------------------------------------------------------------------
|
||||
|
||||
local path = core.get_modpath("jvmi_mapgen")
|
||||
core.register_mapgen_script(path.."/mapenv.lua")
|
||||
local mod = jvmi.register_mod("jvmi_mapgen")
|
||||
|
||||
|
||||
-- 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 -------------------------------------------------------------------------------
|
||||
|
||||
local core = _G.core
|
||||
local jvmi = _G.jvmi
|
||||
local vector = _G.vector
|
||||
|
||||
local path = core.get_game_info().path
|
||||
local C = dofile(path.."/common/constants.lua")
|
||||
local Region = dofile(path.."/common/region.lua")
|
||||
local table = dofile(path.."/common/table.lua")
|
||||
|
||||
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")
|
||||
local biomes = jvmi.require_mod("jvmi_biomes")
|
||||
local C = jvmi.C
|
||||
local check = jvmi.check
|
||||
local Region = jvmi.Region
|
||||
local table = jvmi.table
|
||||
|
||||
|
||||
-- Constants ---------------------------------------------------------------------------------------
|
||||
@@ -19,7 +17,8 @@ local A = C.ALTITUDE
|
||||
local TERRAIN_TYPES = nil
|
||||
local TERRAIN_TYPE_NOISE = nil
|
||||
|
||||
-- Common Node Content Ids -----------------------------------------------------
|
||||
|
||||
-- Content Ids -----------------------------------------------------
|
||||
|
||||
local AIR_ID = core.CONTENT_AIR
|
||||
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)
|
||||
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.
|
||||
|
||||
@@ -227,26 +251,7 @@ function private.prepare_terrain_table()
|
||||
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 ------------------------------------------------------------------------------------------
|
||||
|
||||
private.on_load()
|
||||
core.register_on_generated(private.populate_region)
|
||||
@@ -1,11 +1,9 @@
|
||||
-- Imports & Exports -------------------------------------------------------------------------------
|
||||
|
||||
local core = _G.core
|
||||
local jvmi = _G.jvmi
|
||||
|
||||
|
||||
-- Constants ---------------------------------------------------------------------------------------
|
||||
|
||||
local S = core.get_translator("jvmi_nodes")
|
||||
local S = jvmi.mods.nodes.S
|
||||
|
||||
|
||||
-- Registrations -----------------------------------------------------------------------------------
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
-- Imports & Exports -------------------------------------------------------------------------------
|
||||
|
||||
local core = _G.core
|
||||
local jvmi = _G.jvmi
|
||||
|
||||
local mod = jvmi.register_mod("jvmi_nodes")
|
||||
|
||||
|
||||
-- Script ------------------------------------------------------------------------------------------
|
||||
|
||||
local path = core.get_modpath("jvmi_nodes")
|
||||
dofile(path.."/earthy.lua")
|
||||
dofile(path.."/liquid.lua")
|
||||
dofile(path.."/stony.lua")
|
||||
mod.domodfile("earthy.lua")
|
||||
mod.domodfile("liquid.lua")
|
||||
mod.domodfile("stony.lua")
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
-- 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 ---------------------------------------------------------------------------------------
|
||||
|
||||
local C = dofile(core.get_game_info().path.."/common/constants.lua")
|
||||
local S = core.get_translator("jvmi_nodes")
|
||||
|
||||
|
||||
-- Registrations -----------------------------------------------------------------------------------
|
||||
-- Script ------------------------------------------------------------------------------------------
|
||||
|
||||
core.register_node("jvmi_nodes:water_flowing", {
|
||||
description = S("Flowing Water"),
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
-- 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 -----------------------------------------------------------------------------------
|
||||
-- Script ------------------------------------------------------------------------------------------
|
||||
|
||||
core.register_node("jvmi_nodes:bedrock", {
|
||||
description = S("Bedrock"),
|
||||
|
||||
+62
-36
@@ -1,38 +1,67 @@
|
||||
-- Imports & Exports -------------------------------------------------------------------------------
|
||||
|
||||
local core = _G.core
|
||||
local jvmi = _G.jvmi
|
||||
|
||||
jvmi.register_mod("jvmi_player")
|
||||
local private = {}
|
||||
|
||||
|
||||
-- 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 = {
|
||||
debug = true,
|
||||
fast = true,
|
||||
fly = true,
|
||||
give = true,
|
||||
interact = true,
|
||||
noclip = true,
|
||||
privs = true,
|
||||
server = true,
|
||||
settime = true,
|
||||
teleport = true,
|
||||
debug = true, fast = true, fly = true, give = true, interact = true, noclip = true,
|
||||
privs = true, server = true, settime = true, teleport = true,
|
||||
}
|
||||
|
||||
|
||||
-- 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.
|
||||
|
||||
Args:
|
||||
- player_name:string - the name of the desired player
|
||||
player_name:string - the name of the desired player
|
||||
|
||||
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)
|
||||
for _, player in ipairs(core.get_connected_players()) do
|
||||
@@ -44,6 +73,21 @@ function private.find_player(name)
|
||||
return nil
|
||||
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.
|
||||
|
||||
@@ -63,7 +107,7 @@ end
|
||||
]]--
|
||||
function private.set_starting_pos(player_name, delays)
|
||||
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")
|
||||
return
|
||||
end
|
||||
@@ -107,26 +151,8 @@ function private.set_starting_pos(player_name, delays)
|
||||
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)
|
||||
-- Script ------------------------------------------------------------------------------------------
|
||||
|
||||
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)
|
||||
private.configure_hand()
|
||||
core.register_on_joinplayer(private.on_player_joined)
|
||||
|
||||
Reference in New Issue
Block a user