Modding and even Game development itself usually requires a lot of trial & error. The more time you can save on those iteration times the better, as it accumulates quickly. Besides being quick to start up, VS offers a bundle more tricks to help you mod fast and efficiently. Here are some of the tricks every serious modder should use:
- Use macros! Switching from/to creative/survival mode and
/time set daybound to a keyboard shortcut is a must have. Hit CTRL+M to open the macro manager which will let you set those up!
- Don't fully restart the game to test out changes! In 95% of cases its enough to just leave the game world and rejoin or use ingame reload commands. You can quickly reload a world using the shortcut
- Don't restart/rejoin at all if you are doing trial&error on textures and shape files. These can be reloaded with the commands
.reload shapes. The latter may require you to place&remove a block so that the chunk gets redrawn
- Translation entries can be reloaded with
.reload lang, the handbook can be reloaded with
- Set up a quickstart.bat script, that contains e.g.
VintageStory.exe -oTestWorld -pcreativebuilding- this will insta-launch you into a super flat creative world named "TestWorld"
- Leave your mod unpacked in the mods folder! No need to zip it up, it'll load up just fine unpacked :-)
.tfeditto modify the lookings of your item/block inside the GUI, Hands or on the ground - with live preview.
.bseditto edit block selection and collisionboxes ingame - with live preview.
- Use the
/expclangcommand to generate a neatly pre-formatted list of language entries destined for your en.json, it's placed in a file named collectiblelang.json in the same folder where VintageStory.exe is. It creates language entries for any block or item that currently has no translation. Can save you a ton of time by not needing to handwrite your en.json file.
- Use the error reporter activated via
/errorreporter 1to save yourself the work of finding and scouring through the log files for problems. This feature will make it so that a dialog pop ups during start up of the game if any errors were encountered.
- If you want to create json patches, you can use ModMaker 3000™, a command line tool that ships with the game, to build the patches for you
- If you are stuck with an asset problem, look through the server-main.txt and client-main.txt! The engine is very talkative when it comes to asset errors.
When writing C# mods
- Use break points for debugging
- Browse through the many utility classes provided by the VS API, you might be able to save a lot of coding efforts! (e.g. ColorUtil, GameMath, ArrayExtensions, DictExtensions, HashsetExtensions, JsonUtil, ReaderWriterExtensions, SerializerUtil, WildcardUtil
- If you don't know it already, the LINQ extension, part of the .net framework, is an extremely powerful tool to make code more expressive.
- You can use edit&continue feature of Visual Studio to modify code while the game is running!
- If you don't have already make sure the games log output ends up in the Visual Studio output window
- If you are working with shaders, you can reload them with
Efficient Search Methods
More often than not, you'd want your code to find something in the game world. As you might already know, computers are not exactly the best at parallel processing like human eyes are, so they have to sequentially look through the entire search space. When doing so, keep in mind that, first and foremost, the most efficient search method is one that never runs, within a search space that is of size zero ;-)
In other words, sometimes you can avoid searches altogether through other clever means! If you still need to do a search, here's some more optimal ways than the brute force way:
- Entity Search
Use EntityPartitioning -
api.ModLoader.GetModSystem<EntityPartitioning>().WalkEntityPartitions(). This system partitions entities into 8x8x8 block buckets through the entire loaded game world, then only searches inside those buckets, within your supplied search radius, greatly reducing the search space.
- Block Search
a) If you want an entity to find a certain, not extremely common block, use the POI Registry. This registry lets block entities register a point of interest that entities can search through very efficiently. They are also partitioned into chunk column buckets to additionally reduce the search space. For a code sample, check out the berry bush block entity
b) For regular full chunk scans, I recommend a separate background thread that loads the chunk and access the raw block data via
chunk.Blocks. It's an array indexed with
(y * chunksize + z) * chunksize + x, where the xyz are local coordinate from 0 to chunkize-1. You should only write to a chunk in the main thread however! If you want to avoid threading for now, you can still iterate through
chunk.Blocksin the main thread and even slice up the task across multiple ticks, like vanilla beehives do.
c) For rare area scans, there is
api.World.GetBlockAccessorPrefetch(). This block accessor lets you pre-load an area and then rather efficiently iterate through each block in given area