Skip to content

Multi Block Structures

Redempt edited this page Dec 14, 2020 · 2 revisions

RedLib comes with a Multi-Block Structure API, which allows you to scan in multi-block structures and build them or detect their presence, among other things. To get started, you'll probably want to make your own MultiBlockStructure. To do this, you should first enable developer mode for RedLib. You can do this by changing devMode from false to true in its config.

After doing this, reload or restart your server, and developer mode will be enabled, giving you access to some tools. You can then run /struct tool to get a multi-block structure selection tool. With this, you can right-click two corners of a structure and run /struct export [name]. After running this command, a file will be generated with the scan of the structure, and the command will tell you where it is.

Note that container contents are not copied as part of the structure data. It is also not intended for especially massive sections of blocks; avoid using it for areas larger than 100x100.

Additionally, you can run /struct create [name] to play around with it. After running this command, left-clicking a block will tell you whether the structure is present at that location. If it is, it will tell you the rotation of the structure, whether it's mirrored, and the relative location of the block you clicked within the structure. This information is useful for the Multi-Block Structure API.

Once you have an exported structure, you can load it via MultiBlockStructure.create with a name and some other optional arguments. It takes either a String or an InputStream, so you can load it from a file or as a resource inside your jar.

With the MultiBlockStructure instance created, you're ready to build it or check for its presence. You can also get other information about the structure, like the dimensions, or the block at a given relative position. By calling getAt(Location), you can check whether the structure exists at the given location. This will work regardless of which block within the structure is at that location, and regardless of the rotation or mirroring of the structure. If the structure exists at that location, this will return a Structure instance. With the Structure instance, you can check the rotation and mirroring, get relative blocks within the structure, and check if it's still intact. You can also get the Region that the structure occupies.

Calling getAt(Location) on a MultiBlockStructure is a very expensive operation for larger structures. If you need to ensure a structure's integrity, consider caching, listening for events that modify blocks, or calling Structure.isIntact() instead, which is considerably faster.

You can also build your structure within the world by calling one of the variants of MultiBlockStructure.build. If your structure is especially large, try buildAsync instead. buildAsync is not truly async, but will build the structure across multiple ticks, setting a specified number of blocks every tick, and pass the Structure to a callback when it has been built.

Clone this wiki locally