Minecraft Java Edition – Silverfish Stone/Egg Placement

minecraft-java-edition

How are silverfish monster eggs generated? All I know is that they are found in strongholds and igloos, but what determines which part they spawn in? (As in, is it totally random, or does it look for a certain structure/pattern etc…) The MC wiki only says:
"found in Strongholds and igloo basements, occasionally in place of normal stone bricks. "

Best Answer

Strongholds

As noted by Minecraft Wiki - Stronghold:

They contain several doors and rooms made mostly of stone brick (45%), mossy stone brick (30%), cracked stone brick (20%) and monster egg blocks (5%)

When selecting blocks to fill in with, the following function is called:

float randomFloat = rand.nextFloat();

if (randomFloat < 0.2F)
{
    this.blockstate = Blocks.stonebrick.getStateFromMeta(BlockStoneBrick.CRACKED_META);
}
else if (randomFloat < 0.5F)
{
    this.blockstate = Blocks.stonebrick.getStateFromMeta(BlockStoneBrick.MOSSY_META);
}
else if (randomFloat < 0.55F)
{
    this.blockstate = Blocks.monster_egg.getStateFromMeta(BlockSilverfish.EnumType.STONEBRICK.getMetadata());
}
else
{
    this.blockstate = Blocks.stonebrick.getDefaultState();
}

The monster egg block is selected at random from a list of other valid blocks, with the stated 5% chance of being selected in comparison.

Wherever this function is used is where monster egg blocks will be created in a stronghold. The only room in a stronghold that does not contain silverfish blocks is the "corridor" room, which connects other room types together (typically being very small).

Image example, replacing all stone bricks with lapis blocks to show what the corridor encompasses (which is where no monster egg blocks will spawn):

Short corridor of lapis blocks

Igloos

Igloos make use of the new structure template system implemented in 1.9 (where structures are data-driven rather than hard-coded). The monster egg blocks are not randomly generated, but will instead appear at the same location every time as defined by the structure file.

For example, in this image, the lapis blocks represent where monster egg blocks will always be placed:

Bottom of an igloo

Here is the structure data being used, where state is the blockstate (which points to normal stone brick monster eggs) and pos is the position relative to the corner of the structure, showing that the block is not randomly placed:

state: 8289