Here I'll show the final code that definitly works for me:
//spawn structure
if (!worldIn.isRemote) {
WorldServer worldserver = (WorldServer) worldIn;
MinecraftServer minecraftserver = worldIn.getMinecraftServer();
TemplateManager templatemanager = worldserver.getStructureTemplateManager();
ResourceLocation loc = new ResourceLocation(Reference.MOD_ID,"t1");
Template template = templatemanager.getTemplate(minecraftserver, loc);
Utils.getLogger().info("=======0======="+template);
if (template != null) {
worldIn.notifyBlockUpdate(pos, iblockstate, iblockstate, 3);
PlacementSettings placementsettings = (new PlacementSettings()).setMirror(Mirror.NONE)
.setRotation(Rotation.NONE).setIgnoreEntities(false).setChunk((ChunkPos) null)
.setReplacedBlock((Block) null).setIgnoreStructureBlock(false);
Utils.getLogger().info("=======1======="+loc);
template.addBlocksToWorld(worldIn, pos, placementsettings);
Utils.getLogger().info("========2======="+pos);
}
}