差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录前一修订版后一修订版 | 前一修订版 | ||
modding:introduction [2022/03/14 12:58] – 硫缺铅 | modding:introduction [2022/10/04 03:10] (当前版本) – 外部编辑 127.0.0.1 | ||
---|---|---|---|
行 1: | 行 1: | ||
+ | ====== Modding Introduction ====== | ||
+ | |||
+ | Mindustry mods are simply directories of assets. There are many ways to use the modding API, depending on exactly what you want to do, and how far you're willing to go to do it. | ||
+ | |||
+ | You could just resprite existing game content, you can create new game content with the simpler Json API (which is the main focus of this documentation), | ||
+ | |||
+ | Sharing your mod is as simple as giving someone your project directory; mods are also cross platfrom to any platform that supports them. You'll want to use GitHub (or a similar service) for hosting your source code. To make mods all you really need is any computer with a text editor. | ||
+ | ===== Directory Structure ===== | ||
+ | Your project directory should look something like this: | ||
+ | |||
+ | project | ||
+ | ├── mod.hjson | ||
+ | ├── content | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | │ | ||
+ | ├── maps | ||
+ | ├── bundles | ||
+ | ├── sounds | ||
+ | ├── schematics | ||
+ | ├── scripts | ||
+ | ├── sprites-override | ||
+ | └── sprites | ||
+ | * mod.hjson (required) metadata file for your mod, | ||
+ | * content/ directories for game Content, | ||
+ | * maps/ directory for in-game maps, | ||
+ | * bundles/ directory for Bundles, | ||
+ | * sounds/ directory for Sound files, | ||
+ | * schematics/ directory for Schematic files, | ||
+ | * scripts/ directory for Scripts, | ||
+ | * sprites-override/ | ||
+ | * sprites/ Sprites directory for your content | ||
+ | Every platform has a different user application data directory, and this is where your mods should be placed: | ||
+ | * Linux: ~/ | ||
+ | * Steam: | ||
+ | * Windows: %appdata%/ | ||
+ | * MacOS: ~/ | ||
+ | Note that your filenames should be lowercased and hyphen separated: | ||
+ | * correct: my-custom-block.json | ||
+ | * incorrect: My Custom Block.json | ||
+ | ===== Hjson ===== | ||
+ | |||
+ | Mindustry uses Hjson, which for anyone who knows Json, is simply a superset of the very popular serialization language known as Json. – This means that any valid Json will work, but you get extra useful stuff: | ||
+ | # single line comment | ||
+ | |||
+ | // single line comment | ||
+ | |||
+ | /* multiline | ||
+ | comment */ | ||
+ | |||
+ | key1: single line string | ||
+ | |||
+ | key2: | ||
+ | ''' | ||
+ | multiline | ||
+ | string | ||
+ | ''' | ||
+ | |||
+ | key3: [ value 1 | ||
+ | value 2 | ||
+ | value 3 ] | ||
+ | |||
+ | key4: { key1: string | ||
+ | key2: 0 } | ||
+ | If you don't know any of those words. – A serialization language, is simply a language which encodes information for a program, and encode means to translate informantion from one form to another, and in this case, to translate text into Java data structures. | ||
+ | ===== mod.hjson ===== | ||
+ | At the root of your project directory, you must have a mod.json which defines the basic metadata for your project. This file can also be (optionally) named mod.hjson to potentially help your text editor pick better syntax highlighting. | ||
+ | |||
+ | |||
+ | name: " | ||
+ | displayName: | ||
+ | author: Yourself | ||
+ | description: | ||
+ | version: " | ||
+ | minGameVersion: | ||
+ | dependencies: | ||
+ | hidden: false | ||
+ | |||
+ | * name will be used to reference to your mod, so name it carefully; | ||
+ | * displayName this will be used as a display name for the UI, which you can use to add formatting to said name; | ||
+ | * description of the mod will be rendered in the ingame mod manager, so keep it short and to the point; | ||
+ | * dependencies is optional, if you want to know more about that, go to the dependencies section; | ||
+ | * minGameVersion is the minimum build version of the game. This is required to be a number greater than 105. | ||
+ | * hidden is whether or not this mod is essential for multiplayer, | ||
+ | ===== Content ===== | ||
+ | |||
+ | At the root of your project directory you can have a content/ directory, this is where all the Json/Hjson data goes. Inside of content/ you have subdirectories for the various kinds of content, these are the current common ones: | ||
+ | * content/ | ||
+ | * content/ | ||
+ | * content/ | ||
+ | * content/ | ||
+ | Note that each one of these subdirectories needs a specific content type. The filenames of these files is important, because the stem name of your path (filename without the extension) is used to reference it. | ||
+ | Furthermore the files within these content/< | ||
+ | |||
+ | The content of these files will tend to look something like this: | ||
+ | |||
+ | |||
+ | type: TypeOfThing | ||
+ | name: Name Of Thing | ||
+ | description: | ||
+ | # ... more fields here ... | ||
+ | |||
+ | field type notes | ||
+ | type String Content type of this object. | ||
+ | name String Displayed name of content. | ||
+ | description String Displayed description of content. | ||
+ | Other fields included will be the fields of the type itself. | ||
+ | |||
+ | A side note, name and description are not required to be in the json structure. You can define them for any language with (Bundles)[# | ||
+ | |||
+ | ===== Types ===== | ||
+ | Types have numerous fields, but the important one is type; this is a special field used by the content parser, that changes which type your object is. A Router type can't be a Turret type, as they' | ||
+ | |||
+ | Types extend each other, so if MissileBulletType extends BasicBulletType, | ||
+ | |||
+ | What you can expect a field to do is up to the specific type, some types do absolutely nothing with their fields, and work mostly as a base types will extend from. One such type is Block. | ||
+ | |||
+ | In this unit example, the type of the unit is flying. The type of the bullet is BulletType, so you can use MissileBulletType, | ||
+ | |||
+ | One could also use mech, legs, naval or payload as the unit type here. | ||
+ | |||
+ | type: flying | ||
+ | weapons: [ | ||
+ | { | ||
+ | bullet: { | ||
+ | type: MissileBulletType | ||
+ | damage: 9000 | ||
+ | } | ||
+ | } | ||
+ | ] | ||
+ | |||
+ | As of build 125.1, types can also be the fully-qualified class name of a Java class. | ||
+ | |||
+ | For example, to specify a block as a MendProjector, | ||
+ | |||
+ | While not particularly useful for vanilla types, this can be used to load block types from other Java mods as dependencies. | ||
+ | |||
+ | ===== Tech Tree ===== | ||
+ | Much like type there exist another magical field known as research which can go at the root of any block object to put it in the techtree. | ||
+ | |||
+ | |||
+ | research: duo | ||
+ | This would put your block after duo in the techtree, and to put it after your own mods block you would write your < | ||
+ | |||
+ | Research costs: | ||
+ | |||
+ | type cost notes | ||
+ | blocks requirements ^ 1.1 * 20 * researchCostMultiplier researchCostMultiplier is a stat that can be set on blocks | ||
+ | units requirements ^ 1.1 * 50 --- | ||
+ | The cost is then rounded down to the nearest 10, 100, 1k, 10k, or 100k depending on how expensive the cost is. | ||
+ | |||
+ | requirements is the cost of the block or unit. Units use their build cost/ | ||
+ | |||
+ | If you want to set custom research requirements use this object in place of just a name: | ||
+ | |||
+ | |||
+ | research: { | ||
+ | parent: duo | ||
+ | requirements: | ||
+ | copper/100 | ||
+ | ] | ||
+ | } | ||
+ | This can be used to override block or unit costs, or make resources need to be researched instead of just having to produce it. | ||
+ | ===== Sprites ===== | ||
+ | All you need to make sprites, is an image editor that supports transparency (aka: not paint). Block sprites should be 32 * size, so a 2x2 block would require a 64x64 image. Images must be PNG files with a 32-bit RGBA pixel format. Any other pixel format, such as 16-bit RGBA, may cause Mindustry to crash with a " | ||
+ | |||
+ | |||
+ | file sprites/ | ||
+ | If any of them are not 32-bit RGBA formatted, fix them. | ||
+ | |||
+ | Sprites can simply be dropped in the sprites/ subdirectory. The content parser will look through it recursively. Images are packed into an " | ||
+ | |||
+ | Content is going to look for sprites relative to it's own name. content/ | ||
+ | |||
+ | Content may look for multiple sprites. my-hail could be a turret, and it could look for the suffix < | ||
+ | |||
+ | You can find all the vanilla sprites here: | ||
+ | |||
+ | https:// | ||
+ | Another thing to know about sprites is that some of them are modified by the game. Turrets specifically have a black border added to them, so you must account for that while making your sprites, leaving transparent space around turrets for example: Ripple | ||
+ | |||
+ | To override ingame content sprites, you can simply put them in sprites-override/ | ||
+ | ===== Sound ===== | ||
+ | Custom sounds can be added through the modding system by dropping them in the sounds/ subdirectory. It doesn' | ||
+ | |||
+ | Just like any other assets, you reference them by the stem of your filenames, so pewpew.ogg and pewpew.mp3 can be referenced with pewpew from a field of type Sound. | ||
+ | |||
+ | Here's a list of built-in sounds: | ||
+ | |||
+ | artillery back bang beam bigshot boom breaks build buttonClick click combustion conveyor corexplode cutter door drill explosion explosionbig fire flame flame2 grinding hum laser laserbig laserblast lasercharge lasercharge2 lasershoot machine message mineDeploy minebeam missile mud noammo pew place plantBreak plasmaboom plasmadrop press pulse railgun rain release respawn respawning rockBreak sap shield shoot shootBig shootSnap shotgun smelter spark splash spray steam swish techloop thruster tractorbeam unlock wave wind wind2 wind3 windhowl windowHide none | ||
+ | ===== Dependencies ===== | ||
+ | |||
+ | You can add dependencies to your mod by simple adding other mods name in your mod.json: | ||
+ | |||
+ | |||
+ | dependencies: | ||
+ | other-mod-name | ||
+ | not-a-mod | ||
+ | ] | ||
+ | The name of dependencies are lower-cased and spaces are replaced with - hyphens, for example Other MOD NamE becomes other-mod-name. | ||
+ | |||
+ | To reference the other mods assets, you must prefix the asset with the other mods name: | ||
+ | |||
+ | other-mod-name-not-copper would reference not-copper in other-mod-name | ||
+ | other-mod-name-angry-dagger would reference angry-dagger in other-mod-name | ||
+ | not-a-mod-angry-dagger would reference angry-dagger in not-a-mod | ||
+ | ===== Bundles ===== | ||
+ | An optional addition to your mod is called bundles. The main use of bundles are give translations of your content, but there' | ||
+ | |||
+ | The contents of this file is very simple: | ||
+ | |||
+ | |||
+ | block.example-mod-silver-wall.name = Серебряная Стена | ||
+ | block.example-mod-silver-wall.description = Стена из серебра. | ||
+ | If you've read the first few sections of this guide, you'll spot it right away: | ||
+ | |||
+ | <content type> | ||
+ | <content type> | ||
+ | With your own custom bundle lines for use in scripts you can use whatever key you like: | ||
+ | |||
+ | message.egg = Eat your eggs | ||
+ | randomline = Random Line | ||
+ | Notes: | ||
+ | |||
+ | mod/content names are lowercased and hyphen separated. | ||
+ | List of content types: | ||
+ | |||
+ | item block bullet liquid status unit weather sector error planet | ||
+ | |||
+ | List of bundle suffixes relative to languages: | ||
+ | |||
+ | en pt_PT bg zh_TW in_ID cs vi es pl lt it hu pt_BR et nl ja nl_BE ro zh_CN fi eu tr ko th sr be fil tk sv uk_UA de da ru fr | ||
+ | ===== GitHub ===== | ||
+ | Once you have a mod of some kind, you'll want to actually share it, and you may even want to work with other people on it, and to do that you can use GitHub. If you don't know what Git (or GitHub) is at all, then you should look into GitHub Desktop, otherwise simply use your favorite command line tool or text editor plugin. | ||
+ | |||
+ | All you need understand is how to open repositories on GitHub, stage and commit changes in your local repository, and push changes to the GitHub repository. Once your project is on GitHub, there are three ways to share it: | ||
+ | |||
+ | with the endpoint, for example Anuken/ | ||
+ | with the zip file, for example https:// | ||
+ | add the topic/tag mindustry-mod on your repository, which should add it to the topic search and the Mod scraper. | ||
+ | ===== FAQ ===== | ||
+ | |||
+ | * time in game is calculated through ticks; | ||
+ | * ticks sometimes called frames, are assumed to be 1/60th of a second; | ||
+ | * tilesize is 8 units internally; | ||
+ | to calculate range out of lifetime and speed you can do lifetime * speed = range; | ||
+ | * Abstract what is abstract? All you need to know about abstract types is that they cannot be instantiated/ | ||
+ | * what is a NullPointerException? | ||
+ | * bleeding-edge what is bleeding-edge? | ||