Minecraft Blogs / Tutorial

Using the Jigsaw Block in your Data Pack

  • 8,950 views, 4 today
  • 13
  • 7
  • 27
Baroque Obama's Avatar Baroque Obama
Level 66 : High Grandmaster Architect
168
Before Jumping In
Before continuing, you'll want to be familiar with the following:


The Basics
The Jigsaw Block (minecraft:jigsaw) is a unique internal block used in random structure generation. Its purpose is to define (within structure pieces) the locations where other structure pieces connect to them, as well as which pieces connect there. The term 'structure pieces' refers to individual .nbt files.

Several of the vanilla structures generate in a method essentially governed by source code, however three particular structures (Village, Bastion Remnant, and Pillager Outpost) generate as pieces joined together by Jigsaw Blocks.

These blocks can be used to create custom structures from custom pieces as well via data packs; world generation files included in the same pack can be used to control where and how often any structures generate.



Orientation
The Jigsaw Block has several orientation block states, and how it's oriented makes a big difference. In order to cause another structure piece to generate beside the piece you're working on, you'll need opposing Jigsaw Blocks at the appropriate edges of the pieces.

For example, you have a structure piece that you'd like to have another piece generate beside, attached to its north face. You'd need to:
  • Place a north-oriented Jigsaw Block somewhere on the north face of your first structure piece
  • Place a south-oriented Jigsaw block on the appropriate face of the other structure piece
  • Fill in the correct data in the Jigsaw Blocks' GUIs (explained below)
The structure pieces generate such that those two Jigsaw Blocks touch each other, and so the X/Y coordinates you'd pick for the Jigsaw blocks on the north/south face determine their relative alignment.

Up-oriented and down-oriented Jigsaw Blocks don't work this way. Their purpose is to generate structure pieces that are contained entirely within the original structure piece. An example of this is villager generation in villages. In vanilla villages, villagers don't 'spawn' upon generation - there are a bunch of Jigsaw Blocks in the ground, oriented upward; these generate tiny structure pieces that just have a matching down-oriented Jigsaw Block with a Villager standing on top amidst a couple of Structure Voids.



Jigsaw GUI
The Jigsaw GUI allows you to define its properties. These are as follows:

•Target pool
By default, this is set to minecraft:empty (i.e. nothing). This would be left as minecraft:empty if you don't want a new structure piece to generate attached to this Jigsaw Block (this type of Jigsaw use is explained below).

'Template Pools' can be defined in which you specify a list of any number of structure pieces and their random-selection weight; assigning a Template Pool in the Target pool field will cause your Jigsaw Block to try to generate a structure selected randomly (with weight) from it. You can of course use a pool that contains only one structure piece to guarantee its selection.

•Name
By default, this is set to minecraft:empty (i.e. nothing). The Name is used so that Jigsaw Blocks in other structure pieces can find this Jigsaw Block (explained below) - it's used as an identifier.

This would be left as minecraft:empty if other structure pieces shouldn't find this Jigsaw Block (this type of Jigsaw use is explained below).

•Target name
By default, this is set to minecraft:empty (i.e. nothing). This would be left as minecraft:empty if you don't want a new structure piece to generate attached to this Jigsaw Block (this type of Jigsaw use is explained below).

The Target name works together with the Target pool to find the correct part of an acceptable structure piece to generate attached to your Jigsaw. The Jigsaw Block randomly (with weight) selects a structure piece from its Target pool, then randomly selects an appropriately-facing Jigsaw Block in the chosen structure piece whose Name is set the same as your Jigsaw's Target name, and generates the chosen structure piece such that the two Jigsaw Blocks face and touch each other.

•Turns into
By default, this is set to minecraft:air. When the structure piece generates, the Jigsaw Block transforms into another block of your choice to remove itself and complete the structure.

•Joint type (up/down-oriented Jigsaw Blocks only)
By default, this is set to Rollable. When Rollable, the structure piece that generates attached to this Jigsaw Block can generate randomly rotated 0°/90°/180º/270°, around the Y-axis, anchored on the target Jigsaw Block. When set to Aligned, there is no rotation (0°).



Usage Example

Let's say you'd like a structure that always has a fountain in the center with a random house connected to it on its north, south, east, and west edges, forming a '+' shaped mini-village. You have your fountain structure piece built, as well as 11 different house structure pieces that can be randomly drawn from to fill the 4 'house slots'.

You'll want your fountain piece to be the starting point for your structure, and so you'll make a Template Pool that contains only the fountain piece, as well as a Configured Structure Feature for the full structure that refers to that Template Pool in its 'start_pool' tag. Then, make sure to add this feature to the 'starts' list tag in the biome files the structure should generate in.
  • The fountain itself would start with four Jigsaw Blocks - one at the north/south/east/west edges of the structure. All of them would have their Target pool set to a new Template Pool you create that lists all 11 houses.
  • They would all have Name set to minecraft:empty, because Jigsaw Blocks in other structure pieces have no reason to generate your central fountain piece.
  • You can arbitrarily set whichever Target name you'd like here (e.g. 'target:name' or 'custom:house'); the idea is that there will be Jigsaw Blocks in each house piece whose Name is set to the same value.

With respect to Turns into, note that typically Jigsaw Blocks are best placed in the ground so one can easily align them and make sure the generation is seamless; typically one has them turn into the appropriate block that should be at that location in the ground. If the Jigsaw Block is in the air, it's usually best to use Structure Void rather than air; that being said, there are circumstances in which one might want to use air - one should use minecraft:cave_air.

Each of the house pieces would have one Jigsaw Block at an edge - this Jigsaw block will align with one of the 4 in the fountain piece such that they face and touch each other. The Jigsaw Blocks in the house pieces would have their Target pool and Target name set to minecraft:empty, because no new structure pieces should be generated from these Jigsaws.

Each of these Jigsaw Blocks would have Name set to the same value as the Target name in the fountain's Jigsaws.

The result is that, when Minecraft decides that your structure will be generated at a certain location:
  • The Start Pool is drawn from, in this case guaranteeing a fountain piece is generated on the spot (this is 'level 0' generation)
  • The four Jigsaws in the fountain piece each check their Target pools for a piece, and try to find a Jigsaw Block in the chosen piece with a Name matching the fountain Jigsaw's Target name, then generate that piece attached as described above (this is 'level 1' generation)
  • The four house pieces that were randomly chosen and generated are checked for Jigsaw Blocks that search a Target pool for a Target name, and it's found that there aren't any - end of generation (otherwise we'd have 'level 2' generation)
And we get our structure. With respect to 'levels' of generation, one can specify how many levels deep the generation tree branches out after the Start Pool structure is generated. This is done by adjusting the 'size' tag in your Configured Structure Feature; only integer values from 0 to 7 inclusive are allowed.



A much simpler example can be found in Underworld Labyrinth - this is a collection of 64 identically-sized square mazes that have exits on their north/south/east/west faces.
  • The Start Pool is the only Template Pool, containing all 64 maze pieces
  • Each piece has a north/south/east/west Jigsaw Block
  • The Jigsaw Blocks all draw from the Start Pool
  • The Jigsaw Blocks all have the same Name and Target name (which are the same as each other)
  • The 'size' tag of the Configured Structure Feature is set to 2
The result is a diamond-shaped configuration of perfectly-aligned squares, with a total of 13 pieces, making a huge connected labyrinth.



Limitations
With no formal documentation, trial and error has been my primary information resource. Collaborative discussion with Rainbeau_Flambe has also been very productive. Some limitations have been encountered, which should be taken note of:
  • Bastion Remnants always spawn their Start Pool piece with its base at Y=31. This limits what can be done with them to some extent, but this constant value can also be used for advantage (see Abyssal Villages). Structures also seem to have a hard-coded total size maximum that stops generation 64 blocks away from the starting piece, where further pieces won't generate beyond.
  • minecraft:cave_air is always a much better choice than just air - when a piece generates underwater (e.g. a Bastion Remnant-type in Overworld), only Cave Air will actually replace the water
  • Blocks that can be waterlogged will generate waterlogged if the piece generates underwater, even if fully surrounded by other blocks


If you have more to contribute, please reach out. The world needs as much information as possible about this wonderful block!

Press Square to testify.
Tags

Create an account or sign in to comment.

TheRedstoneBear
04/22/2023 8:19 pm
Level 1 : New Miner
TheRedstoneBear's Avatar
I was using it, but whenever it generated the jigsaws would be rotated randomly, even on align mode. There is also always a gap between them. Do you know why that is?
2
Baroque Obama
04/23/2023 12:12 am
Level 66 : High Grandmaster Architect
history
Baroque Obama's Avatar
The short answer is that random placement and rotation of structures is a built-in annoyance that typically requires some creativity to get around (some degree of symmetry probably being the simplest solution).

The one thing that custom structures need is a way to control both of these things entirely.
1
Baroque Obama
04/06/2023 7:12 am
Level 66 : High Grandmaster Architect
Baroque Obama's Avatar
Each element in the elements list of a template pool gets a weight tag with an integer value.

1
meepstertron
04/06/2023 3:57 am
Level 1 : New Miner
meepstertron's Avatar
Hey i was wondering if there was some Kind of weight property,
I'm currently coding a dungeons datapack where I want a randomly generated dungeon with a rare room like a treasure room. Could someone help me?

Regards Meep aka Jan
1
Dermugettum
03/06/2023 11:25 pm
Level 22 : Expert Miner
Dermugettum's Avatar
It's awesome to see some fleshed-out documentation on jigsaw blocks!

I'm currently working on a jigsaw structure that's giving me some trouble. I have a starting pool where one aboveground piece always generates, but there's one room out of all my underground pieces that doesn't always generate. It's kind of crucial, kind of like the end portal in the stronghold. I don't know if it's possible to have two recurring pieces in a randomly generated structure or not.

Also, I'm getting a lot of generated structures that only generate up to 3-4 rooms when there should be way more with the amount of pieces and template pools I've set up. I've set the 'size' tag up to 7 but it doesn't seem to be helping.

Lastly, I haven't figured out how to get an underground structure with an aboveground entrance to stop poking out of the terrain. I thought about adding levels to it like a mineshaft, but I don't know enough to be sure that'll work.
2
Baroque Obama
03/06/2023 11:45 pm
Level 66 : High Grandmaster Architect
history
Baroque Obama's Avatar
When it comes to the specific problem with inconsistent structure selection, it's hard to say what advice I'd give without looking at the project itself (and my computer sucks rn—too ancient to run current/recent MC versions).

That being said, I'm always trying to look for another angle. In this case, I might look at using functions to make the magic happen—many of my data packs are great examples. Some I'd recommend looking at which are really outside-the-box are Sky Realms and Towers of Wizardry.

Sky Realms makes floating islands generate with the regular terrain, with tall, penile tower structures that always have entrances at the floating island level and at regular ground level (through a very cool/simple structure/function set) - might be useful.

Towers of Wizardry is one of my of many packs which generate 'structures'/blocks wherever I choose (independent of genuine world generation), using functions only. I'll highlight this one (and Armageddon: the Final Colosseum) because this is the entire basis for these packs, and will make it easier to digest as a data pack.

I'm sure you'll find a creative solution :).
2
MatthGeek
10/09/2022 7:45 pm
Level 21 : Expert System
MatthGeek's Avatar
Great tutorial! Just one thing, up/down jigsaws don't just have to be for generating entirely within a structure. They can also be used to add multiple levels to a structure.
1
Baroque Obama
10/09/2022 10:20 pm
Level 66 : High Grandmaster Architect
Baroque Obama's Avatar
Great observation, you're not wrong :)
1
NikoKun
04/15/2022 11:08 am
Level 36 : Artisan Professor
NikoKun's Avatar
I'm curious.. Do you think there's any way to use jigsaw/structures to generate an endless maze dimension? If it is, I haven't quite been able to figure it out yet, although there does seem to be some new jigsaw features in the upcoming update, which I'm hoping might make it more possible.. I'm just not sure.
2
Baroque Obama
04/15/2022 11:59 am
Level 66 : High Grandmaster Architect
Baroque Obama's Avatar
Sure thing, just make sure to insert one or more clever Command blocks in your structure(s), so that the commands (and functions) of your choice are called when a structure generates. This is accomplished by including a block of Redstone inside a structure as well, right beside the Command block, to activate it immediately when it generates. (See my Sky Realms pack for a concrete example of this in action).

Many of my data packs include one or more functions that are primarily setblock commands and the like, made for generating specific things in specific places; such a function could be called by a Command block inside your structure upon generation.

What you're asking is totally doable and not really tough, but there are a few moving parts to it :). No plug-ins needed, this can be done in Vanilla.

I think the key takeaway is that Jigsaw blocks aren't required in any way to accomplish your goal, and would only unnecessarily introduce randomness in the placement of things. One can accomplish perfect placement with much more customizable randomness and better results without them here, using the method above with Structure block.

There's a fair bit to it though... feel free to PM me if you'd like more help or more specifics :).
2
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome