### Configure Server Settings via JSON Source: https://github.com/movingblocks/terasology/blob/develop/docs/Playing.md An example JSON configuration file for a headless server. This allows setting default modules, world generation parameters, and other server-specific configurations. Changes in `config.cfg` take priority after initial setup. ```json { "defaultModSelection": { "modules": [ "MyModule", "MyModule2" ], "defaultGameplayModuleName": "MyModule" }, "worldGeneration": { "worldTitle": "World Title", "defaultSeed": "custom seed for the server", "defaultGenerator": "MyModule:MyWorldgen" }, "moduleConfigs": {}, } ``` -------------------------------- ### Example Module Configuration Source: https://github.com/movingblocks/terasology/wiki/Module.txt This is an example of a Module.txt file, showing the structure for defining a module's metadata, dependencies, and type. ```JSON { "id" : "CoreSampleGameplay", "version" : "2.0.0-SNAPSHOT", "displayName" : "Core Gameplay", "description" : "Minimal gameplay template. Little content but a few starting items.", "dependencies" : [ {"id": "Core", "minVersion": "2.0.0"} ], "isGameplay" : "true", "defaultWorldGenerator" : "Core:FacetedPerlin" } ``` -------------------------------- ### Test Replay Start Logic Source: https://github.com/movingblocks/terasology/blob/develop/docs/Replay-Tests.md Implement checks for the start of a replay, verifying player character and initial position. ```java @Override protected void testOnReplayStart() throws Exception { LocalPlayer localPlayer = CoreRegistry.get(LocalPlayer.class); TestUtils.waitUntil(() -> localPlayer.isValid()); character = localPlayer.getCharacterEntity(); initialPosition = new Vector3f(19.79358f, 13.511584f, 2.3982882f); LocationComponent location = character.getComponent(LocationComponent.class); assertEquals(initialPosition, location.getLocalPosition()); // check initial position. } ``` -------------------------------- ### Dependency Report Example Source: https://github.com/movingblocks/terasology/blob/develop/docs/Using-Locally-Developed-Libraries.md An example entry in the dependency report showing a dependency resolved from a local project. ```text org.terasology:gestalt-module:5.1.5 ➡ project :gestalt:gestalt-module ``` -------------------------------- ### Initialize and Run Replay in a Separate Thread Source: https://github.com/movingblocks/terasology/wiki/Replay-Tests Initializes ReplayTestingEnvironment and starts a new thread to open a replay. The replay title is specified, and it can be run headless. This setup allows for testing in the main thread while the replay executes concurrently. ```Java private ReplayTestingEnvironment environment = new ReplayTestingEnvironment(); /** To test the replay while it is executing, it is necessary to create a thread that will run the replay. */ private Thread replayThread = new Thread() { @Override public void run() { try { //This is the title of the replay to be played. It is generally the name of the folder in the 'recordings' directory. String replayTitle = "REPLAY_TITLE"; /* This opens the game and executes the replay desired for testing. The first parameter of the "openReplay" method is the replay title, and the second one is if the replay should be headless. */ environment.openReplay(replayTitle, true); } catch (Exception e) { throw new RuntimeException(e); } } }; ``` -------------------------------- ### Get Facade Server Source: https://github.com/movingblocks/terasology/wiki/Codebase-Structure Use this command to get the FacadeServer. ```groovy groovyw facade get FacadeServer ``` -------------------------------- ### Prefab Inheritance Example Source: https://github.com/movingblocks/terasology/wiki/Entity-System-Architecture Demonstrates prefab inheritance by creating an 'angryGelatinousCube' that inherits from 'core:gelatinousCube' and modifies the movement speed. ```json { "name": "core:angryGelatinousCube", "parent": "core:gelatinousCube", "CharacterMovement": { "speedMultiplier": 0.3 } } ``` -------------------------------- ### Example Client ID List Source: https://github.com/movingblocks/terasology/blob/develop/docs/Playing.md Client IDs are added to the allowlist and denylist in JSON format. This example shows a list of two client IDs. ```json ["6a5f11f7-4038-4ef0-91ac-86cb957588b1","01264d12-27cf-4699-b8e2-bdc92ac8ef73"] ``` -------------------------------- ### Java Naming Conventions Example Source: https://github.com/movingblocks/terasology/wiki/Code-Conventions Demonstrates standard Java naming conventions for packages, classes, constants, and methods. Adheres to camelCase and PascalCase as specified. ```java package test; class TestClass { private static final int SOME_CONSTANT = 0; int someInt; void doSomething() { } } ``` -------------------------------- ### Initialize a New Module Source: https://github.com/movingblocks/terasology/wiki/Terasology's-Multi-Repo-Workspace Use this command to initialize a new module within your workspace, cloning its repository into the 'modules' directory. This is useful for starting a new module or adding an existing one. ```bash groovyw module init ``` -------------------------------- ### JavaFX Installation on Arch/Gentoo Source: https://github.com/movingblocks/terasology/blob/develop/docs/Troubleshooting-Developer.md Arch and Gentoo do not include JavaFX by default. Install the `java-openjfx` package on Arch or enable the `javafx` USE flag on Gentoo. ```text java-openjfx ``` -------------------------------- ### Blog Post Metadata Example Source: https://github.com/movingblocks/terasology/wiki/Outreach This is the required metadata section for a blog post in `index.md`. Ensure all fields are correctly filled. ```markdown --- posttype: "blog" title: cover: "./<cover-image-name>.jpg" description: <summary> author: <your-nickname> date: "YYYY-MM-DD" tags: [<tag-list>] --- ``` -------------------------------- ### Compile and Start Terasology (Command Line) Source: https://github.com/movingblocks/terasology/wiki/Contributor-Quick-Start Execute this command in your terminal to compile the Terasology project and launch the game. This is one of the primary ways to run the game during development. ```bash gradlew game ``` -------------------------------- ### Get a Specific Module Source: https://github.com/movingblocks/terasology/wiki/Terasology's-Multi-Repo-Workspace Use this command to fetch and clone a specific module's repository into your 'modules' directory. This is the simplest way to add a single module to your workspace. ```bash groovyw module get <module> ``` -------------------------------- ### Declare Gooey Module Dependency with Max Version Source: https://github.com/movingblocks/terasology/wiki/Module-Dependencies This example shows how to specify a dependency with both a minimum and maximum version, effectively defining a version range like `0.54.*`. ```json "dependencies" : [ { "id" : "Gooey", "minVersion" : "0.54.0", "maxVersion" : "0.55.0" } ], ``` -------------------------------- ### Run Headless Server with Java Source: https://github.com/movingblocks/terasology/wiki/Setup-a-headless-server Execute the Terasology server in headless mode using a Java 11 JAR file. This will start the server on the default port 25777. ```bash java -jar Terasology.jar --headless ``` -------------------------------- ### Initialize Module Foundation Source: https://github.com/movingblocks/terasology/wiki/Contributor-Quick-Start Use this command to fetch the core module foundation for your workspace. This is a necessary step after cloning the repository. ```bash groovyw module init iota ``` -------------------------------- ### Create New Facade Source: https://github.com/movingblocks/terasology/wiki/Codebase-Structure Use this command to create a new facade, initializing it with template files and a Git repository. ```groovy groovyw facade create DevFacade ``` -------------------------------- ### PC Facade CLI Help Source: https://github.com/movingblocks/terasology/blob/develop/facades/PC/README.md Displays the help information for the Terasology command-line interface, detailing available options for configuration and startup. ```sh ./Terasology --help Usage: terasology [-h] [--[no-]crash-report] [--create-last-game] [--headless] [--load-last-game] [--permissive-security] [--[no-]save-games] [--[no-]sound] [--[no-]splash] [--homedir=<homeDir>] [--max-data-size=<size>] [--oom-score=<score>] [--override-default-config=<overrideConfigPath>] [--server-port=<serverPort>] --[no-]crash-report Enable crash reporting --create-last-game Recreates the world of the latest game with a new save file on startup -h, /h, -?, /?, -help, /help, --help Show help --headless Start headless (no graphics) --homedir=<homeDir> Path to home directory --load-last-game Load the latest game on startup --max-data-size=<size> Set maximum process data size [Linux only] --oom-score=<score> Adjust out-of-memory score [Linux only] --override-default-config=<overrideConfigPath> Override default config --permissive-security --[no-]save-games Enable new save games --server-port=<serverPort> Change the server port --[no-]sound Enable sound --[no-]splash Enable splash screen For details, see https://github.com/MovingBlocks/Terasology/wiki/Advanced-Options Alternatively use our standalone Launcher from https://github.com/MovingBlocks/TerasologyLauncher/releases ``` -------------------------------- ### Create New Module Source: https://github.com/movingblocks/terasology/wiki/Codebase-Structure Creates a brand new module and initializes it with template content and a local Git repository. ```groovy groovyw module create MyNewModule ``` -------------------------------- ### Install Java OpenJFX on Arch Linux Source: https://github.com/movingblocks/terasology/wiki/Troubleshooting-Developer Arch Linux does not include JavaFX by default. Install the `java-openjfx` package to resolve this. ```bash sudo pacman -Syu java-openjfx ``` -------------------------------- ### Clone Terasology Engine Repository Source: https://github.com/movingblocks/terasology/wiki/Codebase-Structure This command is used to clone the primary Terasology engine repository, which is the starting point for the project. ```bash git clone https://github.com/MovingBlocks/Terasology.git ``` -------------------------------- ### Create a New Module Source: https://github.com/movingblocks/terasology/wiki/Developing-Modules This command initializes a new module within your workspace. The new module will be created in the 'modules/' directory with the specified name. For Linux-like systems, use './groovyw'. ```bash groovyw module create MySample ``` -------------------------------- ### Clean IntelliJ Project Configuration Source: https://github.com/movingblocks/terasology/wiki/Troubleshooting-Developer Command to remove IntelliJ configuration files from the workspace, useful for resetting a buggy IntelliJ setup. ```bash gradlew cleanIdea ``` -------------------------------- ### Get TeraNUI Library Source Source: https://github.com/movingblocks/terasology/blob/develop/docs/Using-Locally-Developed-Libraries.md Fetches the TeraNUI source code into the local Terasology workspace for development. This command places the source into `/libs/TeraNUI`. ```shell groovyw lib get TeraNUI ``` -------------------------------- ### Update an Existing Module Source: https://github.com/movingblocks/terasology/wiki/Developing-Modules Run this command to synchronize your local module with the latest changes from its main repository. Replace 'Sample' with the name of the module you are working on. ```bash groovyw module update Sample ``` -------------------------------- ### Implement BooleanTypeHandler Source: https://github.com/movingblocks/terasology/blob/develop/subsystems/TypeHandlerLibrary/README.MD Example of implementing a `TypeHandler` for the `Boolean` type. This handler serializes booleans using the provided serializer and deserializes them by checking if the data is a boolean. ```java public class BooleanTypeHandler extends TypeHandler<Boolean> { @Override public PersistedData serializeNonNull(Boolean value, PersistedDataSerializer serializer) { return serializer.serialize(value); } @Override public Optional<Boolean> deserialize(PersistedData data) { if (data.isBoolean()) { return Optional.of(data.getAsBoolean()); } return Optional.empty(); } } ``` -------------------------------- ### Non-Guarded Log Statement Example Source: https://github.com/movingblocks/terasology/blob/develop/docs/Code-Conventions.md This Java code demonstrates a log statement that is not guarded, leading to unnecessary string creation and manipulation even if logging is disabled. ```java logger.debug("log something" + method() + " and " + param.toString() + "concat strings"); ``` -------------------------------- ### Fetch an Existing Module Source: https://github.com/movingblocks/terasology/wiki/Developing-Modules Use this command to download an existing module from a remote repository into your local workspace. Ensure you are in the root of your workspace. For Linux-like systems, use './groovyw'. ```bash groovyw module get Sample ``` -------------------------------- ### Chest Item Slots with @Replicate and @Owns Source: https://github.com/movingblocks/terasology/wiki/Entities,-Components-and-Events-on-the-Network Example of an InventoryComponent field for chest items, using @Replicate to ensure server-to-client synchronization and @Owns for ownership replication. ```java @Replicate @Owns public List<EntityRef> itemSlots = Lists.newArrayList(); ``` -------------------------------- ### Replay Test Methods using AcceptanceTestEnvironment Source: https://github.com/movingblocks/terasology/wiki/Replay-Tests Implement these methods to define checks at different stages of a replay: start, during, and end. Use TestUtils.waitUntil for synchronization during replay. ```java @Override protected void testOnReplayStart() throws Exception { LocalPlayer localPlayer = CoreRegistry.get(LocalPlayer.class); TestUtils.waitUntil(() -> localPlayer.isValid()); character = localPlayer.getCharacterEntity(); initialPosition = new Vector3f(19.79358f, 13.511584f, 2.3982882f); LocationComponent location = character.getComponent(LocationComponent.class); assertEquals(initialPosition, location.getLocalPosition()); // check initial position. } @Override protected void testDuringReplay() throws Exception { EventSystemReplayImpl eventSystem = (EventSystemReplayImpl) CoreRegistry.get(EventSystem.class); TestUtils.waitUntil(() -> eventSystem.getLastRecordedEventIndex() >= 1810); // tests in the middle of a replay needs "checkpoints" like this. LocationComponent location = character.getComponent(LocationComponent.class); assertNotEquals(initialPosition, location.getLocalPosition()); // checks that the player is not on the initial position after they moved. } @Override protected void testOnReplayEnd() throws Exception { LocationComponent location = character.getComponent(LocationComponent.class); Vector3f finalPosition = new Vector3f(25.189344f, 13.406443f, 8.6651945f); assertEquals(finalPosition, location.getLocalPosition()); // checks final position } ``` -------------------------------- ### Fetch Additional Modules and Dependencies Source: https://github.com/movingblocks/terasology/wiki/Contributor-Quick-Start Use this command to recursively fetch a specified module and all of its dependencies. This is useful when you want to work with specific modules or their features. ```bash groovyw module recurse <module> ``` -------------------------------- ### Basic Command Implementation Source: https://github.com/movingblocks/terasology/blob/develop/docs/Developing-Commands.md Implement a simple console command by creating an annotated method within a ComponentSystem. Returned strings are displayed in the console. ```java import org.terasology.logic.console.commands.Command; import org.terasology.logic.console.commands.RegisterSystem; import org.terasology.logic.core.ComponentSystem; @RegisterSystem public class MyCommands extends BaseComponentSystem { @Command( shortDescription = "Say hello", helpText = "Writes hello world to the console" ) public String hello() { return "hello world"; } } ``` -------------------------------- ### Event Processing Method Example Source: https://github.com/movingblocks/terasology/blob/develop/docs/Events-and-Systems.md This method is called when an OnAddedComponent event occurs on an entity that has both MyComponent and LocationComponent. The parameters are automatically populated with the event, entity, and the specified components. ```java import org.terasology.entitySystem.event.Event; import org.terasology.entitySystem.entity.EntityRef; import org.terasology.entitySystem.systems.RegisterSystem; import org.terasology.entitySystem.systems.BaseComponentSystem; import org.terasology.entitySystem.components.ReceiveEvent; import org.terasology.logic.location.LocationComponent; @RegisterSystem public class MySystem extends BaseComponentSystem { @ReceiveEvent(components = {MyComponent.class, LocationComponent.class}) public void onMyComponentAdded(OnAddedComponent event, EntityRef entity, MyComponent myComponent) { // Method logic here } // Other system methods... } // Dummy component for example purposes class MyComponent { // Component fields and methods } // Dummy event for example purposes class OnAddedComponent implements Event { // Event fields and methods } ``` -------------------------------- ### Run Headless Server from Source Source: https://github.com/movingblocks/terasology/wiki/Setup-a-headless-server Compile and run the Terasology server in headless mode directly from the source code using Gradle. ```bash gradlew server ``` -------------------------------- ### Fetch Module and Dependencies Source: https://github.com/movingblocks/terasology/wiki/Codebase-Structure Fetches a specified module and all of its dependencies as source code. ```groovy groovyw module recurse JoshariasSurvival ``` -------------------------------- ### Basic Command Implementation Source: https://github.com/movingblocks/terasology/wiki/Developing-Commands Implement a simple command that returns a string. The command method must be in a ComponentSystem class and annotated with @Command. ```java import org.terasology.gestalt.entitysystem.component.ComponentSystem; import org.terasology.context.annotation.RegisterSystem; import org.terasology.logic.console.annotations.Command; @RegisterSystem public class MyCommands extends BaseComponentSystem { @Command( shortDescription = "Say hello", helpText = "Writes hello world to the console" ) public String hello() { return "hello world"; } } ```