Skip to content

5. Development en US

xiaohengying edited this page Apr 2, 2021 · 4 revisions

How to complie

Peparation

Please install Microsoft Visual Studio 2019 and cmake

create a new dir

Run the following command in the source code root folder(use powershell):

mkdir build

(c)

Configure Cmake

run cd build to enter the build dir then run:

cmake ..  -DCMAKE_BUILD_TYPE=Release

Compilation

Run under the build index

cmake --build   . --config Release

after compilation, trapdoor-mod.dll will be generated in Release folder

Only the Release version can be used, not the Debug version

Develop

Reference only

Structure of index

This is how the index looks:

├─api  //No actual function, mainly ports for BDS under the index
│  ├─block   //blocks related ports
│  ├─commands  //commands analyse
│  ├─entity   //entities ports
│  ├─exexpermental  
│  ├─graphics  //graphics ports
│  ├─include
│  ├─lib   //hook related
│  ├─math  
│  ├─tools  //tools-related
│  └─world //world-running ports
├─doc
├─img
├─include
├─mod   //the implement of functions
│  ├─config  //trapdoor-config related
│  ├─function 
│  ├─hopper
│  ├─player
│  ├─spawn
│  ├─tick
│  └─village
└─test

Creating personal mod with trapdoor's api

  1. Write a new branch to trapdoor::BDSMod
    class TrapdoorMod : public trapdoor::BDSMod {
}
  1. Initialise the mod target fromdllmain.cpp
trapdoor::BDSMod *createBDSModInstance() {
    return new mod::TrapdoorMod();
}

void mod_init() {
    initConsole();
    // trapdoor::initLogger("trapdoor.log", false, true, true);
    trapdoor::initLogger("trapdoor.log", true, false, false);
    auto *mod = createBDSModInstance();
    trapdoor::initializeMod(mod);
    mod::TrapdoorMod::printCopyRightInfo();
}
  1. ChooseServerLevel::tick in GameTick.cppas the target of initializing
THook(
        void,
        MSSYM_B1QA4tickB1AE11ServerLevelB2AAA7UEAAXXZ,
        trapdoor::Level * serverLevel
) {


    if (!trapdoor::bdsMod) {
        L_ERROR("mod is nullptr");
    }
    if (!trapdoor::bdsMod->getLevel()) {
        trapdoor::bdsMod->setLevel(serverLevel);
        trapdoor::bdsMod->asInstance<mod::TrapdoorMod>()->initialize();
    }
}

If there is time available, there may ba a change of releasing a more detailed tutorial

Words from the one who translates: Sorry for potential unclear or non-professional wording as I do not have coding related background