tutorial:jigsaw
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:jigsaw [2020/08/15 13:03] – emmanuelmess | tutorial:jigsaw [2021/12/30 05:47] (current) – Fix link directing at Forge version, not Fabric redgrapefruit | ||
---|---|---|---|
Line 2: | Line 2: | ||
Jigsaws are good for advanced structures such as dungeons & villages, and allow you to spend more time on actually building content vs. messing with procedural generation code. | Jigsaws are good for advanced structures such as dungeons & villages, and allow you to spend more time on actually building content vs. messing with procedural generation code. | ||
- | A repository with finished code can be found [[https:// | + | A repository with the finished code from this tutorial |
+ | A full example with structure files and more can be found [[https:// | ||
===== Creating a StructureFeature ===== | ===== Creating a StructureFeature ===== | ||
Line 53: | Line 54: | ||
</ | </ | ||
- | To understand what happens here, we'll have to dive into jigsaws (https:// | ||
- | |||
- | Structure Blocks are a simple way of saving a structure to a .nbt file for future use. Jigsaws are a component of structure blocks that assemble multiple structures into a single one; similar to normal jigsaws, each piece of the structure connects at a jigsaw block, which is like a connection wedge in a puzzle piece. We'll assume you're familiar with saving structures-- if you aren' | ||
- | |||
- | The jigsaw menu consists of 3 fields: | ||
- | |||
- | * target pool | ||
- | * attachment type | ||
- | * turns into | ||
- | |||
- | {{ https:// | ||
- | |||
- | When thinking about this as a puzzle, the target pool is the group of puzzle pieces you can search through. If you have a total of 10 pieces, one target pool may have 7 of the total pieces. This field is how a jigsaw specifies, "Hi, I'd like a piece from group B to connect to me!" In the case of a village, this may be a road saying, "Give me a house!" | ||
- | |||
- | The attachment type can be seen as a more specific filter within target pools-- a jigsaw can only connect to other jigsaws with the same attachment type. This is like the type of connector on a puzzle piece. The usages for this are a little bit more specific. | ||
- | |||
- | Finally, the "turns into" field is simply what the jigsaw is replaced with after it finds a match. If the jigsaw is inside your cobblestone floor, it should probably turn into cobblestone. | ||
- | |||
- | Here's an example implementation: | ||
- | |||
- | {{ https:// | ||
- | |||
- | Our finalized structure will consist of multiple colored squares connecting to each other. It will have a white or a black square in the center, and orange, magenta, light blue, and lime squares branching off on the sides randomly. Here is the setup of our 2 initial squares: | ||
- | |||
- | {{ https:// | ||
- | |||
- | This jigsaw will ask for any other jigsaw that: | ||
- | * is in the // | ||
- | * has an attachment type of // | ||
- | It then turns into white concrete to match the rest of the platform. | ||
- | |||
- | For demo purposes, we've made 2 starting platforms: one is white, and one is black. The only difference is what they turn into. We'll save these as structure files using structure blocks: | ||
- | |||
- | {{ https:// | ||
- | |||
- | For our randomized edge platforms, we've made 4 extra squares of different colors. Again, despite being used for a different purpose, the jigsaw construction is //the same// aside from the "turns into" field. | ||
- | |||
- | {{ https:// | ||
- | |||
- | We now have 6 saved '' | ||
- | |||
- | {{ https:// | ||
- | |||
- | For usage, we'll move these to '' | ||
- | |||
- | {{ https:// | ||
- | |||
- | The setup is complete! We now have 6 total squares. Let's briefly recap the goal: | ||
- | * have a white or black square selected as the center for our structure | ||
- | * have a pool of the 4 other colors | ||
- | * branch off from the center square with our 4 extra colors | ||
- | |||
- | Let's head back to our '' | ||
- | <code java [enable_line_numbers=" | ||
- | private static final Identifier BASE_POOL = new Identifier(" | ||
- | private static final Identifier COLOR_POOL = new Identifier(" | ||
- | </ | ||
- | |||
- | Remember: every jigsaw ends up searching through the color pool, but we still have a base pool! This is to keep our black & white squares out of the outside generated squares. It's also going to be our origin pool, where we randomly select 1 structure from to begin our generation. | ||
- | |||
Now all we have to do is add our starting piece in our '' | Now all we have to do is add our starting piece in our '' | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
Line 125: | Line 66: | ||
ExamplePiece.init(); | ExamplePiece.init(); | ||
- | StructurePoolBasedGenerator.addPieces(config.startPool, config.size, ExamplePiece:: | + | StructurePoolBasedGenerator.method_30419(config.getStartPool(), config.getSize(), ExamplePiece:: |
pos, children, random, calculateMaxYFromPiecePositions, | pos, children, random, calculateMaxYFromPiecePositions, | ||
Line 131: | Line 72: | ||
} | } | ||
</ | </ | ||
- | The Identifier is the starting pool to select from, the int is the size of the entire structure (with 7 being "7 squares out"), and the 3rd argument is a factory for the piece we'll register in a second. | ||
+ | The Identifier is the starting pool to select from, the int is the size of the entire structure (with 7 being "7 squares out"), and the 3rd argument is a factory for the piece we'll register in a second. | ||
Our finalized '' | Our finalized '' | ||
Line 237: | Line 178: | ||
The projection is how the pool is placed in the world. Rigid means it will be placed directly as is, and terrain matching means it will be bent to sit on top of the terrain. The latter may be good for a wheat field structure that moves with the terrain shape, whereas the first would be better for houses with solid floors. | The projection is how the pool is placed in the world. Rigid means it will be placed directly as is, and terrain matching means it will be bent to sit on top of the terrain. The latter may be good for a wheat field structure that moves with the terrain shape, whereas the first would be better for houses with solid floors. | ||
+ | |||
+ | |||
+ | ==== Jigsaws and pieces ==== | ||
+ | |||
+ | To understand what happens here, we'll have to dive into jigsaws (https:// | ||
+ | |||
+ | Structure Blocks are a simple way of saving a structure to a .nbt file for future use. Jigsaws are a component of structure blocks that assemble multiple structures into a single one; similar to normal jigsaws, each piece of the structure connects at a jigsaw block, which is like a connection wedge in a puzzle piece. We'll assume you're familiar with saving structures-- if you aren' | ||
+ | |||
+ | The jigsaw menu consists of 3 fields: | ||
+ | |||
+ | * target pool | ||
+ | * attachment type | ||
+ | * turns into | ||
+ | |||
+ | {{ https:// | ||
+ | |||
+ | When thinking about this as a puzzle, the target pool is the group of puzzle pieces you can search through. If you have a total of 10 pieces, one target pool may have 7 of the total pieces. This field is how a jigsaw specifies, "Hi, I'd like a piece from group B to connect to me!" In the case of a village, this may be a road saying, "Give me a house!" | ||
+ | |||
+ | The attachment type can be seen as a more specific filter within target pools-- a jigsaw can only connect to other jigsaws with the same attachment type. This is like the type of connector on a puzzle piece. The usages for this are a little bit more specific. | ||
+ | |||
+ | Finally, the "turns into" field is simply what the jigsaw is replaced with after it finds a match. If the jigsaw is inside your cobblestone floor, it should probably turn into cobblestone. | ||
+ | |||
+ | Here's an example implementation: | ||
+ | |||
+ | {{ https:// | ||
+ | |||
+ | Our finalized structure will consist of multiple colored squares connecting to each other. It will have a white or a black square in the center, and orange, magenta, light blue, and lime squares branching off on the sides randomly. Here is the setup of our 2 initial squares: | ||
+ | |||
+ | {{ https:// | ||
+ | |||
+ | This jigsaw will ask for any other jigsaw that: | ||
+ | * is in the // | ||
+ | * has an attachment type of // | ||
+ | It then turns into white concrete to match the rest of the platform. | ||
+ | |||
+ | For demo purposes, we've made 2 starting platforms: one is white, and one is black. The only difference is what they turn into. We'll save these as structure files using structure blocks: | ||
+ | |||
+ | {{ https:// | ||
+ | |||
+ | For our randomized edge platforms, we've made 4 extra squares of different colors. Again, despite being used for a different purpose, the jigsaw construction is //the same// aside from the "turns into" field. | ||
+ | |||
+ | {{ https:// | ||
+ | |||
+ | We now have 6 saved '' | ||
+ | |||
+ | {{ https:// | ||
+ | |||
+ | For usage, we'll move these to '' | ||
+ | |||
+ | {{ https:// | ||
+ | |||
+ | The setup is complete! We now have 6 total squares. Let's briefly recap the goal: | ||
+ | * have a white or black square selected as the center for our structure | ||
+ | * have a pool of the 4 other colors | ||
+ | * branch off from the center square with our 4 extra colors | ||
+ | |||
+ | Let's head back to our '' | ||
+ | <code java [enable_line_numbers=" | ||
+ | private static final Identifier BASE_POOL = new Identifier(" | ||
+ | private static final Identifier COLOR_POOL = new Identifier(" | ||
+ | </ | ||
+ | |||
+ | Remember: every jigsaw ends up searching through the color pool, but we still have a base pool! This is to keep our black & white squares out of the outside generated squares. It's also going to be our origin pool, where we randomly select 1 structure from to begin our generation. | ||
===== Registering Everything ===== | ===== Registering Everything ===== |
tutorial/jigsaw.1597496589.txt.gz · Last modified: 2020/08/15 13:03 by emmanuelmess